1. Navigation2 introduction

Navigation2 overall architecture diagram

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-20241228163948056

Then, start fast relocation and wait for rviz to be automatically opened.

Parameter Description

image-20241230141255298

At this time, you can see that the map is loaded, but the car is not accurately positioned. Then we click [2D Pose Estimate] to set the initial pose for the car. According to the approximate position of the car in the actual environment, click and drag with the mouse in rviz, and the car can be quickly positioned on the map. As shown in the figure below, the area scanned by the radar roughly coincides with the actual obstacle.

Note: If it still cannot be positioned, it may be that the car is in an obstacle area. Please place it in a place with no obstacles around it and start again. You can also keep the terminal open, restart the car directly, wait for the data to be automatically restored and then reposition. It may also be that there are too few map feature points when building the map, and the map must be built more carefully.

image-20241230141910329

Next, run the navigation node,

Take the virtual machine as an example, input in the terminal,

Parameter description

Note: Here, testaa.yaml and testaa.pbstream must be mapped at the same time, that is, the same map, refer to cartograph mapping algorithm to save the map

Single-point navigation, click the [2D Goal Pose] tool, 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-20241228165438137

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

image-20231219120654717

After adding, rviz displays as follows.

image-20241228170754338

Then click [Waypoint/Nav Through Poses Mode] and use the [Nav2 Goal】Give any target point,

image-20231219121038108

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 click the refresh button in the upper left corner.

rosgraph

6. View TF tree

Terminal input,

image-20241228171458227

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-20241228171432431

7. Code analysis

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

Here is a description of how to quickly relocate localization_imu_odom.launch.py.

The following nodes are started here:

 

Navigation node navigation_cartodwb_launch.py,

The following nodes are started here:

In addition, a navigation parameter configuration file dwb_nav_params.yaml is loaded.

The map file is located in,

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.