ROS 2 Navigation

1. Introduction

  • The goal of this tutorial is

    • to use the ROS 2 navigation capabilities to move the robot autonomously.

  • The packages you will use:

    • workshop_ros2_navigation

Lines beginning with # indicates the syntax of these commands.

Commands are executed in a terminal:

  • Open a new terminal → use the shortcut ctrl+alt+t.

  • Open a new tab inside an existing terminal → use the shortcut ctrl+shift+t.

  • Lines beginning with $ indicates the syntax of these commands.

  • The computer of the real robot will be accessed from your local computer remotely. For every further command, a tag will inform which computer has to be used. It can be either [TurtleBot] or [Remote PC].

You can use the given links for further information.

2. General Approach

The ROS 2 Navigation System is the control system that enables a robot to autonomously reach a goal state, such as a specific position and orientation relative to a specific map. Given a current pose, a map, and a goal, such as a destination pose, the navigation system generates a plan to reach the goal, and outputs commands to autonomously drive the robot, respecting any safety constraints and avoiding obstacles encountered along the way.

It consists of several ROS components. An overview of its interactions is depicted in the following picture:


Figure 1: Navigation2 Architecture

source: navigataion

3. Launch the navigation stack

3.1. Check the map

  1. Check the location of your map

    Once you create a map, you will have two files: “name of your map”.pgm and “name of your map”.yaml

    For example, a workspace has the following layout:

  2. Check if the location of “name of your map”.pgm in “name of your map”.yaml is right

    For example, the context of “my_map.yaml” is as followed:

      # my_map.yaml
      image: ./my_map.pgm
      resolution: 0.050000
      origin: [-10.000000, -10.000000, 0.000000]
      negate: 0
      occupied_thresh: 0.65
      free_thresh: 0.196

    Hint: make sure that there is the right path of my_map.pgm in my_map.yaml. The path of “my_map.png” in “my_map.yaml” is relative. So if “my_map.yaml” and “my_map.png” are in the same folder, the parameter of “image” should be “image: ./my_map.pgm”

3.2. Start the simulated robot

  1. Open a terminal

  2. Set ROS environment variables

    • First you need to go into your workspace and source your workspace:

      $ source install/setup.bash
    • Set up Gazebo model path:

      $ export GAZEBO_MODEL_PATH=`ros2 pkg \
      prefix turtlebot3_gazebo`/share/turtlebot3_gazebo/models/
    • set up the robot model that you will use:

      $ export TURTLEBOT3_MODEL=burger
  3. Bring up Turtlebot in simulation

    # in the same terminal, run
    $ ros2 launch turtlebot3_gazebo
  4. Start navigation stack

    Open another terminal, source your workspace, set up the robot model that you will use, then

    $ ros2 launch turtlebot3_navigation2 \ \
    use_sim_time:=true map:=maps/"you map name".yaml

    The path of the map is relative to the place where you will run this command.

    You also can use this command to check which parameter that you can define:

    ros2 launch turtlebot3_navigation2 \

    If everything has started correctly, you will see the RViz and Gazebo GUIs like this. ../../_images/rviz_navigation_1.pngrviz_navigation_1


3.3. Start with a physicals robot

Open a terminal on TurtleBot3.

Bring up basic packages to start TurtleBot3 applications.


$ source .bashrc
$ ros2 launch turtlebot3_bringup

[Remote PC]

$ cd "your workspace"
$ source install/setup.bash
$ export ROS_DOMAIN_ID =
 "same as ROS DOMAIN ID of the turtlebot you are using"
$ ros2 launch turtlebot3_navigation2\