3. ROS2 Lidar Sensors¶
3.1. Learning Objectives¶
In this example, we will add a lidar sensor to match the one on top of Turtlebot3, and add the rostopics to publish lidar sensor data and info.
Add lidar sensor to the robot
Connect lidar sensor output to a ROS2 lidar publisher node to publish the data.
Visualize everything in RViz2.
Completed the ROS2 Import and Drive TurtleBot3 tutorial so that Turtlebot is loaded and moving around.
3.2. Adding a Lidar ROS2 Bridge¶
3.2.1. Adding a Lidar Sensor¶
First we need to add a lidar sensor to the robot.
Go to Create -> Isaac -> Sensors -> Lidar -> Rotating.
To place the synthetic lidar sensor at the same place as the robot’s lidar unit, drag the lidar prim under /World/turtlebot3_burger/base_scan. Zero out any displacement in the Transform fields inside the Property tab. The lidar prim should now be overlapping with the scanning unit of the robot.
Inside the RawUSDProperties tab for the lidar prim, set the maxRange to 25. This way the lidar will ignore anything that’s beyond 25 meters. This will prevent the lidar reporting a hit everywhere in the room because of the walls.
We’ll check drawLines to visualize the lidar scans.
Press Play to see the lidar comes to life. Red lines of the scan means hit, green means no hit, the color spectrum from green to yellow to red is proportional to the distance of the object detected.
3.2.2. Lidar ROS2 OG Graph¶
Once the lidar sensor is in place, we can add the corresponding OG nodes to stream the detection data to a Rostopic. OG nodes for Lidar publisher should matches the images below.
3.2.3. Graph Explained¶
On Playback Tick Node: Producing a tick when simulation is “Playing”. Nodes that receives ticks from this node will execute their compute functions every simulation step.
ROS2 Context Node: Setting the Domain ID for the laser scan publisher node.
Isaac Read Lidar Beam Node: Retrieve information about the Lidar and data. For inputs:LidarPrim, add target to point to the Lidar sensor we just added at /World/turtlebot3_burger/base_scan/Lidar.
ROS2 Publish Laser Scan: Publishing laser scan data. Type
/laser_scaninto the Topic Name field.
Isaac Read Simulation Time: Use Simulation time to timestamp the
Constant String: Input to set frameID to turtle.
3.2.4. Verify ROS connections¶
Press Play to start ticking the graph and the physics simulation.
In a separate ROS2-sourced terminal , check that the associated rostopics exist with
ros2 topic list.
/laser_scanshould be listed in addition to
To visualize the laser scan data, open RViz2 by typing in
rviz2on the command line and enter.
Inside rviz, add a Laser Scan type to visualize. Make sure the Topic that the laser scan is listening to matches the topic name inside the ROS2 Publisher Laser Scan, and fixed frame matches the frameID inside the ROS2 Publish Laser Scan node.
3.3. Multiple Sensors in RViz2¶
To display multiple sensors in RViz2, there are a few things that are important to make sure all the messages are synced up and timestamped correctly.
Use Isaac Read Simulation Time as the node that feeds the timestamp into all of the publishing nodes’ timestamps.
To publish the simulation time, you can setup the following graph to publish a ROS clock topic.
To visualize all the sensors at once inside RViz2, make sure the frameID of all the cameras and sensors all have the same ID name. The frameID can be found inside the Property tab -> RawUSDProperties menu -> frameId field.
To see the multi-sensor example below, open the USD asset
Isaac/Samples/ROS2/Scenario/simple_room_turtlebot.usdOpen its Action graphs and notice the frameID of all the cameras and lidar publisher were set to “turtle”.
To see the rviz image below, make sure the simulation is playing. In a ROS2-sourced terminal, open with the configuration provided using the command:
ros2 run rviz2 rviz2 -d ros2_workspace/src/isaac_tutorials/rviz2/camera_lidar.rviz.
Ensure that the
use_sim_time ROS2 param is set to true after running the RViz2 node.
This ensures that the RViz2 node is synchronized with the simulation data especially when RViz2 interpolates position of lidar data points.
Set the parameter using the following command in a new ROS2-sourced terminal:
ros2 param set /rviz use_sim_time true
This tutorial covered
Adding a Lidar sensor
Adding a Lidar Rostopic
Adding a Clock Rostopic
Displaying multiple sensors in RViz2.
3.4.1. Next Steps¶
Continue on to the next tutorial in our ROS2 Tutorials series, ROS2 Transform Trees and Odometry, to learn how to add global and relative transforms to a TF tree.