用上位机给STM32直流驱动板发指令,STM32完成上位机指令后,但由于编码器计数未清零,指令不能连续发送,该怎么办?
[mw_shl_code=c,true]s32 pwm;
extern s16 dAngle;
//s16 Now_position;
void Speed_control(s16 set_Position,s16 set_Speed)
{
pwm+=PID(set_Speed,dAngle);
if(pwm>10000)
pwm=9000;
if(pwm<0)
pwm=500;
// TIM1->CCR1=pwm;
if(set_Position==TIM2->CNT)
{
TIM1->CCR1=0x0000;
TIM1->CCR2=0x0000;
// delay_ms(1000);
// flag=1;
}
else if(set_Position>TIM2->CNT)
{
TIM1->CCR1=pwm;
TIM1->CCR2=0x0000;
}
else if(set_Position<TIM2->CNT)
{
TIM1->CCR1=0x0000;
TIM1->CCR2=pwm;
}
}
[/mw_shl_code]
用TIM2进行编码器计数,通过电脑串口设置
set_Position(位置),set_Speed(速度)
设置转9000个脉冲,但由于电机惯性,编码器计数显示9231个脉冲,怎么让误差减小?
当驱动板完成指令电机停止后,怎么让编码器的计数清零,为下一次指令接收做好准备?
2.usmart调试
---------------------------------
PID控制是先调位置,再调速度吗?
double IDCalc(PID *pp,double NextPoint)
{
double dError,Error;
Error = pp->SetPoint - NextPoint;
pp->SumError += Error;
dError = pp->LastError - pp->revError;
pp->revError = pp->LastError;
pp->LastError = Error;
return (pp->roportion*Error /*比例调节*/
+ pp->Integral*pp->SumError /*积分补偿*/
+ pp->Derivative*dError); /*微分补偿*/
}
一周热门 更多>