Ros2 Cartographer Setup(1)_ workspace build using Rplidar A1

mseokq23·2024년 11월 18일

Developing Self Driving with Jetson Nano · Phase 0 · ROS2 Foxy (archived) · ROS2 Setup (2)

Goal: Build a ROS2 workspace with the rplidar_ros driver and get the RPLIDAR A1 running.
Result: ❌ Failed / abandoned — the LiDAR worked on ROS2 after the port fix, but the project moved to ROS1 Noetic (LiDAR again in Jetson Project #4).
Final code: not used in the final code (ROS2 driver; the ROS1 LiDAR setup is src/robot_bringup/launch/lidar.launch).
Env: Jetson Nano B01 · Ubuntu 20.04 · ROS2 Foxy

🔧 Problem: rplidar_node died with Error, unexpected error, code: 80008004.
Cause: the driver could not talk to the LiDAR over the serial port (port name / permission / settings).
Fix: check the port, add the user to dialout, chmod 666 /dev/ttyUSB0, and set the port, baud rate and frame in the launch file.

1. Build the workspace with rplidar_ros

Step 1. Clone the driver (ROS2 branch)

❌ Tried: git clone https://github.com/robopeak/rplidar_ros.git → this repository is the ROS1 driver (it still works on ROS1), so rosdep install fails on ROS2:

ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
rplidar_ros: Cannot locate rosdep definition for [rosconsole]
Continuing to install resolvable dependencies...

✅ Use the ros2 branch of the Slamtec repository instead:

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone -b ros2 https://github.com/Slamtec/rplidar_ros.git

If you already cloned the wrong repository, delete it first and clone again:

cd ~/ros2_ws/src
rm -rf rplidar_ros
git clone -b ros2 https://github.com/Slamtec/rplidar_ros.git

Step 2. Install the dependencies

cd ~/ros2_ws
rosdep update
rosdep install --from-paths src --ignore-src -r -y

Step 3. Build the package

colcon build

Step 4. Source the workspace

source install/setup.bash

All commands of steps 2–4:

2. Launch the RPLIDAR node

With the robopeak repository the launch file is rplidar.launch.py:

ros2 launch rplidar_ros rplidar.launch.py

If you see this error, switch to Slamtec/rplidar_ros (-b ros2) as in Step 1.

With Slamtec/rplidar_ros (used from here on) the A1 has its own launch file:

ros2 launch rplidar_ros rplidar_a1_launch.py

3. Troubleshooting: code: 80008004

Output:

jetson@nano:~/ros2_ws$ ros2 launch rplidar_ros rplidar_a1_launch.py
[INFO] [launch]: All log files can be found below /home/jetson/.ros/log/2024-11-18-19-01-13-608322-nano-15970
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [rplidar_node-1]: process started with pid [15976]
[rplidar_node-1] [INFO] [1731952874.222439109] [rplidar_node]: RPLidar running on ROS2 package rplidar_ros. RPLIDAR SDK Version:2.1.0
[rplidar_node-1] [ERROR] [1731952874.222796098] [rplidar_node]: Error, unexpected error, code: 80008004
[ERROR] [rplidar_node-1]: process has died [pid 15976, exit code 255, cmd '/home/jetson/ros2_ws/install/rplidar_ros/lib/rplidar_ros/rplidar_node --ros-args -r __node:=rplidar_node --params-file /tmp/launch_params_68htuxzc'].

Step 1. Check the port name

ls /dev/ttyUSB*

Step 2. Add your user to the dialout group

sudo usermod -a -G dialout $USER

Check the groups:

groups $USER

Step 3. Give access to the USB port

sudo chmod 666 /dev/ttyUSB0

Step 4. Edit rplidar_a1_launch.py

nano ~/ros2_ws/src/rplidar_ros/launch/rplidar_a1_launch.py

I changed serial_port, serial_baudrate, frame_id, inverted = False and angle_compensate = True in the Node(...) part:

📄 ~/ros2_ws/src/rplidar_ros/launch/rplidar_a1_launch.py (the Node part, transcribed from the screenshot)

        Node(
            package='rplidar_ros',
            executable='rplidar_node',
            name='rplidar_node',
            parameters=[{'channel_type': channel_type,
                         'serial_port': '/dev/ttyUSB0',
                         'serial_baudrate': 115200,
                         'frame_id': 'laser_frame',
                         'inverted': False,
                         'angle_compensate': True}],
            output='screen'),

⚠️ In the screenshot /dev/ttyUSB0 and laser_frame have no quotes. They have to be Python strings ('/dev/ttyUSB0', 'laser_frame'), otherwise the launch file does not load.

💡 The same file already declares launch arguments (serial_port, serial_baudrate, frame_id, inverted, angle_compensate). With the unedited file you can pass the values on the command line instead:
ros2 launch rplidar_ros rplidar_a1_launch.py serial_port:=/dev/ttyUSB0 frame_id:=laser_frame

Finally the RPLIDAR A1 works:

rplidar_node: health status OK, scanning at 10 Hz


➡️ Next: Ros2 Cartographer Setup(2)_custom serial communication node

0개의 댓글