Welcome to Muto S2 Robot repository
12.Teach pendant synchronized action
12、Teach pendant synchronized action
12、Teach pendant synchronized action12.1、Purpose12.2、Communication principles12.3、Preparation before experiment12.4、code12.5、Operational experiments and experimental purposes
12.1、Purpose
Using the LAN TCP remote communication function, one six-legged robot can remotely control another six-legged robot.
12.2、Communication principles
The principle of this experiment is to use one of the six-legged robots as a server, open the TCP network service, receive data, and perform operations; while the other six-legged robot serves as the client, that is, the operator, to read the angle value of the servo , and then sends the angle of the servo to the server through the TCP service; at this time, the client has been rapidly reading the angle value of the servo and sent it to the server. The server receives and immediately updates the angle of the servo, thereby realizing remote control of two hexapod robots. The function of synchronizing actions.
12.3、Preparation before experiment
- This experiment involves two hexapod robots with the same hardware. Except for the different running programs, everything else can be the same. If the six-legged robot uses the system image that comes with the factory, please end the factory program that starts automatically at boot before performing this experiment.
- Ensure that both six-legged robots are connected to the same LAN, that is, connected to the same router (either wired or wireless), and can communicate within the LAN.
- Since there are two hexapod robots involved here, in order to easily distinguish them, we call the hexapod robot that is the server A hexapod robot (the controlled party), and the hexapod robot that is the controller is called A hexapod robot. B six-legged robot (free to move). Since the movement of hexapod A depends on the movement of hexapod B, please set both hexapods to their default postures before starting the program.
12.4、code
【Server code: A six-legged robot】
Please see the content of the following path for the specific code:
~/muto/Samples/AI_Samples/12_sync_movement/A_robot_follow.py
【Client code: B six-legged robot】
Please see the content of the following path for the specific code:
xxxxxxxxxx~/muto/Samples/AI_Samples/12_sync_movement/B_robot_ctrl.py
12.5、Operational experiments and experimental purposes
- Open the terminal of the A hexapod robot and run the A_robot_follow.py program. Then write down the printed IP address.
xxxxxxxxxxpython3 ~/muto/Samples/AI_Samples/12_sync_movement/A_robot_follow.py
- Open the terminal of B hexapod robot and replace the IP address noted in the previous step to the ip address in B_robot_ctrl.py.
xxxxxxxxxx# 根据A_Robot的IP地址修改以下参数# Modify the following parameters based on the IP address of A_Robotip = '192.168.2.112'port = 6100robot_init()try:ready()connect_tcp_server(ip, port)except:g_bot.load_leg(1)g_bot.zero_reset()waitClose(g_socket)del g_botprint(" Program closed! ")
- After the modification is completed, save and exit, and then run the B_robot_ctrl.py program.
xxxxxxxxxxpython3 ~/muto/Samples/AI_Samples/12_sync_movement/B_robot_ctrl.py
Note that you must first run the A_robot_follow.py program of the A hexapod robot, and then run the B_robot_ctrl.py program of the B hexapod robot. The B hexapod robot terminal will print the connection information and the sent data, and the communication between the two hexapod robots will officially begin.
At this time, you can see that the state of the A hexapod robot is the same as that of the B hexapod robot, and you can move the leg1 leg of the B hexapod robot by rotating it, and the leg1 leg of the A hexapod robot will also move with it.
Through such TCP transmission commands, the effect of synchronized movements of two six-legged robots can be achieved. When turning the servo angle of the hexapod robot, please be careful that the angle range does not exceed the control range of the servo.