CodeTheRobot

ROS 2 Lyrical Luth · Lesson 81 of 86

Building a full AMR stack

Project: drive base, sensors, localization and Nav2 as one package set.

Estimated time · 120–180 min

Learning goals

What you will understand

  • Explain building a full amr stack in your own words
  • Use it in a small robotics example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

An autonomous mobile robot (AMR) stack has layers: description (URDF/xacro), hardware or simulation (ros2_control, Gazebo), sensing (lidar, IMU, camera), state estimation (odometry, EKF, AMCL), navigation (Nav2) and a supervisor that receives goals. Each layer is a package with a clear interface, and one bringup package launches them.

Build it in the order of the dependencies and test each layer alone before adding the next: base drives on cmd_vel, sensors publish with the right frames, odometry matches distance driven, the map and localization work, then navigation. Keep parameters in YAML and use launch arguments for the simulation flag.

Guided lesson

Work through these steps

  1. 1.

    Source the ROS 2 Lyrical environment in a fresh terminal.

  2. 2.

    Read the building a full amr stack example and identify what each line does.

  3. 3.

    Build only the affected package, source the workspace overlay, and run the example.

  4. 4.

    Inspect the result from a second terminal with the ros2 CLI or RViz2 and compare it with the expected result.

Worked example

Read it before you run it

robot_ws/src/
# Workspace source folder.
  amr_description/    (URDF/xacro, meshes)
# The robot model.
  amr_bringup/        (launch, params, maps)
# One-command start-up.
  amr_gazebo/         (worlds, sim launch)
# Simulation.
  amr_navigation/     (Nav2 params, BT files)
# Navigation configuration.
  amr_interfaces/     (custom msgs, srvs, actions)
# Shared interfaces.
colcon build --symlink-install && source install/setup.bash
# Build and source everything.
ros2 launch amr_bringup bringup.launch.py sim:=true
# Start the whole robot in simulation.

What the example is doing

  1. 1.The ros2 commands query the running graph; they do not prove that a node's internal behavior is correct.
  2. 2.Build from the workspace root, then source install/setup.bash so the shell can discover the new package.
  3. 3.Use a second sourced terminal to inspect nodes and interfaces while the example runs.

Watch it run · Mobile robot

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.

goalMOBILE ROBOT

Demo for Building a full AMR stack. Expected result: The workspace builds and the robot navigates to a goal in simulation

Practice code

Now type it yourself

Copy the starter into your ROS 2 package, replace every TODO, then build with colcon build and run it from a sourced terminal.

cd ~/robot_ws/src
# TODO: create ament_cmake packages amr_description, amr_bringup and amr_navigation
cd .. && colcon build --symlink-install

Expected output

The workspace builds and the robot navigates to a goal in simulation
Stuck? Show the full solution (try it yourself first)
cd ~/robot_ws/src
ros2 pkg create --build-type ament_cmake --license Apache-2.0 amr_description
ros2 pkg create --build-type ament_cmake --license Apache-2.0 amr_bringup
ros2 pkg create --build-type ament_cmake --license Apache-2.0 amr_navigation
cd .. && colcon build --symlink-install

Expected result

How you know it worked

  • ROS_DISTRO is lyrical in every terminal used for the exercise.
  • The complete package from the exercise builds and the expected graph entity appears in a second terminal.

Practical exercise

Apply the lesson

Create the five packages, build a differential-drive AMR in Gazebo with lidar and IMU, map a small world, localize with AMCL and send three goals with a script. Record the acceptance checks each layer passed.

Before you continue

  • ROS_DISTRO reports lyrical in every terminal you used
  • The example builds and runs without errors
  • You checked the result with a ros2 command, RViz2 or a test, not just by reading the code

If something goes wrong

ros2 cannot find a package or executable.

Source /opt/ros/lyrical/setup.bash, build from the workspace root, then source install/setup.bash in that terminal.

Nodes run but cannot discover each other.

Confirm both terminals use Lyrical, the same ROS_DOMAIN_ID, and compatible network/discovery settings.