Note: The ROS_DOMAIN_ID of the Raspberry Pi and the microROS control board need to be consistent. You can check [MicroROS Control Board Parameter Configuration] to set the microROS control board ROS_DOMAIN_ID. Check the tutorial [Connect MicroROS Agent] to determine whether the IDs are consistent.

1、Introduction to Navigation2

Navigation2 overall architecture diagram

image-20240126110308679

Navigation2 has the following tools:

● Tools for loading, serving, and storing maps (Map Server)

● Tool to locate the robot on the map (AMCL)

● Navigate from point A to point B with Nav2 Planner

● Tool to control the robot during the following path (Nav2 Controller)

● Tools for converting sensor data into cost map representations in the world of robotics (Nav2 Costmap 2D)

● Tools for building complex robot behaviors using behavior trees (Nav2 Behavior Trees and BT Navigator)

● Tool to calculate recovery behavior in the event of a failure (Nav2 Recoveries)

● Nav2 Waypoint Follower

● Tools and watchdog for managing server lifecycles (Nav2 Lifecycle Manager)

● Plugins that enable user-defined algorithms and behaviors (Nav2 Core)

Navigation 2 (Nav 2) is the navigation framework that comes with ROS 2 and aims to move mobile robots from point A to point B in a safe way. As a result, Nav 2 can perform dynamic path planning, calculate motor speed, avoid obstacles, and restore structures.

Nav 2 uses Behavior Trees (BT) to call modular servers to complete an action. Actions can be calculated paths, 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、Query car information

3.1、Start and connect to the agent

After the Raspberry Pi is successfully powered on, open the terminal and enter the following command to open the agent.

image-20240122162257264

Press the reset button on the microROS control board and wait for the car to connect to the agent. The connection is successful as shown in the figure below.

image-20240122162429192

3.2、Enter the car docker

Open another terminal and enter the following command to enter docker.

When the following interface appears, you have successfully entered docker. Now you can control the car through commands.

image-20240201151703606

4、starting program

First, start the car to process the underlying data program, and enter the following command in the terminal

image-20240126110602528

Then enter the command in the terminal to start rviz for visual navigation.

image-20240126110645296

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 the following command in the terminal.

image-20240126110823312

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

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

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

image-20240126111121433

After adding, rviz displays as follows.

image-20240126111151491

Then click [Waypoint/Nav Through Poses Mode].

image-20240126111254807

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

5、View node communication diagram

Terminal input command

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 command

image-20240126113822497

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

7、Code analysis

Here we only describe the navigation_dwb_launch.py of navigation. The path of this file is as follows.

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 path to the navigation parameter table is as follows.

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.