Welcome to DOGZILLA-Lite repository
7. Single Leg Control
Single Leg Control
1. Purpose
Learning single-leg control of a robot dog
2. Experimental path source code
Enter the robot dog system, end the robot dog program, enter "ip (ip is the robot dog's ip): 8888" in the browser, and enter the password "yahboom"

Then log in and go to cd ~/DOGZILLA_Lite_class/3.Dog Base Control/07.Dog Single Leg Control and run Single_Leg_Control.ipynb .
3. Experimental Phenomenon
After running each source code, you can assign a value according to the control you want to control the single leg of the mechanical dog.
4. Main source code analysis
This source code uses kinematic forward and inverse solutions to control a leg's servo and unload and load the servo. The servo ID and leg name are located in the robot dog as shown in the figure:

- motor(motor_id, data): The API function for positive calculation, which inputs the servo ID number and the corresponding servo angle to control the rotation of the servo
| Parameter name | scope | illustrate |
|---|---|---|
| motor_id | [11,12,13,21,22,23,31,32,33,41,42,43,51,52,53] | The first digit represents the leg where the servo is located, and the second digit represents the position on the leg, from bottom to top, they are 1, 2, 3 (51\52\53 are the ID numbers of the robot arm, which will not be explained in detail in this chapter, but will be explained in the robot arm chapter) |
| data | Lower: [-70, 50], Middle: [-66, 93], Upper: [-31, 31] | This parameter represents the angular position of the servo, in degrees |
- leg(leg_id, data): Kinematic inverse solution API function, which passes in the end position of the leg and controls the robot dog's servo to reach the corresponding angle through the inverse solution algorithm.
| Parameter name | scope | illustrate |
|---|---|---|
| leg_id | 1, 2, 3, 4 | Respectively represent the left front leg, right front leg, right hind leg, left hind leg |
| data | x:[-35,35],y:[-18,18],z:[75,115] | This parameter represents the foot end position, the unit is mm |
The four legs take the middle point of their shoulders as the origin, the front is the positive direction of the X axis, the left is the positive direction of the Y axis, and the bottom is the direction of the Z axis.

- load_motor(leg_id): Loading a single leg servo . At this time, you cannot change the state of the leg to be loaded by hand when the robot is powered on.
| Parameter name | scope | illustrate |
|---|---|---|
| leg_id | 1, 2, 3, 4 | Respectively represent the left front leg, right front leg, right hind leg, left hind leg |
- unload_motor(leg_id): unload a single leg servo . At this time, you can use your hand to change the shape of the leg to be unloaded when the robot dog is powered on.
| Parameter name | scope | illustrate |
|---|---|---|
| leg_id | 1, 2, 3, 4 | Respectively represent the left front leg, right front leg, right hind leg, left hind leg |