Welcome to ROSMASTER M1 repository
2.Multi-vehicle navigation
Multi-vehicle navigation
1. Program Description
This function allows you to assign two cars different navigation points in RVIZ. The two cars will plan routes based on their respective positions on the map and navigate to the designated locations, avoiding obstacles in real time.
1.1. Functional Requirements
For more information, please refer to [12.Multi-vehicle Course] -- [1.Multi-vehicle control] -- [1.1. Functional Requirements]
1.2. Navigation Map
Before starting a multi-car platoon, you need to place the map file on the mainboard or in a virtual machine.
~/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_nav/maps/yahboomcar.yaml~/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_nav/maps/yahboomcar.pgm
The map file includes a .yaml parameter file and a .pgm image file.
Note: Both cars require the same map file
2. Program Startup
Using the Raspberry Pi 5 as an example, due to performance issues, a virtual machine is required for visualization.
The virtual machine must be on the same local area network as both robots, and the ROS_DOMAIN_ID must be set to the same for both robots. Modify the contents of ~/.bashrc and refresh the environment variables after the modification.
For Raspberry Pi and Jetson-Nano boards, you need to open a terminal on the host computer and enter the command to enter the Docker container. Once inside the Docker container, enter the commands mentioned in this lesson in the terminal. For instructions on entering the Docker container from the host computer, refer to [01. Robot Configuration and Operation Guide] -- [4.Enter Docker (For JETSON Nano and RPi 5)].
For RDKX5 and Orin boards, simply open a terminal and enter the commands mentioned in this lesson.
This example uses two robots, Robot1 and Robot2. Please place them nearby in advance to ensure smooth network connectivity. This example requires a high data transfer rate.
2.1. Starting Chassis Data
On Robot1, open the terminal and enter the following command to start chassis data fusion, including radar data, filtered IMU and ODOM data, and EKF fusion.
xxxxxxxxxxros2 launch yahboomcar_multi M1_laser_bringup_multi_launch.xml robot_name:=robot1

Similarly, on Robot2, open the terminal and enter the following command to start chassis data fusion.
xxxxxxxxxxros2 launch yahboomcar_multi M1_laser_bringup_multi_launch.xml robot_name:=robot2

2.2. Launching rviz and Publishing Map Data
In the virtual machine configured for multi-machine communication, open a terminal and enter the following command to launch rviz.
xxxxxxxxxxros2 launch yahboomcar_multi display_multi_nav_launch.py
After launching, the image below appears.

Then launch the map loading program. The default map launched is yahboomcar.yaml, and the file path is:
xxxxxxxxxx~/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_nav/maps/yahboomcar.yaml
Enter the following command in the terminal to launch (you only need to load the map service in one robot's terminal).
xxxxxxxxxxros2 launch yahboomcar_multi map_server_launch.py

Next, on the virtual machine, our rviz visualization loads the created map.
(Due to network issues, the map may not be transferred to the virtual machine. Press Ctrl+C to shut it down and then restart the map loading service.)

2.3. Start AMD positioning
Open the terminal on robot1 and enter the following command to start AMD positioning.
xxxxxxxxxxros2 launch yahboomcar_multi M1_amcl_robot1_launch.py

Open the terminal on the robot2 car and enter the following command to start AMCL positioning.
xxxxxxxxxxros2 launch yahboomcar_multi M1_amcl_robot2_launch.py

As shown in the figure below, the error message "AMCL cannot publish a pose or update the transform. Please set the initial "pose..." indicates that the program is running the amcl positioning program.

Next, based on the car's position on the actual map, we use the [2D Pose Estimate] tool in rviz2 to give the car an initial pose. Here, rviz has two [2D Pose Estimate], the first tool is used to set the initial pose of robot 1, and the second tool is used to set the initial pose of robot 2. Use these two tools to set the initial poses for both robots.
As shown in the figure below, the areas scanned by the two radars overlap with the black area on the map. The blue point cloud represents the radar scan of robot 2, and the red point cloud represents the radar scan of robot 1.

2.4. Start nav2 Navigation
On robot 1, open the terminal and enter the following command to start nav2 navigation for robot 1.
xros2 launch yahboomcar_multi M1_nav_robot1_launch.py
On robot 2, open the terminal and enter the following command to start nav2 navigation for robot 2.
xros2 launch yahboomcar_multi M1_nav_robot2_launch.py
If both launch successfully, the expansion area shown in the image below will appear.

You can use the [2D Goal Pose] tool as shown below to navigate car number one.

Use the [2D Goal Pose] tool to assign a target point to each robot. RViz offers two [2D Goal Pose] tools: the first for robot1 and the second for robot2. Use these tools to assign target points to both robots, as shown in the image below. After assigning a target point, the robot will plan a path and navigate to it. The image below shows simultaneous navigation for both robots.
