金牌会员
- 积分
- 1800
- 威望
- 910
- 贡献
- 548
- 兑换币
- 491
- 注册时间
- 2017-1-5
- 在线时间
- 171 小时
|
2#
楼主 |
发表于 2017-3-8 23:05:43
|
只看该作者
float Value_main_pre,angle_pre_error,Value_secondary_pre,angle_pre_speed_error,angle_pre_pre_speed_error,Value_secondary;
float balance(float Angle,float Gyro)
{
float kp_main=10,angle_error,Value_main,angle_speed_error;
float KP_secondary=11,KD_secondary=1.5;
angle_error =Angle-ZHONGZHI_ANGLE;
Value_main = Value_main_pre +kp_main*(angle_error-angle_pre_error);
Value_main_pre = Value_main;
angle_pre_error = angle_error;
angle_speed_error = Value_main-ZHONGZHI_ANGLE_SPEED;
Value_secondary = Value_secondary_pre+KP_secondary*(angle_speed_error-angle_pre_speed_error)+KD_secondary*(angle_speed_error-2*angle_pre_speed_error+angle_pre_pre_speed_error);
Value_secondary_pre = Value_secondary;
angle_pre_pre_speed_error = angle_pre_speed_error;
angle_pre_speed_error = angle_speed_error;
return Value_secondary;
} |
|