不是角度PWM给正值,速度PWM就应该给负值吗
void speed_get(){
waittime++;
if(waittime==20){
SpeedLeft=PACNT*constant;//感觉需要比例系数?????滤波
PACNT=0;
if(drtion==0){这是判断速度方向
SpeedLeft=-SpeedLeft;
}
waittime=0;
speedtime=0;
err=speedset-SpeedLeft;
sumerr+=err;
oldspeed=newspeed;
newspeed=0.01*sumerr+1*err;
}
}
void speed_control(){
speedf=newspeed-oldspeed;
motor_speed_give=(int)(oldspeed+speedf*(speedtime+1)/20);
speedtime++;
}
不对吗求指正??? |