中级会员
- 积分
- 240
- 金钱
- 240
- 注册时间
- 2018-4-21
- 在线时间
- 105 小时
|
30金钱
调了一天的横滚角内环P I和D还没开始调 给大了就一边电机转 给小点倒是能保证四个电机都转 但是总调不出等幅振荡 而且总是一边两个电机速度比另两边大 导致飞机一直绕着轴转
这是我的PID程序 电机1234的顺序是顺时针来的
float PID_Postion_Cal(float target,float measure,float p,float i,float d)
{
float out;
error=target-measure;
Integ+=error;
if(Integ>300)
Integ=300;
if(Integ<-300)
Integ=-300;
Deriv=error-last_error;
out=p*error+i*Integ+d*Deriv;
last_error=error;
return out;
}
void PID(struct _out_angle *angle,struct _gyro *gyro_filter)
{//外环
Pitch_shell_out=PID_Postion_Cal(0,angle->pitch,Pitch_shell_kp,Pitch_shell_ki,Pitch_shell_kd);
Roll_shell_out=PID_Postion_Cal(0,angle->roll,Roll_shell_kp,Roll_shell_ki,Pitch_shell_kd);
Yaw_shell_out=PID_Postion_Cal(0,angle->yaw,Yaw_shell_kp,Roll_shell_ki,Roll_shell_kd);
//内环
Pitch=PID_Postion_Cal(Pitch_shell_out,gyro_filter->y,Pitch_core_kp,Pitch_core_ki,Pitch_core_kd);
Roll=PID_Postion_Cal(Roll_shell_out,gyro_filter->x,Roll_core_kp,Roll_core_ki,Roll_core_kd);
Yaw=PID_Postion_Cal(Yaw_shell_out,gyro_filter->z,Yaw_core_kp,Yaw_core_ki,Yaw_core_kd);
thro1=(u16)(temp+Pitch-Roll-Yaw);
thro2=(u16)(temp+Pitch-Roll+Yaw);
thro3=(u16)(temp-Pitch+Roll-Yaw);
thro4=(u16)(temp-Pitch+Roll+Yaw);
if(thro1>2000)thro1=2000;
if(thro2>2000)thro2=2000;
if(thro3>2000)thro3=2000;
if(thro4>2000)thro4=2000;
Motor_Out(thro1,thro2,thro3,thro4);
Send_MotoPWM(thro1-1000,thro2-1000,thro3-1000,thro4-1000,Roll_shell_out+200,Roll+500,Yaw,0);
}
网上的文章找了很多 都是找等幅震荡的点 但是这个点我一直找不到 P给小了PID控制效果反而没了
跪求高人指点迷津
|
|