Lidar n301 UDP port error

Hi, I have a lsLidar n301 that I am trying to do mapping with. Everytime I try to launch it using this command:

roslaunch lidar_n301_decoder lidar_n301.launch

It gives me this:

process[lidar_n301_driver_node-1]: started with pid [3036]
process[lidar_n301_decoder_node-2]: started with pid [3037]
[ INFO] [1612535114.993745138]: Opening UDP socket: address 192.168.1.222
[ INFO] [1612535114.994363689]: Opening UDP socket: port 2368
[ INFO] [1612535114.994655261]: expected frequency: 888.889 (Hz)
[ INFO] [1612535115.008378977]: Opening UDP socket: port 2368
bind: Address already in use
[ERROR] [1612535115.008835604]: Cannot open UDP port…
[ERROR] [1612535115.009058713]: Cannot initialize lidar driver…
[ WARN] [1612535115.053882169]: Using GPS timestamp or not 0
[lidar_n301_driver_node-1] process has finished cleanly
log file: /home/ubuntu/.ros/log/b11f3d48-67b9-11eb-b8e3-dca6327f6ea9/lidar_n301_driver_node-1*.log

I have used ifconfig to do the following in order to try and fix it:

ubuntu@devbot:~$ sudo ifconfig eth0 192.168.1.1 netmask 255.255.255.0
ubuntu@devbot:~$ ifconfig
eth0 Link encap:Ethernet HWaddr dc:a6:32:7f:6e:a9
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::dea6:32ff:fe7f:6ea9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9345 errors:0 dropped:0 overruns:0 frame:0
TX packets:126 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:560700 (560.7 KB) TX bytes:16647 (16.6 KB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1319165 errors:0 dropped:0 overruns:0 frame:0
TX packets:1319165 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:150899355 (150.8 MB) TX bytes:150899355 (150.8 MB)

wlan0 Link encap:Ethernet HWaddr dc:a6:32:7f:6e:aa
inet addr:192.168.8.140 Bcast:192.168.8.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7719 errors:0 dropped:1 overruns:0 frame:0
TX packets:910 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1101558 (1.1 MB) TX bytes:149197 (149.1 KB)

Sorry for the long post but I thought you would need all the information.

I am using a Pi 4 on my Magni

Hmm interesting, our team is using the same type of lidar I think. We used this setup in /etc/network/interfaces:

auto eth0
	iface eth0 inet static
	address 192.168.42.125/24 #this IP may depend on your lidar settings
	gateway 0.0.0.0
	dns-nameservers 8.8.8.8

And launched it using:

  <arg name="device_IP" default="192.168.42.222" />
  <arg name="device_Port" default="2368" />
  <arg name="laser_link" default="laser" />
  <arg name="angle_disable_min" default="-1" />
  <arg name="angle_disable_max" default="-1" />

  <node pkg="lidar_n301_driver" type="lidar_n301_driver_node" name="lidar_n301_driver_node" output="screen">
    <param name="frame_id" value="$(arg laser_link)"/>
    <param name="device_ip" value="$(arg device_IP)"/>
    <param name="device_port" value="$(arg device_Port)"/>
  </node>

  <node pkg="lidar_n301_decoder" type="lidar_n301_decoder_node" name="lidar_n301_decoder_node" output="screen">
    <param name="child_frame_id" value="$(arg laser_link)"/>
    <param name="point_num" value="2000"/>
    <param name="angle_disable_min" value="$(arg angle_disable_min)"/>
    <param name="angle_disable_max" value="$(arg angle_disable_max)"/>
    <param name="min_range" value="0.1"/>
    <param name="max_range" value="50.0"/>
    <param name="frequency" value="10.0"/>
    <param name="publish_point_cloud" value="false"/>
  </node>

I can’t really explain further since I wasn’t the one doing the said setup, but I hope that helps in some way.

It is likely that for whatever reason some other code running on your system has decided to use that port number then you cannot use it.

Before you start your lidar run an incantation of netstat to show ports and the process/pid that is using the port.

Example: netstat -p

netstat can tell a great many things about open ports so look at it’s help menu for other ideas.

Find a port number near the one in the launch file and use that port number instead perhaps is one thought to think about if it would help.

The port is generally preceeded with a : so this will maybe help:
netstat -a | grep :2368

Also, first time after a reboot try it because maybe some instance is hung up on very first time so then 2368 in use shows for all future process starts.

Hi, I followed your steps and used netstat -a to find a port close to 2368:

udp 0 0 *:46898 :
udp 0 0 *:2368 :
udp 0 0 localhost:323 :

I used port number 46898 and adjusted the launch files to use this port number. However, after trying this as well as port number 2366 I get the following warning error:

process[lidar_n301_driver_node-1]: started with pid [2276]
process[lidar_n301_decoder_node-2]: started with pid [2277]
[ INFO] [1612796424.195910067]: Opening UDP socket: address 192.168.1.222
[ INFO] [1612796424.196075321]: Opening UDP socket: port 46898
[ INFO] [1612796424.196146582]: expected frequency: 888.889 (Hz)
[ INFO] [1612796424.207801183]: Opening UDP socket: port 46898
[ INFO] [1612796424.207992154]: Initialised lidar n301 without error
[ WARN] [1612796424.232993950]: Using GPS timestamp or not 0
[ WARN] [1612796426.208538383]: lidar poll() timeout
[ WARN] [1612796428.209801356]: lidar poll() timeout
[ WARN] [1612796430.211876218]: lidar poll() timeout
[ WARN] [1612796432.214122258]: lidar poll() timeout

I am able to ping the IP address of the Lidar though. So I’m thinking the fault lies with my choice of port number.

The port number usage can have odd rules.
What I meant to say is use a number very near that number that is busy.
Don’t use some really way off number or you may hit some odd rule.

So you have the right idea but there may be some other hard coded port number in some config file or even some source file of the lidar driver. That may have to agree or your driver may not find the lidar.

I am sorry, I don’t have that setup so it’s just me guessing things.

Try to search for other persons who had to use a different port and see if they found some other thing that has to change in the lidar driver so it too uses this new port you have semi-arbitrarilly chosen.

Also there should be some option of netstat that can in some way tell you WHAT process and even the location of the executable that is using the port you wanted to use. I know I have used that before I just don’t remember the magical incantation. Look at the netstat help. BUT be aware that the way netstat works on differrent operating system varies in option names so be sure you are looking at the proper help for the operating system you are using which in our case is Ubuntu Linux 16.04 There is also a ‘netstat --help’ but that sort of help is a bit short on words so finding some help on a web search may offer more practical help.

So it may be that other port can be changed as something to try as well.

Try to be sure you are NOT starting the driver twice because THAT would explain everything too.

Can you please tell us if you are using the lidar with the power box or the one with only the split cable?

We have our lidar provider change the IPs of the lidar to 192.168.42.222 by default but there may recently been some logistical mixup. Can you also try the same with 192.168.1.222 in the launch file and with 192.168.42.125 in the /etc/network/interfaces then reboot the robot.

lidar. launch is started on boot, so this time please test by

rosnode kill /lidar_n301_driver_node
rosnode kill /lidar_n301_decoder_node
roslaunch goalroutes_bringup lidar.launch

also please check that you hear light humming from the lidar to make sure it has power.

@Ivano any chance solving that error? I am having the same issue with my lsLidar driver.