-
程序为飞思卡尔光电K60
资源介绍
很好的程序void GetMotorPulse(void) //获取电机速度,并积分;
{
MotorPulse_R = -(short)FTM1_CNT;
MotorPulse_L = (short)FTM2_CNT;
FTM1_CNT= 0;
FTM2_CNT= 0;
//电机脉冲信号
CarSpeed = (MotorPulse_L + MotorPulse_R) / 2;
MotorPulse_L = 0;
MotorPulse_R = 0;
CarSpeed *= CAR_SPEED_CONSTANT; //单位转化
}
/*官方速度控制算法*/
void SpeedControl(void)
{
float fP,fI,iError;
iError=CAR_SPEED_SET-CarSpeed; //给定速度-实际速度
fP=SPEED_CONTROL_P*iError;
fI=SPEED_CONTROL_I*iError;
SpeedControlIntegral += fI;
SpeedControlOutOld=SpeedControlOutNew;
SpeedControlOutNew=fP+SpeedControlIntegral;
}