Skip to main content

5.4.2 Navigation2

Introduction

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

SLAM Mapping explains how to run SLAM algorithms for mapping. This section introduces how to use Nav2 for navigation based on the created map. Similarly, use Gazebo on the PC to create a virtual environment and a car, use Rviz2 to set the navigation destination, and run the Nav2 program for navigation using the RDK.

Supported Platforms

PlatformExecutionFunction
RDK X3, RDK X3 Module, RDK X5Ubuntu 20.04 (Foxy), Ubuntu 22.04 (Humble)Start the simulation environment on the PC and start the navigation function on the RDK, and finally display the navigation effect through Rviz2

Preparation

RDK

  1. The RDK has been flashed with the Ubuntu 20.04/22.04 image provided by D-Robotics.

  2. The RDK has successfully installed tros.b.

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

sudo apt update 
sudo apt install ros-foxy-navigation2
sudo apt install ros-foxy-nav2-bringup
  1. The PC on the same network segment as the RDK has installed Ubuntu 20.04/22.04 system, ROS2 desktop version, simulation environment Gazebo, and data visualization tool Rviz2.
  • Ubuntu 20.04 system and ROS2 Foxy Desktop Full
  • Gazebo and Turtlebot3 related packages. Installation commands:
sudo apt-get install ros-foxy-gazebo-*
sudo apt install ros-foxy-turtlebot3*
sudo apt install ros-foxy-navigation2
sudo apt install ros-foxy-nav2-bringup

User Guide

RDK

This section describes how to set up a simulation environment on the PC, how to set the navigation destination, and how to run the navigation function with RDK and view the navigation result.

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

The simulation environment is shown in the following image:

  1. Start the navigation function on the RDK.

    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
  2. Start the Rviz2 tool on the PC.

source /opt/ros/foxy/setup.bash
ros2 launch nav2_bringup rviz_launch.py

The Rviz2 interface is shown in the following image:

  1. Set the initial position and orientation of the robot in Rviz2.

    After Rviz2 is launched, the robot does not know where it is initially. By default, Nav2 waits for the user to provide an approximate initial position for the robot. Refer to the robot's position in Gazebo and find that position on the map. Set the initial position of the robot by clicking the "2D Pose Estimate" button in Rviz2 and then clicking on the estimated position of the robot on the map. The initial movement direction of the robot can be set by dragging the clicked position forward. The process is shown in the following image:

    Once the initial position of the robot is set, the coordinate transformation tree will be established and Nav2 will be fully activated and ready. The robot and point cloud can be seen at this time.

  2. Set the destination in Rviz2.

    Click the "Navigation2 Goal" button and select a destination.Here is the translation of the Chinese parts in the content, while preserving the original format and content:

    Now you can see the robot is moving.

Result Analysis

The navigation effect is shown in the figure below: