CodeTheRobot

Ubuntu Linux for Robotics · Lesson 64 of 96

LiDAR drivers

Installing a lidar driver, serial permissions, the /scan topic and RViz2.

Estimated time · 45–75 min

Learning goals

What you will understand

  • Explain lidar drivers in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

A lidar driver node reads the sensor over USB, serial or Ethernet and publishes sensor_msgs/LaserScan on /scan. Install the driver for your model (many are in apt as ros-lyrical-<vendor>-ros2), make sure your user can open the device (dialout group or a udev rule), and set the frame id to the lidar link from your URDF.

Check in this order: the OS sees the device (lsusb, ls /dev/ttyUSB*), the node starts, ros2 topic hz /scan shows the rate, and RViz2 draws the scan in the right place. Wrong baud rate, missing permission and a wrong frame id are the usual failures.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the lidar drivers commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

ls -l /dev/ttyUSB* /dev/rplidar
# Confirm the device exists and see its owner and permissions.
sudo usermod -aG dialout $USER
# Allow your user to open serial devices (log out and in).
ros2 run sllidar_ros2 sllidar_node --ros-args -p serial_port:=/dev/rplidar -p frame_id:=lidar_link
# Start the driver with the port and frame id.
ros2 topic hz /scan
# Check the scan rate.
ros2 topic echo /scan --once --field header
# Check the frame id and timestamp.
rviz2
# Add a LaserScan display with Fixed Frame base_link.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

Watch it run · Sensor view

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

SENSOR VIEW

Demo for LiDAR drivers. Expected result: frame_id: lidar_link

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

# TODO: print only the header of one /scan message

Expected output

frame_id: lidar_link
Stuck? Show the full solution (try it yourself first)
ros2 topic echo /scan --once --field header

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Start a lidar driver (or play a bag), verify the rate and the frame id, view the scan in RViz2, and deliberately use the wrong frame id to see how the scan is drawn in the wrong place.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.