Welcome to DOFBOT Pro repository
12. Two DOFBOT Synchronized Actions
Two DOFBOT Synchronized Actions
Note: This experiment requires two Dofbot Pro.
12.1 Communication Principle
The principle of this experiment is to use one Dofbot Pro as a server, starting a TCP network service to receive data and execute operations; while the other Dofbot Pro acts as a client, also known as the controller, reading the angle values of all servos sequentially and immediately sending all servo angles to the server via TCP service. At this time, the client continuously reads servo angle values and sends them to the server. The server receives and sets the angles to immediately update all servos, achieving remote synchronized action between the two robotic arms.
12.2 Pre-Experiment Preparation
- This experiment involves two Dofbot Pro with identical hardware. Except for the different programs running, everything else can be the same. If the Dofbot Pro are using the factory system image, please first stop the auto-starting factory program before conducting this experiment.
- Ensure both Dofbot Pro are connected to the same local area network, i.e., connected to the same router (wired or wireless connection is acceptable), and can communicate within the local area network.
- Since this experiment involves two Dofbot Pro, to easily distinguish them, we call the Dofbot Pro acting as the server "Arm A" (the controlled side), and the Dofbot Pro acting as the controller "Arm B" (the freely movable side). Since Arm A's movement depends on Arm B's motion, to avoid excessive movement range of Arm A when starting the program, please adjust both Arm A and Arm B to an upright vertical position before starting the program.

12.3 Program Code
[Server Code: Arm A]
For specific code content, please refer to the following path:
~/dofbot_pro/dofbot_ctrl/scripts/12.sync_movement/A_arm_follow.py
[Client Code: Arm B]
For specific code content, please refer to the following path:
xxxxxxxxxx~/dofbot_pro/dofbot_ctrl/scripts/12.sync_movement/B_arm_ctrl.py
12.4 Experimental Operation and Purpose
Experimental Purpose: Use Arm B to remotely control Arm A.
- Open the terminal of Arm A and run the A_arm_follow.py program. Then note down the printed IP address.
xxxxxxxxxxcd ~/dofbot_pro/dofbot_ctrl/scripts/12.sync_movement/python3 A_arm_follow.py

- Open the terminal of Arm B and replace the IP address recorded in the previous step in the ip address position in B_arm_ctrl.py.

- After modification, save and exit, then run the B_arm_ctrl.py program.
xxxxxxxxxxcd ~/dofbot_pro/dofbot_ctrl/scripts/12.sync_movement/python3 B_arm_ctrl.py

Note: You must run Arm A's A_arm_follow.py program first, then run Arm B's B_arm_ctrl.py program. Arm B's terminal will print connection information and sent data, while communication between the two robotic arms officially begins.
At this time, you can see that Arm A's state is the same as Arm B's state, and you can modify Arm A's state by moving Arm B's posture. Through this TCP transmission command, the effect of synchronized action between two robotic arms can be achieved. Arm A's control has angle limitations, while Arm B's free movement has no angle limitations. If Arm B's servo 1 is moved beyond 180 degrees, Arm A will stay at 180 degrees until Arm B's angle is adjusted back to a reasonable range before continuing to move.