Tutorial for using Point Cloud Library (PCL) with ROS 2.
Code adapted for ROS 2 from ROS Industrial: Building a Perception Pipeline.
Install ROS 2, create a workspace then install the following packages:
sudo apt install ros-galactic-pcl-ros
sudo apt install ros-galactic-pcl-conversions
Clone this repo into a ROS 2 workspace and build:
source <ROS_WS>/install.setup.bash
cd <ROS_WS>/src
git clone https://github.com/adrian-soch/pcl_tutorial
colcon build
After building the easiest way to start the node is through the launch file, change the paramters inside processing_node.launch.py
then:
ros2 launch pcl_tutorial processing_node.launch.py
Then start a PointCloud2 Publisher, this can be from a real hardware, from a simulation, or a rosbag. To play a rosbag that has pointcloud data recorded:
ros2 bag play <PATH_TO_BAG>
Optionally, you can pause rosbags, or play them 1 message at a time:
ros2 service call /rosbag2_player/toggle_paused rosbag2_interfaces/TogglePaused
ros2 service call /rosbag2_player/play_next rosbag2_interfaces/PlayNext
-
To view the point cloud topics, run
rviz2
in a new terminal. -
Click
Add
near the bottom right, select theBy topic
tab, and then select the point cloud 2 topic that you want to see. -
Go to
Global Options -> Fixed Frame
and select the frame the data is in. Otherwise there will be aGlobal Status
error that prevents you from seeing the data. -
To make LiDAR points easier to see go to
PointCloud2 -> Style
and selectPoints
from the dropdown menu. Feel free to try changing any other settings -
You can save the current configuration and rviz2 will open to this configuration by default. This can be changed at any time.
An easy way to debug ROS 2 C++ programs is through VSCode.
- Build the package with simlinks, and the debug flag
- Run the ROS node with gdb prefix (or add to launch file)
- Add the following to the
launch.json' in the
.vscode` folder
colcon build --packages-select lesson_perception --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo
ros2 run --prefix 'gdbserver localhost:3000' lesson_perception perception_node
Create VSCode `launch.json`
{
"version": "0.2.0",
"configurations": [
{
"name": "ROS2 C++ Debugger",
"request": "launch",
"type": "cppdbg",
"miDebuggerServerAddress": "localhost:3000",
"cwd": "/",
"program": "/home/<PATH_TO_ROS_WS>/install/<PACKAGE>/lib/<PACKAGE>/<EXECUTABLE>"
}
]
}
# Run debugger in vscode
- Info on PCL, or for use witout ROS see : https://pcl.readthedocs.io/projects/tutorials/en/latest/.
- Splitting ROS nodes into multiple files (compared to the basic tutorial): https://answers.ros.org/question/380079/how-to-write-header-file-for-ros-2-publisher/.