1、Introduction to Navigation2

Navigation2 overall architecture diagram

image-20231218212443190

Navigation2 has the following tools:

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

Use Behavior Trees (BT, Behavior Trees) to call the modular server 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 the Behavior Tree (BT) through the action server.

Information reference website:

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

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

Papers corresponding to Navigation2:https://arxiv.org/pdf/2003.00368.pdf

Plug-ins provided by Navigation2:https://navigation.ros.org/plugins/index.html#plugins

2. Program function description

The car connects to the agent, runs the program, and the map will be loaded in rviz. In the rviz interface, use the [2D Pose Estimate] tool to give the initial pose of the car, 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 an obstacle during the process, it will avoid the obstacle by itself and stop when it reaches the destination.

3. Start and connect to the agent

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

image-20240102115954697

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

image-20231218213749352

4. Start the program

First, start the car to process the underlying data program and enter the terminal.

image-20231218213851614

Then, start rviz, visual navigation, and terminal input.

image-20231218213935963

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

image-20231219114410953

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

image-20231219114520084

For single-point navigation, click the [2D Goal Pose] tool, and then select a target point in rviz. The car will plan a path based on the surrounding situation and move along the path to the target point.

image-20231219114601157

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

image-20231219120654717

After adding, rviz displays as follows.

image-20231219120733818

Then click [Waypoint/Nav Through Poses Mode],

image-20231219121038108

 

Use [Nav2 Goal] in the rivz toolbar to specify any target point, and then click [Start Waypoint Following] to start planning path navigation. The car will automatically go to the next point according to the order of the selected points, and no operation is required after reaching the target point. After reaching the last point, the car stops and waits for the next instruction.

image-20231219121141361

5. View the node communication diagram

Terminal input,

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

6. View TF tree

Terminal input,

image-20231219114813673

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

image-20231219114841333

7. Code analysis

Here we only describe the navigation_dwb_launch.py of navigation. The path of this file 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 also loaded. The navigation parameter table is located at,

The map file is as follows

dwb_nav_params.yaml,

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