久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
基于STM32F103的mini四軸源碼
[打印本頁]
作者:
BoykaC
時間:
2018-6-4 12:24
標題:
基于STM32F103的mini四軸源碼
mpu6050作為姿態傳感器
PID適用在mini四軸上 自己DIY后需要再調參數 大四軸正在試
0.png
(42.58 KB, 下載次數: 57)
下載附件
2018-6-4 18:26 上傳
所有資料51hei提供下載:
STM32F103四軸飛行器源碼.rar .7z
(283.09 KB, 下載次數: 34)
2022-12-16 04:05 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
單片機源程序如下:
#include "Maths.h"
#include "Control.h"
#include "struct_all.h"
//RC
uint8_t Rc_Lock=1;//1上鎖;0解鎖
/******************************************************************************
函數原型: void RC_Limit(struct _Rc *rc)
功 能: 限制遙控指令范圍
*******************************************************************************/
void RC_Limit(struct _Rc *rc)
{
rc->THROTTLE = (rc->THROTTLE<=1000)?1000:rc->THROTTLE;
rc->THROTTLE = (rc->THROTTLE>=2000)?2000:rc->THROTTLE;
rc->PITCH = (rc->PITCH<=1000)?1000:rc->PITCH;
rc->PITCH = (rc->PITCH>=2000)?2000:rc->PITCH;
rc->ROLL = (rc->ROLL<=1000)?1000:rc->ROLL;
rc->ROLL = (rc->ROLL>=2000)?2000:rc->ROLL;
rc->YAW = (rc->YAW<=1000)?1000:rc->YAW;
rc->YAW = (rc->YAW>=2000)?2000:rc->YAW;
rc->AUX1 = (rc->AUX1<=1000)?1000:rc->AUX1;
rc->AUX1 = (rc->AUX1>=2000)?2000:rc->AUX1;
rc->AUX2 = (rc->AUX2<=1000)?1000:rc->AUX2;
rc->AUX2 = (rc->AUX2>=2000)?2000:rc->AUX2;
rc->AUX3 = (rc->AUX3<=1000)?1000:rc->AUX3;
rc->AUX3 = (rc->AUX3>=2000)?2000:rc->AUX3;
}
/******************************************************************************
函數原型: void RC_LOCK(void)
功 能: 遙控手勢指令及解鎖處理(以下注釋針對美國手,遙控默認的就是美國手)
*******************************************************************************/
void RC_LOCK(void)
{
static uint8_t count0,count1,count2;
if(Rc.THROTTLE<1300 )//&& Rc.YAW>1700 && Rc.PITCH>1400 && Rc.PITCH<1600)
count0++;
else
count0 = 0;
if(count0>15 && Rc_Lock==1)
{
Rc_Lock = 0;//左手油門手的搖桿打向右下角,右手搖桿不動,解鎖
LED3_OFF;
Delay_led(100);
LED3_ON;
Delay_led(100);
}
////////////////////////////////////////////////
if(Rc.THROTTLE<1300 && Rc.YAW<1300 && Rc.PITCH>1400 && Rc.PITCH<1600)
count1++;
else
count1 = 0;
if(count1>150 && Rc_Lock==0)
{
Rc_Lock = 1;//左手油門手的搖桿打向左下角,右手搖桿不動,上鎖
LED3_OFF;
Delay_led(100);
LED3_ON;
Delay_led(100);
}
////////////////////////////////////////////////
if(Rc.THROTTLE<1300 && Rc.YAW<1300 && Rc.PITCH<1300)
count2++;
else
count2 = 0;
if(count2>100)//&& Rc_Lock)//上鎖狀態才能校正
{
count2=0;
Do_GYRO_Offset();//左手油門手的搖桿打向左下角,右手搖桿俯仰方向拉到最底,校正陀螺儀
Do_ACC_Offset(); //左手油門手的搖桿打向左下角,右手搖桿俯仰方向拉到最底,校正加速度計
LED3_OFF;
Delay_led(50);
LED3_ON;
Delay_led(50);
LED3_OFF;
Delay_led(50);
LED3_ON;
}
}
//PID
#define angle_max 10.0f
#define angle_integral_max 1000.0f
/******************************************************************************
函數原型: void Control_Angle(struct _out_angle *angle,struct _Rc *rc)
功 能: PID控制器(外環)
*******************************************************************************/
void Control_Angle(struct _out_angle *angle,struct _Rc *rc)
{
static struct _out_angle control_angle;
static struct _out_angle last_angle;
//////////////////////////////////////////////////////////////////
// 以下為角度環
//////////////////////////////////////////////////////////////////
if(rc->ROLL>1490 && rc->ROLL<1510)
rc->ROLL=1500;
if(rc->PITCH>1490 && rc->PITCH<1510)
rc->PITCH=1500;
//////////////////////////////////////////////////////////////////
if(rc->AUX1>1495 && rc->AUX1<1505)
rc->AUX1=1500;
if(rc->AUX2>1495 && rc->AUX2<1505)
rc->AUX2=1500;
//////////////////////////////////////////////////////////////////
control_angle.roll = angle->roll - (rc->ROLL -1500)/13.0f + (rc->AUX2 -1500)/100.0f;
control_angle.pitch = angle->pitch - (rc->PITCH -1500)/13.0f - (rc->AUX1 -1500)/100.0f;
//////////////////////////////////////////////////////////////////
if(control_angle.roll > angle_max) //ROLL
roll.integral += angle_max;
if(control_angle.roll < -angle_max)
roll.integral += -angle_max;
else
roll.integral += control_angle.roll;
if(roll.integral > angle_integral_max)
roll.integral = angle_integral_max;
if(roll.integral < -angle_integral_max)
roll.integral = -angle_integral_max;
//////////////////////////////////////////////////////////////////
if(control_angle.pitch > angle_max)//PITCH
pitch.integral += angle_max;
if(control_angle.pitch < -angle_max)
pitch.integral += -angle_max;
else
pitch.integral += control_angle.pitch;
if(pitch.integral > angle_integral_max)
pitch.integral = angle_integral_max;
if(pitch.integral < -angle_integral_max)
pitch.integral = -angle_integral_max;
//////////////////////////////////////////////////////////////////
if(rc->THROTTLE<1200)//油門較小時,積分清零
{
roll.integral = 0;
pitch.integral = 0;
}
//////////////////////////////////////////////////////////////////
roll.output = roll.kp *control_angle.roll + roll.ki *roll.integral + roll.kd *(control_angle.roll -last_angle.roll );
pitch.output = pitch.kp*control_angle.pitch + pitch.ki*pitch.integral + pitch.kd*(control_angle.pitch-last_angle.pitch);
//////////////////////////////////////////////////////////////////
last_angle.roll =control_angle.roll;
last_angle.pitch=control_angle.pitch;
}
#define gyro_max 50.0f
#define gyro_integral_max 5000.0f
/******************************************************************************
函數原型: void Control_Gyro(struct _SI_float *gyro,struct _Rc *rc,uint8_t Lock)
功 能: PID控制器(內環)
*******************************************************************************/
void Control_Gyro(struct _SI_float *gyro,struct _Rc *rc,uint8_t Lock)
{
static struct _out_angle control_gyro;
static struct _out_angle last_gyro;
int16_t throttle1,throttle2,throttle3,throttle4;
//////////////////////////////////////////////////////////////////
// 以下為角速度環
//////////////////////////////////////////////////////////////////
if(rc->YAW>1400 && rc->YAW<1600)
rc->YAW=1500;
if(rc->AUX3>1495 && rc->AUX3<1505)
rc->AUX3=1500;
//////////////////////////////////////////////////////////////////
control_gyro.roll = -roll.output - gyro->y*Radian_to_Angle;
control_gyro.pitch = pitch.output - gyro->x*Radian_to_Angle;
if(rc->AUX4 & Lock_Mode)
control_gyro.yaw = - gyro->z*Radian_to_Angle - (rc->AUX3 -1500)/100.0f;//鎖尾模式
else
control_gyro.yaw = -(rc->YAW-1500)/2.0f - gyro->z*Radian_to_Angle + (rc->AUX3 -1500)/50.0f;//非鎖尾模式
//////////////////////////////////////////////////////////////////
if(control_gyro.roll > gyro_max) //GYRO_ROLL
gyro_roll.integral += gyro_max;
if(control_gyro.roll < -gyro_max)
gyro_roll.integral += -gyro_max;
else
gyro_roll.integral += control_gyro.roll;
if(gyro_roll.integral > gyro_integral_max)
gyro_roll.integral = gyro_integral_max;
if(gyro_roll.integral < -gyro_integral_max)
gyro_roll.integral = -gyro_integral_max;
//////////////////////////////////////////////////////////////////
if(control_gyro.pitch > gyro_max)//GYRO_PITCH
gyro_pitch.integral += gyro_max;
if(control_gyro.pitch < -gyro_max)
gyro_pitch.integral += -gyro_max;
else
gyro_pitch.integral += control_gyro.pitch;
if(gyro_pitch.integral > gyro_integral_max)
gyro_pitch.integral = gyro_integral_max;
if(gyro_pitch.integral < -gyro_integral_max)
gyro_pitch.integral = -gyro_integral_max;
//////////////////////////////////////////////////////////////////
// if(control_gyro.yaw > gyro_max)//GYRO_YAW
// gyro_yaw.integral += gyro_max;
// if(control_gyro.yaw < -gyro_max)
// gyro_yaw.integral += -gyro_max;
// else
gyro_yaw.integral += control_gyro.yaw;
if(gyro_yaw.integral > gyro_integral_max)
gyro_yaw.integral = gyro_integral_max;
if(gyro_yaw.integral < -gyro_integral_max)
gyro_yaw.integral = -gyro_integral_max;
//////////////////////////////////////////////////////////////////
if(rc->THROTTLE<1200)//油門較小時,積分清零
{
gyro_yaw.integral = 0;
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
歡迎光臨 (http://m.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
中文字幕视频一区
|
狠狠躁日日躁夜夜躁2022麻豆
|
91高清国产
|
91狠狠综合
|
日本伊人
|
91午夜精品亚洲一区二区三区
|
天天干天天操天天插
|
91av在线看
|
av福利在线
|
国产成人在线视频
|
日韩亚洲欧美在线
|
久久夜视频
|
老女人性生活视频
|
日韩欧美大片
|
国产精品成人一区二区三区
|
欧美日韩国产三级
|
久久在线免费观看
|
久久精品一区二区三区四区
|
欧美性色网
|
国产成人精品一区二区三区在线
|
黄色裸体视频
|
久久精品视频一区二区
|
久久男人天堂
|
亚洲在线播放
|
色一情一乱一乱一区91av
|
手机av网站
|
在线播放a
|
影音先锋中文字幕在线
|
久久久成人精品
|
亚洲福利影院
|
国产一区二区三区视频在线
|
国产主播av
|
情侣av
|
九色av
|
久久久久久免费
|
久久精品欧美一区二区三区不卡
|
成人欧美一区二区三区黑人免费
|
羞羞的视频网站
|
久久99精品久久久久久琪琪
|
三年中文在线看免费观看
|
国产三级做爰高清在线
|