WAVEGO 步态调试具体方法
步态调试
通过修改ServoCtrl.h中的步态相关参数,调整步态的运动效果。
相关参数
在ServoCtrl.h中,除单一腿控制章节的参数外,用于整体步态调试的参数如下:
- WALK_ACC:这是一个距离,单位mm,用于支撑副/摆动副互相过渡
- WALK_EXTENDED_Z:单位mm,控制找地点在左右方向上的延申距离
- WALK_SIDE_MAX:腿部末端点左右摆动的最大幅度,单位mm
- WALK_MASS_ADJUST:用于在行进中调整重心偏移量,系数无单位,数值越大,重心偏移量越大,目前只在三角步态中有使用
- WALK_LIFT_PROP:摆动副在运动周期内的占用比例(时间),例如0.25表示在一个完整运动周期内的25%的时间内处于摆动副,数值越小,摆动越快,理论上支撑副时间越长越稳定,这一参数的限制主要在于舵机的转速和WALK_RANGE,WALK_LIFT,WALK_ACC的大小。
- STEP_DELAY:用于设置腿部摆动时的插值运算间隔时间。
- 其余参数不是由人来设置的,这里不做介绍,后面函数调试章节会介绍
函数调试
对角步态
根据单一腿控制中介绍的方法,让每条腿在其自己的运动周期内摆动,左前腿为1,左后腿为2,右前腿为3,右后腿为4,当1、4按照相同的运动周期摆动(称作A组),2、3按照相同的运动周期摆动(称作B组),A组与B组相差半个周期的相位,保证每一时刻至少有1组处于支撑副。
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); } }
上面的代码,用于执行对角步态,Group_A与Group_B相差半个周期的相位:
Group_A = GlobalInput; Group_B = GlobalInput+0.5; if(Group_B>1){Group_B--;}
GlobaIInput从0到1循环变化,AB组通过上面的算法获得自己的运动周期参数,形成对角步态。
turnCmd用于调整旋转方向,当turnCmd为0时可以使用directionAngle来调整平移方向(此时机器人头部朝向不变)
三角步态
三角步态的目的是让机器人每时每刻至少有三条腿处于支撑副,此步态更加复杂,需要更加精细的调试才能使用,上面对角步态是将四条腿分成AB两组,三角步态则是将四条腿分为了四组,1 2 3 4 对应 A B C D,每两组的运动周期最少相差1/4个相位。
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); } }
与对角步态相比,除了从两组变为四组外,还增加了下面这三个参数:
float aInput = 0; float bInput = 0; float adProp;
这三个参数都不是由人来设置的,这三个参数用于在运动中动态调整机器人的重心偏移量,aInput和bInput用于保存计算出来的偏移量,adProp用于从当前的运动周期所处位置来计算偏移量aInput和bInput。
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--;}
上面用于调整每组运动的相位差,例如目前的摆动顺序为2 3 4 1 2 3 4 1……,你可以将上面的代码更改为:
StepB = GlobalInput; StepC = GlobalInput + 0.25; StepA = GlobalInput + 0.5; StepD = GlobalInput + 0.75;
此时的摆动顺序为 2 3 1 4 2 3 1 4 ……,但是相位差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; }
上面这部分代码用于计算aInput和bInput,具体的重心偏移位置,主要目的是将重心移向目前处于支撑副的三个脚在水平面投影所组成的三角形内。你可以修改上面的代码(计算逻辑和0.125这个加权系数)或删除上面的代码,观察动作变化。
三角步态其余的算法逻辑与对角步态的相同,步态调整需同时结合单一腿控制和上面相关参数内的参数调整。