How to Publish LIDAR Data Using a ROS Launch File

2021-06-11-12.20.04

In this tutorial, I will show you how to publish LIDAR data using a ROS launch file.

Real-World Applications

This project has a number of real-world applications: 


  • Indoor Delivery Robots
  • Room Service Robots
  • Mapping of Underground Mines, Caves, and Hard-to-Reach Environments
  • Robot Vacuums
  • Order Fulfillment
  • Factories

Prerequisites

Getting Started

To publish LIDAR data, you are going to want to follow this tutorial. Follow all the instructions up until you reach the section entitled “Build a Map Using the Hector-SLAM ROS Package”. Don’t go beyond that point.

Create the Launch File

Once you’ve completed the step above, open a terminal window, and go to the main launch file.

Turn on your Jetson Nano.

Open a terminal window.

Go to your launch file.

roscd launch_jetson_nano_bot
cd launch
gedit jetson_nanobot.launch

Add the following lines below the IMU data publisher node.

  <!-- Lidar Data Publisher Using RPLIDAR from Slamtec -->
  <!-- Used for obstacle avoidance and can be used for mapping --> 
  <!-- Publish: /scan -->
  <node name="rplidarNode"          pkg="rplidar_ros"  type="rplidarNode" output="screen">
    <param name="serial_port"         type="string" value="/dev/ttyUSB0"/>
    <param name="serial_baudrate"     type="int"    value="115200"/><!--A1/A2 -->
    <!--param name="serial_baudrate"  type="int"    value="256000"--><!--A3 -->
    <param name="frame_id"            type="string" value="laser"/>
    <param name="inverted"            type="bool"   value="false"/>
    <param name="angle_compensate"    type="bool"   value="true"/>
  </node>  

Save the file, and close it.

Launch the Launch File

Open a new terminal window, and go to the home directory.

cd

Launch the launch file.

roslaunch launch_jetson_nano_bot jetson_nanobot.launch

If you open a new terminal window, and type the following command, you will be able to see the active topics.

rostopic list

Let’s see what LIDAR data is being published to the /scan ROS topic. Open a new terminal window, and type the following command to see a single message (the number after the -n tag indicates how many messages you want to see):

rostopic echo -n1 /scan

Alternatively, you can see the full stream of messages by typing:

rostopic echo /scan

Press CTRL + C to stop the data.

Visualize the Data

Open a new terminal window, and start rviz so we can visualize the data.

rosrun rviz rviz

Change the Fixed Frame to laser.

Click the Add button in the bottom-left of the window.

Select LaserScan, and click OK.

Set the LaserScan topic to /scan.

Increase the size to 0.03 so that you can see the data more easily.

Here is what you should see:

2021-05-12-21.37.57

Press CTRL + C on all windows to shut everything down.