1. Navigation2 Introduction

Navigation2 Overall Architecture

image-20231218212443190

Navigation2 has the following tools:

Navigation 2 (Nav 2) is the navigation framework included with ROS 2. Its purpose is to enable a mobile robot to move from point A to point B in a safe way. Therefore, Nav 2 can perform behaviors such as dynamic path planning, calculating motor speeds, avoiding obstacles, and recovering structures.

Nav 2 uses behavior trees (BT) to call modular servers to complete an action. Actions can be path calculations, control efforts, recovery, or other navigation-related actions. These actions are independent nodes that communicate with behavior trees (BT) through action servers.

Reference URL:

Navigation2 Document: https://navigation.ros.org/index.html

Navigation2 github: https://github.com/ros-planning/navigation2

Navigation2 Corresponding Paper: https://arxiv.org/pdf/2003.00368.pdf

Plugins provided by Navigation2: https://navigation.ros.org/plugins/index.html#plugins

2. Program Function Description

The car connects to the proxy, runs the program, and the map will be loaded in rviz. In the rviz interface, use the [2D Pose Estimate] tool to give the car an initial pose, and then use the [2D Goal Pose] tool to give the car a target point. The car will plan a path based on its own environment and move to the destination according to the planned path. If it encounters obstacles during the process, it will avoid obstacles by itself and stop after reaching the destination.

3. Start and connect the agent

Take the supporting virtual machine as an example, enter the following command to start the agent,

image-20241226101427280

Then, turn on the car switch and wait for the car to connect to the proxy. The connection is successful as shown in the figure below.

image-20241226101559446

4. Start the program

4.1 Run the command

First, start the car to process the underlying data program. Take the matching virtual machine as an example. Enter the terminal,

image-20241228152432886

Then, start rviz, visualize navigation, and enter in the terminal

image-20231218213935963

At this time, the map loading is not displayed, because the navigation program has not been started, so there is no map loading. Next, run the navigation node,

Take the virtual machine as an example, terminal input,

image-20241228152532675

At this time, you can see that the map is loaded, and then we click [2D Pose Estimate】, set the initial pose for the car, and click and drag the mouse in rviz according to the position of the car in the actual environment, and the car model moves to the position we set. As shown in the figure below, if the area scanned by the radar roughly coincides with the actual obstacle, it means that the pose is accurate.

image-20241228152617378

Single-point navigation, click the [2D Goal Pose] tool, and then select a target point in rviz. The car plans a path based on the surrounding situation and moves to the target point along the path.

image-20241228152803294

For multi-point navigation, you need to add the nav2 plug-in.

image-20231219120654717

After adding, rviz displays as follows.

image-20241228152937484

Then click [Waypoint/Nav Through Poses Mode],

image-20231219121038108

Use the [Nav2 Goal】Give multiple arbitrary target points, then click 【Start Waypoint Following】to start planning path navigation. The car will automatically go to the next point after reaching the target point according to the order of the selected points, without any operation. After reaching the last point, the car stops and waits for the next instruction.

image-20231219121141361

5. View the node communication graph

Terminal input,

If it is not displayed at the beginning, select [Nodes/Topics(all)], and then click the refresh button in the upper left corner.

rosgraph

6. View TF tree

Terminal input,

image-20241228153734385

After running, two files will be generated in the terminal directory, namely .gv and .pdf files, and the pdf file is the TF tree.

image-20241228153717571

7. Code analysis

Here we only explain navigation_dwb_launch.py ​​of navigation,

Take the virtual machine as an example, the file path is,

navigation_dwb_launch.py,

The following nodes are started here:

In addition, a navigation parameter configuration file dwb_nav_params.yaml and a map file yahboom_map.yaml are loaded.

The map file is located at,

Take the virtual machine as an example, the navigation parameter table is located at,

dwb_nav_params.yaml,

This parameter table configures the parameters required for each node started in the navigation launch file.