ROS2 Lidar - kinda

Continuing my ongoing quest to see if I can get anything from ROS2 and a small Lidar device (I just found a YT video of a very young person, maybe 12? that, of course, got this working using Rviz2 in about 8minutes, pfhh... guess my technical days are numbered?!)

However, not to be deterred, I am choosing to do this the "hard way", ie. I want to see RAW data, I want to see the values being spat out of the Lidar, I want to see the numbers - I then want to record that or process it on the fly - yes, I know that RViz2 will do that, but I want to be able to use it for some autonomous sensor usage, ie. make the thing self-drive & navigate.  Maybe I should search YT to follow another 12year old that has already done that already?


Anyway, I suppose it's a bit like sitting on a couch in your socks & pants, eating biscuits, watching p0rn on the TV, saying, "yeah, I can do that", "that's easy, anyone can do it" - but IRL, it's somewhat more complex & different, there are always challenges & unexpected parameters that hadn't been thought of - so, yeah, maybe it is good having a go yourself & not just watching others? first of all, you'll have to get off the couch, put on some clothes & spruce yourself up to start the long journey of meeting another human being, before you could even get to what you were watching.... wow, that was a digression, even I found it odd. 

anyway, enough grumbling, let's get on with it:

Opening up the previous journey pages:

https://tonyisageek.blogspot.com/2024/12/ugv-rover-with-without-ros2.html

Nope, that was not the one I wanted, ah THIS is the one I want:

https://tonyisageek.blogspot.com/2024/12/ros2-lets-try-this-again.html

Recalling earlier that I had setup ROS2 as a container on my laptop (yes, I'll get to using it on the UGV RPI5 later), I thought, why not plug the Lidar into the laptop and "see what I get"?  Can I get to "see" any raw data, can I get ROS2 to publish to a topic, can I read from that topic?

Lots & lots of questions.  Let's see if I can answer some of them.




I deleted the previous container via Portainer and ran the following so that the /dev/ttyUSB0 port was made available.

[honor laptop]

$ docker run -it --name ros_desktop --priviliged osrf/ros:humble-desktop-full

This will then give access to [CLI 1] below.

Then run this to give us [CLI 2] below:

$ docker exec -it ros2_desktop /bin/bash


[container CLI 1]

$ mkdir dev

$ cd dev

$ git clone https://gitee.com/ldrobotSensorTeam/ldlidar_stl_ros2.git

$ cd ldlidar_stl_ros2

Now, it's at this point I shold go & lookup to see what version I actually have, but I'm lay & there are only 3 options, I'll try the first, failing that, well, you know what comes next.  If none work, off to the inter-webs I go.

I'll just paste down below the next steps. Basically use colcon to build the ROS2 node module code, then source the install/setup.bash file and then run the ros2 launch command to execute the node and make a node that is being published to, so in [CLI 2] we can subscribe to it and see what it is putting out.


root@185410425fa8:~/dev/ldlidar_stl_ros2# colcon build

Starting >>> ldlidar_stl_ros2

[0.336s] WARNING:colcon.colcon_ros.prefix_path.ament:The path '/root/dev/ldlidar_stl_ros2/install/ldlidar_stl_ros2' in the environment variable AMENT_PREFIX_PATH doesn't exist

[0.337s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/root/dev/ldlidar_stl_ros2/install/ldlidar_stl_ros2' in the environment variable CMAKE_PREFIX_PATH doesn't exist

Finished <<< ldlidar_stl_ros2 [0.37s]                     


Summary: 1 package finished [0.61s]

root@185410425fa8:~/dev/ldlidar_stl_ros2# source install/setup.bash 

root@185410425fa8:~/dev/ldlidar_stl_ros2# ros2 launch ldlidar_stl_ros2 ld19.launch.py

[INFO] [launch]: All log files can be found below /root/.ros/log/2024-12-28-14-29-33-279710-185410425fa8-1022

[INFO] [launch]: Default logging verbosity is set to INFO

[INFO] [ldlidar_stl_ros2_node-1]: process started with pid [1023]

[INFO] [static_transform_publisher-2]: process started with pid [1025]

[static_transform_publisher-2] [WARN] [1735396173.357001874] []: Old-style arguments are deprecated; see --help for new-style arguments

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375692397] [LD19]: LDLiDAR SDK Pack Version is: v3.0.3

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375809313] [LD19]: <product_name>: LDLiDAR_LD19

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375830335] [LD19]: <topic_name>: scan

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375848843] [LD19]: <frame_id>: base_laser

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375864208] [LD19]: <port_name>: /dev/ttyUSB0

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375879364] [LD19]: <port_baudrate>: 230400

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375894241] [LD19]: <laser_scan_dir>: Counterclockwise

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375908907] [LD19]: <enable_angle_crop_func>: false

