2012飞思卡尔智能车速度pid调试

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Ctl_P = Kp * SpeedError; //计算比例项

Ctl_I = Ki * SpeedError + Ctl_I;

if(Ctl_I < -1000) //积分项限幅

Ctl_I = -1000;

else if(Ctl_I > 1000)

Ctl_I = 1000;

// T_Ctl_I=Ctl_I;

// T_Ctl_P=Ctl_P;

PWM1input=(8*(Ctl_P + Ctl_I)+3*PWM1inputCache[0]+PWM1inputCache[1])/ 12;

void SpeedCount(void)

{

SpeedCache[3]=SpeedCache[2];

SpeedCache[2]=SpeedCache[1];

SpeedCache[1]=SpeedCache[0];

SpeedCache[0]=SpeedBack;//缓存

NEW_SpeedCache[3]=NEW_SpeedCache[2];

NEW_SpeedCache[2]=NEW_SpeedCache[1];

NEW_SpeedCache[1]=NEW_SpeedCache[0];

NEW_SpeedCache[0]=NEW_SpeedBack;

if(PACNT

{

PA_OverFlow=1;

}

if(PA_OverFlow==0)

{

SpeedBack = PACNT - LastPulseCounter; //计算当前速度;

}

else if(PA_OverFlow==1)

{

SpeedBack=65535*PA_OverFlow+PACNT- LastPulseCounter;

PA_OverFlow=0;

}

if(NEW_PACNT

{

NEW_PA_OverFlow=1;

}

if(NEW_PA_OverFlow==0)

{

NEW_SpeedBack = NEW_PACNT - NEW_LastPulseCounter; //计算当前速度;

}

else if(NEW_PA_OverFlow==1)

{

NEW_SpeedBack=65535*NEW_PA_OverFlow+NEW_PACNT- NEW_LastPu lseCounter;

NEW_PA_OverFlow=0;

}

NEW_LastPulseCounter = NEW_PACNT;

LastPulseCounter = PACNT;

SpeedBack=SpeedBack/PulseCountDen;

NEW_SpeedBack=NEW_SpeedBack/PulseCountDen;

}

void SpeedControl(void)

{

//速度控制

int ErrorSum=0;

int SpeedCtl;

int tri_speed=20;

static uchar SpeedUp;

static uchar SpeedDown;

uint den;

static uint StraightTime;

static uint StraightLineCounter;

SteerIncrementError[2] = SteerIncrementError[1];

SteerIncrementError[1] = SteerIncrementError[0];

SteerIncrementError[0]=SteerIncrementCache[0]-SteerIncre mentCache[2];

ErrorSum=SteerIncrementError[0]*3/2+SteerIncrementError[ 1] + SteerIncrementError[2];

SpeedCtl = m_abs(SteerIncrement + ErrorSum);

if(SpeedCtl<55)

{ //50

SpeedUp = 1;

if(SpeedDown==1)

{

StraightCounter = 0;

StraightCounter++;

SpeedDown = 0;

}

StraightCounter++;

}

else if(SpeedCtl<65)

{ //60

SpeedUp = 0;

SpeedDown = 0;

StraightCounter = 0;

}

else

{

SpeedDown = 1;

if(SpeedUp==1)

{

StraightCounter = 0;

StraightCounter = StraightCounter - 2;

SpeedUp = 0;

}

StraightCounter = StraightCounter - 2;

}

den = m_abs(SteerIncrementCache[0] + SteerIncrementCache[1]) / 2;

if(den==0)

den = 1;

相关文档
最新文档