金牌会员
- 积分
- 1046
- 威望
- 524
- 贡献
- 266
- 兑换币
- 315
- 注册时间
- 2014-11-21
- 在线时间
- 128 小时
|
void MotorControl(int Angleout)
{
Leftcontrol=Angleout;//-Speed_control_out_l; //+Speed_control_out_l;
Rightcontrol=Angleout;//-Speed_control_out_r; //+Speed_control_out_r;
/*
if(Leftcontrol >= 0)
Leftcontrol += 600;
else
Leftcontrol -= 600;
if(Rightcontrol >= 0)
Rightcontrol += 690;
else
Rightcontrol -= 690;
*/
if(Leftcontrol > control_max)
Leftcontrol = control_max;
if(Leftcontrol < control_min)
Leftcontrol = control_min;
if(Rightcontrol > control_max)
Rightcontrol = control_max;
if(Rightcontrol < control_min)
Rightcontrol = control_min;
if(Leftcontrol > 0)
{
FTM_PWM_Duty(FTM0,FTM_CH7,2000+Leftcontrol);//ch7
FTM_PWM_Duty(FTM0,FTM_CH6,0); //ch6
}
else if(Leftcontrol < 0)
{
Leftcontrol=-Leftcontrol;
FTM_PWM_Duty(FTM0,FTM_CH6,2000+Leftcontrol); //ch6
FTM_PWM_Duty(FTM0,FTM_CH7,0); //ch7
}
else
{
FTM_PWM_Duty(FTM0,FTM_CH6,2000);
FTM_PWM_Duty(FTM0,FTM_CH7,2000);
}
if(Rightcontrol > 0)
{
FTM_PWM_Duty(FTM0,FTM_CH5,2000+Rightcontrol); //ch5
FTM_PWM_Duty(FTM0,FTM_CH4,0); //ch4
}
else if(Rightcontrol < 0)
{
Rightcontrol=-Rightcontrol;
FTM_PWM_Duty(FTM0,FTM_CH4,2000+Rightcontrol);//ch4
FTM_PWM_Duty(FTM0,FTM_CH5,0); //ch5
}
else
{
FTM_PWM_Duty(FTM0,FTM_CH4,2000);
FTM_PWM_Duty(FTM0,FTM_CH5,2000);
}
if(Angle_car > 34 || Angle_car< -25)
{
FTM_PWM_Duty(FTM0,FTM_CH4,2000);
FTM_PWM_Duty(FTM0,FTM_CH5,2000);
FTM_PWM_Duty(FTM0,FTM_CH6,2000);
FTM_PWM_Duty(FTM0,FTM_CH7,2000);
}
|
|