[static_transform_publisher-2] [INFO] [1735396173.375726829] [base_link_to_base_laser_ld19]: Spinning until stopped - publishing transform

[static_transform_publisher-2] translation: ('0.000000', '0.000000', '0.180000')

[static_transform_publisher-2] rotation: ('0.000000', '0.000000', '0.000000', '1.000000')

[static_transform_publisher-2] from 'base_link' to 'base_laser'

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375924343] [LD19]: <angle_crop_min>: 135.000000

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.375940895] [LD19]: <angle_crop_max>: 225.000000

[ldlidar_stl_ros2_node-1] [INFO] [1735396173.394444450] [LD19]: ldlidar node start is success

[ldlidar_stl_ros2_node-1] [ERROR] [1735396176.395059337] [LD19]: ldlidar communication is abnormal.

[ldlidar_stl_ros2_node-1] [LDS][INFO][1735396173.394265934][Actual BaudRate reported:230769]

[ERROR] [ldlidar_stl_ros2_node-1]: process has died [pid 1023, exit code 1, cmd '/root/dev/ldlidar_stl_ros2/install/ldlidar_stl_ros2/lib/ldlidar_stl_ros2/ldlidar_stl_ros2_node --ros-args -r __node:=LD19 --params-file /tmp/launch_params_su35zvus --params-file /tmp/launch_params__bu0p5wz --params-file /tmp/launch_params_447pfl61 --params-file /tmp/launch_params_zm0b7jeq --params-file /tmp/launch_params_yq92k3ai --params-file /tmp/launch_params_e64r_uet --params-file /tmp/launch_params_pubtznzg --params-file /tmp/launch_params_riqrzyph --params-file /tmp/launch_params_ngay69gj'].



It is odd that the [ERROR] is thrown here, this might be valid? but I'll do a Nelson for now and flip over to the [CLI 2] terminal - I am very suspicious of that Error....hmmm.....


[container CLI 2]

As I forgot to add this to the ~/.bashrc I'll run it now:

$ source /opt/ros/humble/setup.bash

Now, let's see what ROS2 has in the topic list? ooooo look a new topic has appeared!


root@185410425fa8:~/dev# ros2 topic list

/parameter_events

/rosout

/tf_static


The quickest & easiest way to "see" what /tf_static is showing is to echo it out to the screen, we can do that with the following command:


root@185410425fa8:~/dev# ros2 topic echo /tf_static

transforms:

- header:

    stamp:

      sec: 1735396173

      nanosec: 373586168

    frame_id: base_link

  child_frame_id: base_laser

  transform:

    translation:

      x: 0.0

      y: 0.0

      z: 0.18

    rotation:

      x: 0.0

      y: 0.0

      z: 0.0

      w: 1.0

---

root@185410425fa8:~/dev#


So, in theory this is good news.  I don't like that [Error] in [CLI 1] though, but it does kinda of show how to get ROS2 to identify the Lidar device, get some values from it, publish that to a node topic that can then be subscribed to & the data read & used-ish.


I would call that a, near-success.  Well, maybe NOT.


Because I'm picky, I went back through the [CLI 1] output and I noticed this:

[ldlidar_stl_ros2_node-1] [INFO] [1735398731.742107475] [LD19]: <topic_name>: scan


Therefore that implies the ros2 topic list SHOULD give me a /scan to subscribe to.  Hmmm it doesn't.

