for docker

sudo docker run -it --device /dev/ttyUSB0:/dev/ttyUSB0 ubuntu:focal

Step 1: After setting up the jetson nano and installing ros2 foxy, go onto this link and follow the instructions but MAKE SURE TO SOURCE AS ROS FOXY.

GitHub - CreedyNZ/rplidar_ros2: rplidar_ros2 rplidar ros2

source /opt/ros/foxy/setup.sh

colcon build instead of doing colcon build --symlink-install

Step 2: Plug in the RPLidar to the Jetson Nano.

Step 3: Run the package using the instructions from the GitHub link. When running the package, you will get a cannot bind to specific serial port error / dev/ttyUSB0, run the following line to fix it: sudo chmod 666 /dev/ttyUSBO and run the package again.

Step 4: When you run the package, and when rviz opens, change the fix frame from map to laser frame. Add a visualisation by display type and choose laserScan. You should be able to visualise what the RPLidar can see. Change the LaserScan size from 0.01 to 0.05 if needed.


import os from launch import LaunchDescription from launch.actions import ExecuteProcess from launch_ros.actions import Node

def generate_launch_description():

Set paths

install_path = os.path.join(os.getcwd(), 'install') rplidar_package_path = os.path.join(install_path, 'rplidar_ros/share/rplidar_ros') rviz_config_path = os.path.join(rplidar_package_path, 'rviz/rplidar.rviz')

import os
from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch_ros.actions import Node

def generate_launch_description():
    # Set paths
    install_path = os.path.join(os.getcwd(), 'install')
    rplidar_package_path = os.path.join(install_path, 'rplidar_ros/share/rplidar_ros')
    rviz_config_path = os.path.join(rplidar_package_path, 'rviz/rplidar.rviz')

    # Source setup.bash script
    source_cmd = ExecuteProcess(
        cmd=['bash', '-c', 'source ./install/setup.bash'],
        output='screen'
    )

    # Run rplidarNode
    rplidar_node = Node(
        package='rplidar_ros',
        executable='rplidarNode',
        output='screen'
    )

    # Run static_transform_publisher
    static_transform_publisher = Node(
        package='tf2_ros',
        executable='static_transform_publisher',
        arguments=['0', '0', '0', '0', '0', '0', 'world', 'laser_frame'],
        output='screen'
    )

    # Run rviz2
    rviz_node = Node(
        package='rviz2',
        executable='rviz2',
        arguments=[rviz_config_path],
        output='screen'
    )

    # Run rplidarNodeClient
    rplidar_client_node = Node(
        package='rplidar_ros',
        executable='rplidarNodeClient',
        output='screen'
    )

    return LaunchDescription([
        source_cmd,
        rplidar_node,
        static_transform_publisher,
        rviz_node,
        rplidar_client_node
    ])