Welcome to ROSMASTER M3 repository
1.Multi-vehicle Control
Multi-vehicle Chassis Control
Multi-vehicle Chassis Control1. Content Description2. Preparation Work2.1 Basic Requirements2.2 Setting Vehicle Unit DOMAIN_ID2.2.1 Setting Vehicle Unit Main Control DOMAIN_ID2.2.2 Setting Vehicle Unit STM32 Main Control Board DOMAIN_ID2.3 Modify Vehicle Unit Namespace3. Starting Example Programs3.1 Node Communication3.2 Principle Analysis
1. Content Description
- Run example programs to implement simultaneous control of multiple vehicle units using the keyboard. This tutorial uses 2 vehicle units as an example.
2. Preparation Work
2.1 Basic Requirements
Taking two vehicles as an example, these two vehicles need to simultaneously meet the following three requirements:
- Both vehicle units need to be on the same local area network
- The
ROS_DOMAIN_IDof the main control ROS environment for both vehicle units needs to be the same - The
namespaceof both vehicle units must be set to different values
2.2 Setting Vehicle Unit DOMAIN_ID
- The factory default is 30. If you need to modify it to a specified value, refer to this part of the tutorial. Normally, you don't need to modify it as long as you ensure that the multi-vehicle
DOMAIN_IDis the same.
2.2.1 Setting Vehicle Unit Main Control DOMAIN_ID
For Raspberry Pi 5 users, if the ROS container is not started, you need to start the container first,
bringup_m3Open a terminal inside the container,
xxxxxxxxxxexec_m3- Enter the following command in the terminal to edit the environment file:
xxxxxxxxxxnano .bashrcFind ROS_DOMAIN_ID, modify it to the same value, then save and exit

- Refresh the environment variables in the terminal to see the updated
DOMAIN_ID

2.2.2 Setting Vehicle Unit STM32 Main Control Board DOMAIN_ID
- Edit the configuration program file (any editing method can be used, nano is used here as an example)
- Enter in the host machine terminal,
xxxxxxxxxxnano ~/config_robot.pyModify the value in robot.set_ros_domain_id(30), then press ctrl+x to save

- If the MicroROS agent is started, please close the agent first, then run the configuration program to write the DOMAIN_ID to the chassis control board
xxxxxxxxxxpython3 config_robot.py
2.3 Modify Vehicle Unit Namespace
The
namespaceof both small vehicles must be set to different values to prevent underlying data interference.Set the
namespaceof the first vehicle unit torobot1, and other vehicle units follow this pattern

- If the MicroROS agent is started, please close the agent first, then run the configuration program to write the
namespaceto the chassis control board
xxxxxxxxxxpython3 config_robot.py
3. Starting Example Programs
- Start the chassis communication for all vehicle units, enter the command in the vehicle unit terminal:
xxxxxxxxxxstart_agentThe terminal prints the following information, indicating successful connection

After completing the namespace setting and reconnecting the chassis agent, enter the following command in the corresponding terminal to check whether the namespace and ROS_DOMAIN_ID are set correctly
xxxxxxxxxxros2 node listAs shown in the figure below, the appearance of /robot1/YB_Node and /robot2/YB_Node indicates successful setting,

- Enter command in terminal
xxxxxxxxxxkeyboard_controlAfter the program starts, click on the terminal that started keyboard control, and press the corresponding keys according to the following key table to control the movement of two vehicles,
| Key | Action |
|---|---|
| i or I | Forward |
| < | Backward |
| j or J | Turn left in place |
| l or L | Turn right in place |
| u or U | Forward left turn |
| o or O | Forward right turn |
| m or M | Backward left turn |
| > | Backward right turn |
| k | Stop |
3.1 Node Communication
Enter the following command in the virtual machine terminal to view the node communication diagram,
xxxxxxxxxxros2 run rqt_graph rqt_graphAs shown in the figure below, select [Nodes/Topics(all)] in the upper left corner, then click the refresh button on the left

3.2 Principle Analysis
The keyboard control node /teleop_twist_keyboard publishes the speed topic /cmd_vel. The underlying nodes of both vehicles /robot1/YB_Node and /robot2/YB_Node subscribe to this /cmd_vel topic. After receiving the topic message data, they process it and pass it to the driver board, thereby controlling the vehicle movement.