一、原理
二、代码解析
一、原理
OffsetDuration表示法,以及看懂footfall图
二、代码解析
class OffsetDurationGait : public Gait继承自Gait类。这个类定义了基于偏移时间和持续时间的步态,每条腿有两种状态:接触地面或接触地面(摆动)。
首先看下构造函数需要那些变量来实现,
OffsetDurationGait::OffsetDurationGait(int nSegment, Vec4<int> offsets, Vec4<int> durations, const std::string &name)
nSegment(MPC(模型预测控制)的分段数量):步态主要是匹配MPC控制器,为控制器在一次迭代中提供对应的状态信息,nSegment是MPC预测时间段内的分段数,比如:MPC频率400Hz,预测步长10段,则该步态功能实际预测的步态时间长度为1/400*10=0.025秒,实际使用中,可以依据控制频率,设定nSegment,对一段时间的步态状态进行预测。
offsets(每条腿开始移动时的偏移量,以MPC分段为单位):以一条腿作为起始的参考
durations(每条腿在每个步态周期中的持续时间,以MPC分段为单位):对应的每条腿踩在地面上的时间
带入几个例子进行验证,如:
horizonLength=10;
trotting(horizonLength, Vec4<int>(0,5,5,0), Vec4<int>(5,5,5,5),"Trotting"),
bounding(horizonLength, Vec4<int>(5,5,0,0),Vec4<int>(5,5,5,5),"Bounding"),
walking(int(horizonLength*1.6), Vec4<int>(0,8,4,12), Vec4<int>(12,12,12,12), "Walking"),
random(horizonLength, Vec4<int>(9,13,13,9), 0.4, "Flying nine thirteenths trot"),
构造函数实现内容:
{
_name = name;
// allocate memory for MPC gait table
_mpc_table = new int[nSegment * 4];//4条腿,每条腿10个点的长度,存储每个时刻点的信息表
//起始偏移量在信息表中的百分比
_offsetsFloat = offsets.cast<float>() / (float) nSegment;
//触地持续时长在信息表中的百分比
_durationsFloat = durations.cast<f