Welcome to MicroROS Self-balancing Robot Car repository
1.Multi-machine handle control
Multi-car handle control
Note: The virtual machine needs to be in the same LAN as the car, and the ROS_DOMAIN_ID needs to be consistent. You can check [Must-read before use] to set the IP and ROS_DOMAIN_ID on the board.
1. Program function description
After the program is started, the handle can be used to control the synchronous movement of the two cars. The handle program here is based on the [ROS robot USB wireless handle] sold by Yabo Intelligent Technology. Other handle programs may not be compatible and need to be modified according to the actual remote control key value.
2. Basic settings for multi-machine functions
Taking two cars as an example, it is recommended to use two computers with matching virtual machines, change the config_robot.py files respectively, set robot.set_ros_namespace() to robot1 and robot2 respectively; set robot.set_udp_config() to the IP addresses of the two virtual machines respectively, and the ROS_DOMAIN_ID of the two cars and the ROS_DOMAIN_ID of the virtual machine need to be set to the same. Then open the terminal in the /home/yahboom directory and enter sudo python3 config_Balance_Car.py to run this program (you need to change the rest of the programs other than running multiple cars and rerun this program).

3. Start and connect the agent
Take the matching virtual machine as an example. In the two virtual machines, enter the following command to start the agent of each car.
xxxxxxxxxxsudo docker run -it --rm -v /dev:/dev -v /dev/shm:/dev/shm --privileged --net=host microros/micro-ros-agent:humble udp4 --port 8899 -v4 
Then, turn on the switches of the two cars and wait for the two cars to connect to their respective agents. If the connection is successful, the terminal display is as shown in the figure below.

Check the currently started node. In the two virtual machines, randomly select one and open the terminal to enter,
xxxxxxxxxxros2 node list 
As shown in the figure above, the nodes of both cars have been started. Check the current topic information, input in the terminal,
xxxxxxxxxxros2 topic list 
3. Start the controller control program
Connect the controller receiver to any virtual machine. You need to ensure that the virtual machine can recognize the controller receiver. If it is connected as shown in the figure below, it means it is connected.

If it is not connected, check [Virtual Machine] -> [Removable Devices] in the menu bar on the virtual machine toolbar, and check whether [DragonRise Controller] is checked.
3.1 Run command
In the virtual machine of the connected handle receiver, take the matching virtual machine as an example, input in the terminal,
xxxxxxxxxxros2 launch yahboomcar_multi yahboomcar_multi_joy_launch.pyObserve the handle indicator light, if it is always on, it means the connection is successful. After the program starts, press [START], and the buzzers of the two cars will sound at the same time. Press the R1 key, and the terminal prints the following information, turning on the handle control. You can use the left joystick up and down to control the two cars to move forward and backward at the same time; you can use the right joystick left and right to control the two cars to turn left and right at the same time;
xxxxxxxxxx[yahboom_joy-2] [INFO] [1735197789.731509428] [joy_ctrl]: Play:trueThe remote control button description is as follows:
Left joystick: front and back directions are valid, controlling the car to move forward and backward, and left and right directions are invalid
Right joystick: left and right directions are valid, controlling the car to turn left and right, and front and back directions are invalid
START button: buzzer control
R1 button: handle control speed switch, press it to control the car speed with the remote control
MODE button: switch mode, use the default mode, after switching modes, if the key value is incorrect, the program will report an error and exit.
4. View the node communication graph
Select one of the two virtual machines at random and enter in the terminal,
xxxxxxxxxxros2 run rqt_graph rqt_graph
If it is not displayed at the beginning, select [Nodes/Topics(all)] and click the refresh button in the upper left corner.
5. Source code analysis
Source code reference path (taking the supporting virtual machine as an example):
xxxxxxxxxx/home/yahboom/yahboomcar_ws/src/yahboomcar_multi/yahboomcar_multimulti_yahboom_joy.py,
xxxxxxxxxx#Create topic publisher#create pubself.pub_goal = self.create_publisher(GoalID,"move_base/cancel",10)self.pub_JoyState = self.create_publisher(Bool,"JoyState", 10)#cmd_velself.pub_cmdVel_r1 = self.create_publisher(Twist,'/robot1/cmd_vel_bl',10)self.pub_cmdVel_r2 = self.create_publisher(Twist,'/robot2/cmd_vel_bl',10)self.pub_cmdVel_r3 = self.create_publisher(Twist,'/robot3/cmd_vel_bl',10)#beepself.pub_Buzzer_r1 = self.create_publisher(UInt16,"/robot1/beep", 1)self.pub_Buzzer_r2 = self.create_publisher(UInt16,"/robot2/beep", 1)self.pub_Buzzer_r3 = self.create_publisher(UInt16,"/robot3/beep", 1)#Create topic subscriber, subscribe to /joy node informationself.sub_Joy = self.create_subscription(Joy,'joy', self.buttonCallback,10)#Callback functiondef buttonCallback(self,joy_data):if not isinstance(joy_data, Joy): returnself.user_jetson(joy_data)#Process remote control key values, for detailed code, refer to user_jetson function#Publish speed topicself.pub_cmdVel_r1.publish(twist)self.pub_cmdVel_r2.publish(twist)#Publish buzzer topicself.pub_Buzzer_r1.publish(b)self.pub_Buzzer_r2.publish(b)