CodeTheRobot

Ubuntu Linux for Robotics · Lesson 74 of 96

Install Nav2

apt packages, the TurtleBot 3 demo and checking that the prerequisites work.

Estimated time · 45–60 min

Learning goals

What you will understand

  • Explain install nav2 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

Install Nav2 with sudo apt install ros-lyrical-navigation2 ros-lyrical-nav2-bringup, and the simulated TurtleBot 3 (ros-lyrical-turtlebot3-gazebo) for a first test. Nav2 is a set of lifecycle nodes (planner, controller, behavior, BT navigator, map server, AMCL) started by nav2_bringup.

Nav2 expects a working base: /cmd_vel drives the robot, /odom and the odom → base_link transform exist, a /scan publishes, and the URDF gives a complete TF tree. Test the demo first, then move to your own robot; if the demo fails your installation, not your robot, is the problem.

Guided lesson

Work through these steps

  1. 1.

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

  2. 2.

    Read the install nav2 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

sudo apt install ros-lyrical-navigation2 ros-lyrical-nav2-bringup ros-lyrical-turtlebot3-gazebo
# Install Nav2 and the demo robot.
export TURTLEBOT3_MODEL=waffle
# Choose the robot model.
ros2 launch nav2_bringup tb3_simulation_launch.py
# Start the simulation, Nav2 and RViz2.
ros2 lifecycle get /bt_navigator
# Check that Nav2 servers are active.
ros2 topic list | grep -E 'cmd_vel|odom|scan'
# Confirm the base topics exist.

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 · 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 Install Nav2. Expected result: primary state: active

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 the lifecycle state of /bt_navigator

Expected output

primary state: active
Stuck? Show the full solution (try it yourself first)
ros2 lifecycle get /bt_navigator

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

Install Nav2, run the TurtleBot 3 demo, set the initial pose with '2D Pose Estimate', send a goal, and record the lifecycle state of the servers with ros2 lifecycle get.

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.