初级会员

- 积分
- 70
- 金钱
- 70
- 注册时间
- 2017-4-16
- 在线时间
- 19 小时
|

楼主 |
发表于 2017-5-7 13:01:21
|
显示全部楼层
[mw_shl_code=applescript,true]void all_ch()
{
moto1=(int16_t) (moto1+thr1);
moto2=(int16_t) (moto2+thr2);
moto3=(int16_t) (moto3+thr3);
moto4=(int16_t) (moto4+thr4);
if(moto1>move_Vmin)
moto1=move_Vmin;
if(moto1<move_Vmax)
moto1=move_Vmax;
if(moto2>move_Vmin)
moto2=move_Vmin;
if(moto2<move_Vmax)
moto2=move_Vmax;
if(moto3>move_Vmin)
moto3=move_Vmin;
if(moto3<move_Vmax)
moto3=move_Vmax;
if(moto4>move_Vmin)
moto4=move_Vmin;
if(moto4<move_Vmax)
moto4=move_Vmax;
if(NRF24L01_RxPacket(rxbuf)==1) //èç1ûûóD½óêüμ½èÎoÎêy¾Y¾íÕaÑùÖ′DD
{
TIM_SetCompare1(TIM2,moto1);
TIM_SetCompare2(TIM2,moto2);
TIM_SetCompare3(TIM2,moto3);
TIM_SetCompare4(TIM2,moto4); //Ëĸöí¨μà¶Ôó|Ëĸöμç»ú
}
else
while(1)
{
TIM_SetCompare1(TIM2,val);
TIM_SetCompare2(TIM2,val);
TIM_SetCompare3(TIM2,val);
TIM_SetCompare4(TIM2,val); //Ëĸöí¨μà¶Ôó|Ëĸöμç»ú
}
}
void contrl_pid(void)
{
// float x1,x2,x3;
moto1=0;
moto2=0;
moto3=0;
moto4=0;
/*shell pitch*/
for(ave_n=0;ave_n<5;ave_n++)
{
pitch.shell_xn=Angle_SET.pitch;
pitch.shell_error=pitch.shell_Set - pitch.shell_xn;
pitch.shell_Sn +=pitch.shell_error;
if(pitch.shell_Sn>0.5)
pitch.shell_Sn=0.4;
if(pitch.shell_Sn<-0.5)
pitch.shell_Sn=-0.4;
pitch.shell_out= pitch.shell_kp*pitch.shell_error + pitch.shell_ki*pitch.shell_Sn + pitch.shell_kd*( pitch.shell_error - pitch.shell_error_last );
pitch.shell_error_last=pitch.shell_error; //shell contrl renew data
/*core pitch*/
pitch.core_xn=MPU6050_GYRO_LAST.X/65.6; //?????
pitch.error=pitch.shell_out - pitch.core_xn;
pitch.core_Sn += pitch.error;
if(pitch.core_Sn>10)
pitch.core_Sn=10;//»y·ÖÏT·ù
if(pitch.core_Sn<-10)
pitch.core_Sn=-10;//»y·ÖÏT·ù
pitch.core_out=pitch.core_kp*pitch.error + pitch.core_ki*pitch.core_Sn + pitch.core_kd*( pitch.error - pitch.last_error );
pitch.last_error=pitch.error;
//Sum+=pitch.core_out;
//delay_us(100);
//pitch.core_out=Sum/5.0;
moto1=moto1 + pitch.core_out;
moto2=moto2 + pitch.core_out;
moto3=moto3 - pitch.core_out;
moto4=moto4 - pitch.core_out;
/*shell roll*/
roll.shell_xn=Angle_SET.roll;
roll.shell_error=roll.shell_Set - roll.shell_xn;
roll.shell_Sn +=roll.shell_error;
if(roll.shell_Sn>2)
roll.shell_Sn=2;
if(roll.shell_Sn<-2)
roll.shell_Sn=-2;
roll.shell_out=roll.shell_kp*roll.shell_error + roll.shell_ki*roll.shell_Sn + roll.shell_kd*( roll.shell_error - roll.shell_error_last );
roll.shell_error_last=roll.shell_error;//renew data
/*core roll*/
roll.core_xn=MPU6050_GYRO_LAST.Y /65.6; //????? ?00?s
roll.error = roll.shell_out - roll.core_xn;
roll.core_Sn+=roll.error;
if(roll.core_Sn>10)
roll.core_Sn=10;//»y·ÖÏT·ù
if(roll.core_Sn<-10)
roll.core_Sn=-10;//»y·ÖÏT·ù
roll.core_out=roll.core_kp*roll.error + roll.core_ki * roll.core_Sn + roll.core_kd*(roll.error - roll.last_error);
roll.last_error=roll.error;
moto1=moto1 + roll.core_out;
moto2=moto2 - roll.core_out;
moto3=moto3 - roll.core_out;
moto4=moto4 + roll.core_out;
/*shell yaw*/
yaw.shell_xn=Angle_SET.yaw;
yaw.shell_error=yaw.shell_Set - yaw.shell_xn;
yaw.shell_Sn += yaw.shell_error;
if(yaw.shell_Sn>0.5)
yaw.shell_Sn=0.4;
if(yaw.shell_Sn<-0.5)
yaw.shell_Sn=-0.4;
yaw.shell_out=yaw.shell_kp*yaw.shell_error + yaw.shell_ki*yaw.shell_Sn + yaw.shell_kd*( yaw.shell_error - yaw.shell_error_last );
yaw.shell_error_last=yaw.shell_error;
/*core yaw*/
yaw.core_xn=MPU6050_GYRO_LAST.Z /65.6;
yaw.error = yaw.shell_out - yaw.core_xn;
yaw.core_Sn+=yaw.error;
if(yaw.core_Sn>10)
yaw.core_Sn=10;
if(yaw.core_Sn<-10)
yaw.core_Sn=-10;//»y·ÖÏT·ù //»y·ÖÏT·ù
yaw.core_out=yaw.core_kp*yaw.error + yaw.core_ki * yaw.core_Sn + yaw.core_kd*(yaw.error - yaw.last_error);
yaw.last_error=yaw.error;
moto1=moto1 + yaw.core_out;
moto2=moto2 - yaw.core_out;
moto3=moto3 + yaw.core_out;
moto4=moto4 - yaw.core_out;
delay_us(200);
}
moto1=moto1/5.0;
moto2=moto2/5.0;
moto3=moto3/5.0;
moto4=moto4/5.0;
all_ch();
}[/mw_shl_code] |
|