So, whilst /tf_static is great and all (need to figure out where this is coming from), I need to work out why I cannot "see" /scan.

Let me go and look at the source code for the node:



I believe I need to be echo-ing /scan to see all the live data.  I just looked up the Lidar from Amazon, it looks like I just "might" have the wrong driver?

https://www.amazon.co.uk/Waveshare-Developer-Omni-Directional-Frequency-Quadruped/dp/B0CNCLQ68L



and then this review gave me hope!


and just to amuse myself, I just found this web-page:

https://www.waveshare.com/wiki/Ugv02_Using_LiDAR_Tutorial

Well, yeah, I did that on my own, although it is nice to see / know what the RViz2 setup will be in order to see it in a flashy UI tool though, so that's a bonus.


okay, maybe I should have got to the 3rd launch file, because according to this web-page:

https://www.waveshare.com/wiki/D500_LiDAR_Kit

The D500 is an STL-19P, oh, that is what I did end up running above, so hmmm... maybe it is something else?

I went back to [CLI 1]


root@185410425fa8:~/dev/ldlidar_stl_ros2# ros2 launch ldlidar_stl_ros2 ld19.launch.py

[INFO] [launch]: All log files can be found below /root/.ros/log/2024-12-28-15-38-34-659332-185410425fa8-1102

[INFO] [launch]: Default logging verbosity is set to INFO

[INFO] [ldlidar_stl_ros2_node-1]: process started with pid [1103]

[INFO] [static_transform_publisher-2]: process started with pid [1105]

[static_transform_publisher-2] [WARN] [1735400314.751866270] []: Old-style arguments are deprecated; see --help for new-style arguments

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115351992] [LD19]: LDLiDAR SDK Pack Version is: v3.0.3

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115546711] [LD19]: <product_name>: LDLiDAR_LD19

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115586032] [LD19]: <topic_name>: scan

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115636319] [LD19]: <frame_id>: base_laser

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115667748] [LD19]: <port_name>: /dev/ttyUSB0

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115698338] [LD19]: <port_baudrate>: 230400

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115725996] [LD19]: <laser_scan_dir>: Counterclockwise

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115754561] [LD19]: <enable_angle_crop_func>: false

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115780892] [LD19]: <angle_crop_min>: 135.000000

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.115810994] [LD19]: <angle_crop_max>: 225.000000

[static_transform_publisher-2] [INFO] [1735400315.123442918] [base_link_to_base_laser_ld19]: Spinning until stopped - publishing transform

[static_transform_publisher-2] translation: ('0.000000', '0.000000', '0.180000')

[static_transform_publisher-2] rotation: ('0.000000', '0.000000', '0.000000', '1.000000')

[static_transform_publisher-2] from 'base_link' to 'base_laser'

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.135347501] [LD19]: ldlidar node start is success

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.271460573] [LD19]: ldlidar communication is normal.

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.283247472] [LD19]: Publish topic message:ldlidar scan data.

[ldlidar_stl_ros2_node-1] [ERROR] [1735400316.783380843] [LD19]: get ldlidar data is time out, please check your lidar device.

[ldlidar_stl_ros2_node-1] [ERROR] [1735400316.883579788] [LD19]: get ldlidar data is time out, please check your lidar device.


Okay, ignore the "time out" for the moment.  This is the line that is GOOD!

[ldlidar_stl_ros2_node-1] [INFO] [1735400315.283247472] [LD19]: Publish topic message:ldlidar scan data.


This is implying it was at least attempting to public to the topic scan with the data.


Okay, so I only got this to happen once, but it's now enough to keep me digging into this for a few more hours on a Saturday afternoon / evening / night!!!!

UPDATE: to follow.....

Well, I found the [Error] listed here, they seem to imply it is due to not being able to read/use the /de/vttyUSB0 port.  That may or may not be true as I'm kinda hopping along a thread with the Lidar USB -> Laptop USB -> Docker container, so maybe that is a problem?  Although I don't see how that would be any different on the RPi5 device?

https://github.com/ldrobotSensorTeam/ldlidar_stl_ros2/issues/12









Comments