串级PID具体C语言代码:
if(ctrl.ctrlRate >= 2) //内环进行2次控制、外环进行1次控制、内环控制频率为外环2倍
{
//*****************外环PID**************************//
//俯仰计算//
pit=pit- (Rc_Data.PITCH - Rc_Data.pitch_offset)/30;
ctrl.pitch.shell.increment+= pit; //俯仰方向误差积分
//积分限幅
if(ctrl.pitch.shell.increment> ctrl.pitch.shell.increment_max)
ctrl.pitch.shell.increment= ctrl.pitch.shell.increment_max;
elseif(ctrl.pitch.shell.increment < -ctrl.pitch.shell.increment_max)
ctrl.pitch.shell.increment= -ctrl.pitch.shell.increment_max;
ctrl.pitch.shell.pid_out= ctrl.pitch.shell.kp * pit + ctrl.pitch.shell.ki * ctrl.pitch.shell.increment+ ctrl.pitch.shell.kd * (pit - pitch_old);
pitch_old= pit; //储存 俯仰偏差
//横滚计算//
rol=rol- (Rc_Data.ROLL - Rc_Data.roll_offset)/30;
ctrl.roll.shell.increment+= rol; //横滚方向误差积分
//积分限幅
if(ctrl.roll.shell.increment> ctrl.roll.shell.increment_max)
ctrl.roll.shell.increment= ctrl.roll.shell.increment_max;
elseif(ctrl.roll.shell.increment < -ctrl.roll.shell.increment_max)
ctrl.roll.shell.increment= -ctrl.roll.shell.increment_max;
ctrl.roll.shell.pid_out = ctrl.roll.shell.kp * rol +ctrl.roll.shell.ki * ctrl.roll.shell.increment + ctrl.roll.shell.kd * (rol -roll_old);
roll_old= rol; //储存 横滚偏差
//航向计算////////////
ctrl.yaw.shell.pid_out = ctrl.yaw.shell.kp * (Rc_Data.YAW -Rc_Data.yaw_offset)/10 + ctrl.yaw.shell.kd * sensor.gyro.origin.z;
yaw_old=yaw;
ctrl.ctrlRate = 0;
}
ctrl.ctrlRate++;
//*************内环(角速度环)PD****************************//
ctrl.roll.core.kp_out= ctrl.roll.core.kp * (ctrl.roll.shell.pid_out + sensor.gyro.radian.y *RtA);
ctrl.roll.core.kd_out= ctrl.roll.core.kd * (sensor.gyro.origin.y - sensor.gyro.histor.y);
ctrl.pitch.core.kp_out= ctrl.pitch.core.kp * (ctrl.pitch.shell.pid_out + sensor.gyro.radian.x * RtA);
ctrl.pitch.core.kd_out= ctrl.pitch.core.kd * (sensor.gyro.origin.x - sensor.gyro.histor.x);
ctrl.yaw.core.kp_out= ctrl.yaw.core.kp * (ctrl.yaw.shell.pid_out + sensor.gyro.radian.z * RtA);
ctrl.yaw.core.kd_out= ctrl.yaw.core.kd * (sensor.gyro.origin.z - sensor.gyro.histor.z);
ctrl.roll.core.pid_out= ctrl.roll.core.kp_out + ctrl.roll.core.kd_out;
ctrl.pitch.core.pid_out= ctrl.pitch.core.kp_out + ctrl.pitch.core.kd_out;
ctrl.yaw.core.pid_out= ctrl.yaw.core.kp_out + ctrl.yaw.core.kd_out;
ctrl.roll.core.pid_out、ctrl.pitch.core.pid_out和ctrl.yaw.core.pid_out为电机输出值。
超声波定高:
超声波定高就是测量高度数据与设定数据进行PID控制,在此I需要限幅,高度控制输出值代替油门输出即可。下面定高视频是一键起飞、自主定高、一键降落,定高1米,变化范围不超过5厘米。
光流定点:先上视频下次帖子将为大家介绍 请尽情期待。
四轴飞行器交流群200718960 希望大家互相交流互相提高 更多资料去菜鸟飞行器https://shop127566156.taobao.com/index.htm?spm=2013.1.w5002-11745762171.2.VwngoE&qq-pf-to=pcqq.c2c
最新GPS定点出来了
分享一下最好的一篇四轴飞行器论文