中级会员
- 积分
- 206
- 金钱
- 206
- 注册时间
- 2015-12-23
- 在线时间
- 38 小时
|
5金钱
void CONTROL(float rol_now, float pit_now, float yaw_now, float rol_tar, float pit_tar, float yaw_tar)
{
u16 moto1=0,moto2=0,moto3=0,moto4=0;
vs16 throttle;
float rol = rol_tar + rol_now;
float pit = pit_tar + pit_now;
float yaw = yaw_tar + yaw_now;
throttle = Rc_Get.THROTTLE - 1000;
if(throttle<0) throttle=0;
PID_ROL.IMAX = throttle/2;
Get_MxMi(PID_ROL.IMAX,1000,0);
PID_PIT.IMAX = PID_ROL.IMAX;
PID_ROL.pout = PID_ROL.P * rol;
PID_PIT.pout = PID_PIT.P * pit;
if(rol_tar*rol_tar<0.1 && pit_tar*pit_tar<0.1 && rol_now*rol_now<30 && pit_now*pit_now<30 && throttle>300)
{
PID_ROL.iout += PID_ROL.I * rol;
PID_PIT.iout += PID_PIT.I * pit;
PID_ROL.iout = Get_MxMi(PID_ROL.iout,PID_ROL.IMAX,-PID_ROL.IMAX);
PID_PIT.iout = Get_MxMi(PID_PIT.iout,PID_PIT.IMAX,-PID_PIT.IMAX);
}
else if(throttle<200)
{
PID_ROL.iout = 0;
PID_PIT.iout = 0;
}
PID_ROL.dout = PID_ROL.D * MPU6050_GYRO_LAST.X;
PID_PIT.dout = PID_PIT.D * MPU6050_GYRO_LAST.Y;
PID_YAW.pout = PID_YAW.P * yaw;
vs16 yaw_d;
if(1480>Rc_Get.YAW || Rc_Get.YAW>1520)
{
yaw_d = MPU6050_GYRO_LAST.Z + (Rc_Get.YAW-1500)*10;
GYRO_I.Z = 0;
}
else
yaw_d = MPU6050_GYRO_LAST.Z;
PID_YAW.dout = PID_YAW.D * yaw_d;
PID_ROL.OUT = PID_ROL.pout + PID_ROL.iout + PID_ROL.dout;
PID_PIT.OUT = PID_PIT.pout + PID_PIT.iout + PID_PIT.dout;
PID_YAW.OUT = PID_YAW.pout + PID_YAW.iout + PID_YAW.dout;
if(throttle>200)
{
moto1 = throttle - PID_ROL.OUT - PID_PIT.OUT + PID_YAW.OUT;
moto2 = throttle + PID_ROL.OUT - PID_PIT.OUT - PID_YAW.OUT;
moto3 = throttle + PID_ROL.OUT + PID_PIT.OUT + PID_YAW.OUT;
moto4 = throttle - PID_ROL.OUT + PID_PIT.OUT - PID_YAW.OUT;
}
else
{
moto1 = 0;
moto2 = 0;
moto3 = 0;
moto4 = 0;
}
if(ARMED) Moto_PwmRflash(moto1,moto2,moto3,moto4);
else Moto_PwmRflash(0,0,0,0);
}
在上面这段程序里面为什么rol,pit,yaw,要等与后面那两项相加呢?PID的操控不是应该跟误差有关吗?(rol_tar,pit_tar,yaw_tar为目标角度(或是与现在的差值?),rol_now,pit_now,yaw_now为当前角度)
希望能够得到大家帮助,谢谢大家了!!!
|
|