Skip to main content

5.4.2 Navigation2

Overview

Nav2 (Navigation2) is the built-in navigation framework in ROS2, designed to find a safe way for mobile robots to move from point A to point B. Nav2 can also be applied to other robot navigation scenarios, such as dynamic point tracking, which requires dynamic path planning, motor speed calculation, obstacle avoidance, and more.

SLAM Mapping describes how to run SLAM algorithms for mapping. This section describes how to use Nav2 for navigation based on the built map. Similarly, Gazebo is used on the PC to create a virtual environment and robot, Rviz2 is used to set navigation destinations, and the RDK runs the Nav2 program for navigation.

Supported Platforms

PlatformRuntime EnvironmentExample Functionality
RDK X3, RDK X3 ModuleUbuntu 20.04 (Foxy), Ubuntu 22.04 (Humble)Start the simulation environment on the PC, start navigation on the RDK, and display navigation results via Rviz2
RDK X5, RDK X5 ModuleUbuntu 22.04 (Humble)Start the simulation environment on the PC, start navigation on the RDK, and display navigation results via Rviz2
RDK S100, RDK S100PUbuntu 22.04 (Humble)Start the simulation environment on the PC, start navigation on the RDK, and display navigation results via Rviz2

Preparation

RDK Platform

  1. The RDK has been flashed with the Ubuntu system image.

  2. tros.b has been successfully installed on the RDK.

  3. After tros.b is installed, install Nav2.

# 配置tros.b环境
source /opt/tros/setup.bash
sudo apt update 
sudo apt install ros-${ROS_DISTRO}-navigation2
sudo apt install ros-${ROS_DISTRO}-nav2-bringup
Note

If the sudo apt update command fails or reports an error, please refer to the FAQ section Q10: How to handle apt update command failure or error? for resolution.

Note

If the sudo apt update command fails or reports an error, please refer to the FAQ section Q6: How to handle apt update command failure or error? for resolution.

  1. A PC on the same network as the RDK with Ubuntu, ROS2 desktop edition, Gazebo simulation environment, and Rviz2 visualization tool installed.
source /opt/ros/foxy/setup.bash

Ubuntu 20.04 and ROS2 Foxy desktop edition

After ROS2 is installed on the PC, install Gazebo and Turtlebot3 related packages as follows:

sudo apt-get install ros-${ROS_DISTRO}-gazebo-*
sudo apt install ros-${ROS_DISTRO}-turtlebot3*
sudo apt install ros-${ROS_DISTRO}-navigation2
sudo apt install ros-${ROS_DISTRO}-nav2-bringup

Usage

RDK Platform

This section describes how to set up the simulation environment on the PC, configure navigation destinations, run navigation on the RDK, and view navigation results.

  1. PC: Start the Gazebo simulation environment
source /opt/ros/foxy/setup.bash
export TURTLEBOT3_MODEL=waffle
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
info

If startup fails with the error [ERROR] [gzclient-2]: process has died, run source /usr/share/gazebo/setup.sh and start again.

The simulation environment is shown below:

  1. RDK: Start navigation
# 配置tros.b环境
source /opt/tros/setup.bash
ros2 launch nav2_bringup bringup_launch.py use_sim_time:=True map:=/opt/ros/foxy/share/nav2_bringup/maps/turtlebot3_world.yaml
  1. PC: Start Rviz2
# 配置tros.b环境
source /opt/tros/setup.bash
ros2 launch nav2_bringup rviz_launch.py

Rviz2 display is shown below:

(1) Set the robot's initial position and orientation in Rviz2

After Rviz2 starts, the robot initially does not know its location. By default, Nav2 waits for the user to provide an approximate starting position. Check the robot's position in Gazebo and locate it on the map. Click the "2D Pose Estimate" button in Rviz2, then click on the map at the robot's estimated position. Drag forward from the clicked position to set the robot's initial movement direction. As shown below:

Once the robot's initial position is set, the transform tree is completed and Nav2 becomes fully active and ready. You can then see the robot and point cloud.

(2) Set the destination in Rviz2

Click the "Navigaton2 Goal" button and select a destination.

You can now see the robot moving.

Result Analysis

The navigation result is shown below: