Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales@spotpear.com
dragon_manager@163.com
tech-support@spotpear.com
zhoujie@spotpear.com
WhatsApp:13246739196
Adjust the gait motion effect by modifying the gait-related parameters in ServoCtrl.h.
In ServoCtrl.h, in addition to the parameters in the Single Leg Control section, the parameters used for overall gait debugging are as follows:
According to the method introduced in single leg control, let each leg swing within its own motion cycle, with the left front leg as 1, the left rear leg as 2, the right front leg as 3, and the right rear leg as 4. When legs 1 and 4 swing according to the same motion cycle (referred to as Group A), and legs 2 and 3 swing according to the same motion cycle (referred to as Group B), Group A and Group B are phase-shifted by half a cycle. This ensures that at least one group is in support at any given moment.
void simpleGait(float GlobalInput, float directionAngle, int turnCmd){
float Group_A;
float Group_B;
Group_A = GlobalInput;
Group_B = GlobalInput+0.5;
if(Group_B>1){Group_B--;}
if(!turnCmd){
singleGaitCtrl(1, 1, Group_A, directionAngle, WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(4, 1, Group_A, -directionAngle, -WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(2, 1, Group_B, directionAngle, -WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(3, 1, Group_B, -directionAngle, WALK_EXTENDED_X, WALK_EXTENDED_Z);
}
else if(turnCmd == -1){
singleGaitCtrl(1, 1.5, Group_A, 90, WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(4, 1.5, Group_A, 90, -WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(2, 1.5, Group_B, -90, -WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(3, 1.5, Group_B, -90, WALK_EXTENDED_X, WALK_EXTENDED_Z);
}
else if(turnCmd == 1){
singleGaitCtrl(1, 1.5, Group_A, -90, WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(4, 1.5, Group_A, -90, -WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(2, 1.5, Group_B, 90, -WALK_EXTENDED_X, WALK_EXTENDED_Z);
singleGaitCtrl(3, 1.5, Group_B, 90, WALK_EXTENDED_X, WALK_EXTENDED_Z);
}
}
The code above is used to perform diagonal gait, with Group_A and Group_B phase-shifted by half a cycle
Group_A = GlobalInput;
Group_B = GlobalInput+0.5;
if(Group_B>1){Group_B--;}
GlobaIInput cycles from 0 to 1, and groups A and B obtain their own motion cycle parameters through the above algorithm, forming diagonal gait.
turnCmd is used to adjust the rotation direction. When turnCmd is 0, directionAngle can be used to adjust the translation direction (at which point the robot's head orientation remains unchanged)
The purpose of the triangular gait is to make the robot have at least three legs in the support pair at all times. This gait is more complex and requires more fine debugging to use. The diagonal gait mentioned above divides the four legs into two groups, A and B, while the triangular gait divides the four legs into four groups, with 1, 2, 3, and 4 corresponding to A, B, C, and D. The motion cycles of each two groups differ by at least 1/4 phase.
void triangularGait(float GlobalInput, float directionAngle, int turnCmd){
float StepA;
float StepB;
float StepC;
float StepD;
float aInput = 0;
float bInput = 0;
float adProp;
StepB = GlobalInput;
StepC = GlobalInput + 0.25;
StepD = GlobalInput + 0.5;
StepA = GlobalInput + 0.75;
if(StepA>1){StepA--;}
if(StepB>1){StepB--;}
if(StepC>1){StepC--;}
if(StepD>1){StepD--;}
if(GlobalInput <= 0.25){
adProp = GlobalInput;
aInput = WALK_MASS_ADJUST - (adProp/0.125)*WALK_MASS_ADJUST;
bInput = -WALK_MASS_ADJUST;
}
else if(GlobalInput > 0.25 && GlobalInput <= 0.5){
adProp = GlobalInput-0.25;
aInput = -WALK_MASS_ADJUST + (adProp/0.125)*WALK_MASS_ADJUST;
bInput = -WALK_MASS_ADJUST + (adProp/0.125)*WALK_MASS_ADJUST;
}
else if(GlobalInput > 0.5 && GlobalInput <= 0.75){
adProp = GlobalInput-0.5;
aInput = WALK_MASS_ADJUST - (adProp/0.125)*WALK_MASS_ADJUST;
bInput = WALK_MASS_ADJUST;
}
else if(GlobalInput > 0.75 && GlobalInput <= 1){
adProp = GlobalInput-0.75;
aInput = -WALK_MASS_ADJUST + (adProp/0.125)*WALK_MASS_ADJUST;
bInput = WALK_MASS_ADJUST - (adProp/0.125)*WALK_MASS_ADJUST;
}
if(!turnCmd){
singleGaitCtrl(1, 1, StepA, directionAngle, WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z - bInput);
singleGaitCtrl(4, 1, StepD, -directionAngle, -WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z + bInput);
singleGaitCtrl(2, 1, StepB, directionAngle, -WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z - bInput);
singleGaitCtrl(3, 1, StepC, -directionAngle, WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z + bInput);
}
else if(turnCmd == -1){
singleGaitCtrl(1, 1.5, StepA, 90, WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z - bInput);
singleGaitCtrl(4, 1.5, StepD, 90, -WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z + bInput);
singleGaitCtrl(2, 1.5, StepB, -90, -WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z - bInput);
singleGaitCtrl(3, 1.5, StepC, -90, WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z + bInput);
}
else if(turnCmd == 1){
singleGaitCtrl(1, 1.5, StepA, -90, WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z - bInput);
singleGaitCtrl(4, 1.5, StepD, -90, -WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z + bInput);
singleGaitCtrl(2, 1.5, StepB, 90, -WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z - bInput);
singleGaitCtrl(3, 1.5, StepC, 90, WALK_EXTENDED_X - aInput, WALK_EXTENDED_Z + bInput);
}
}
Compared to the diagonal gait, in addition to changing from two groups to four groups, three more parameters were added below:
float aInput = 0;
float bInput = 0;
float adProp;
These three parameters are not set by the user. They are used to dynamically adjust the center of gravity offset of the robot during motion. aInput and bInput are used to save the calculated offset, and adProp is used to calculate the offset aInput and bInput from the current position of the motion cycle.
StepB = GlobalInput;
StepC = GlobalInput + 0.25;
StepD = GlobalInput + 0.5;
StepA = GlobalInput + 0.75;
if(StepA>1){StepA--;}
if(StepB>1){StepB--;}
if(StepC>1){StepC--;}
if(StepD>1){StepD--;}
The above is used to adjust the phase difference for each set of motions, for example, the current swing order is 2 3 4 1 2 3 4 1......, you can change the above code to:
StepB = GlobalInput;
StepC = GlobalInput + 0.25;
StepA = GlobalInput + 0.5;
StepD = GlobalInput + 0.75;
The current swing order is 2 3 1 4 2 3 1 4 …, but try not to change the phase difference by 1/4.
if(GlobalInput <= 0.25){
adProp = GlobalInput;
aInput = WALK_MASS_ADJUST - (adProp/0.125)*WALK_MASS_ADJUST;
bInput = -WALK_MASS_ADJUST;
}
else if(GlobalInput > 0.25 && GlobalInput <= 0.5){
adProp = GlobalInput-0.25;
aInput = -WALK_MASS_ADJUST + (adProp/0.125)*WALK_MASS_ADJUST;
bInput = -WALK_MASS_ADJUST + (adProp/0.125)*WALK_MASS_ADJUST;
}
else if(GlobalInput > 0.5 && GlobalInput <= 0.75){
adProp = GlobalInput-0.5;
aInput = WALK_MASS_ADJUST - (adProp/0.125)*WALK_MASS_ADJUST;
bInput = WALK_MASS_ADJUST;
}
else if(GlobalInput > 0.75 && GlobalInput <= 1){
adProp = GlobalInput-0.75;
aInput = -WALK_MASS_ADJUST + (adProp/0.125)*WALK_MASS_ADJUST;
bInput = WALK_MASS_ADJUST - (adProp/0.125)*WALK_MASS_ADJUST;
}
The code above is used to calculate aInput and bInput, the specific center of gravity offset position, with the main purpose is to move the center of gravity to the triangle formed by the horizontal projection of the three feet currently on the support pair. You can modify the code above (the calculation logic and the weight coefficient of 0.125) or delete it to observe the changes in the action.
The rest of algorithm logic for the triangular gait is the same as that for the diagonal gait. Gait adjustments need to be made by combining with the single leg control and the parameter adjustment in the relevant parameters above.