Welcome to DOFBOT SE repository
13.Synchronous action
Synchronous Action
Note: This experiment requires two DOFBOTs.
12.1 Communication Principle
The principle of this experiment is to use one DOFBOT as the server, start TCP network service, receive data, and execute operations; while the other DOFBOT acts as the client (controller), reading all servo angles in sequence, and then immediately sending all servo angles to the server via TCP service. At this time, the client continues to quickly read servo angle values and send them to the server. The server receives and immediately updates all servo angles. In this way, the two DOFBOTs achieve remote synchronous motion.
12.2 Pre-Experiment Preparation
- This experiment involves two DOFBOTs with identical hardware. Only the running programs are different; everything else can be the same.
- Ensure both DOFBOTs are connected to the same local area network, that is, connected to the same router (either wired or wireless connection), and can communicate within the LAN.
- Since this experiment involves two DOFBOTs, to easily distinguish them, we call the DOFBOT acting as the server "DOFBOT A" (controlled party), and the DOFBOT acting as the controller "DOFBOT B" (freely movable party). DOFBOT B needs to press the K2 emergency stop button to release the servo torque. Since DOFBOT A's movements depend on DOFBOT B's movements, to avoid DOFBOT A's movement range being too large when the program starts, before starting the program, it is best to adjust both DOFBOT A and DOFBOT B to the vertical upward position.

12.3 Program Code
【Server code: DOFBOT A】
For specific code, see the content at the following path:
/home/yahboom/Dofbot/7.sync_movement/A_arm_follow.py
【Client code: DOFBOT B】
For specific code, see the content at the following path:
xxxxxxxxxx/home/yahboom/Dofbot/7.sync_movement/B_arm_ctrl.py
12.4 Operation Experiment and Purpose
Experiment purpose: Use DOFBOT B to remotely control DOFBOT A.
- Open the terminal of DOFBOT A and run the A_arm_follow.py program. Then note down the printed IP address.
xxxxxxxxxxcd /home/yahboom/Dofbot/7.sync_movement/python3 A_arm_follow.py

- Open the terminal of DOFBOT B, and replace the IP address in B_arm_ctrl.py with the IP address noted in the previous step.

- After modification, save and exit, then run the B_arm_ctrl.py program.
xxxxxxxxxxcd /home/yahboom/Dofbot/7.sync_movement/python3 B_arm_ctrl.py

Note: Be sure to run DOFBOT A's A_arm_follow.py program first, then run DOFBOT B's B_arm_ctrl.py program. DOFBOT B's terminal will print connection information and the data being sent. At the same time, the communication between the two DOFBOTs officially begins.
At this point, you can see that DOFBOT A's state is already the same as DOFBOT B's state. By moving DOFBOT B's posture, you can change DOFBOT A's posture. Through this TCP transmission command, the two DOFBOTs can achieve synchronous motion. DOFBOT A is controlled with angle limitations, while DOFBOT B can move freely without angle limitations. If DOFBOT B's servo 1 is moved beyond 180 degrees, DOFBOT A will stay at 180 degrees until DOFBOT B's angle is adjusted back to a reasonable range before it can continue moving.