资源描述:
《大学生电子设计竞赛B题风力摆源程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、.附录2:风力摆源程序#include"sys.h"#include"usart.h"#include"delay.h"#include"led.h"#include"oled.h"#include"key.h"#include"mpu6050.h"#include"usmart.h"#include"inv_mpu.h"#include"inv_mpu_dmp_motion_driver.h"#include"pwm.h"#include"math.h"floatsetpoint,rx,c;u16zk1=20000,
2、zk2=20000,zk3=20000,zk4=20000;floatpitch,roll,yaw;//?·à-??shorttemp;//???èfloatet,et2,etsum,det,output,etp,etp2,etsump,detp,outputp;floatkp,ki,kd;voidpid(){et=setpoint-roll;if(et>0){etsum=etsum+et;det=et-et2;output=kp*et+ki*etsum+kd*det;et2=et;}if(et<=0){output=
3、24900;}et2=et;}voidpid2()//ó?à′??DD?à?ypitch{etp=setpoint-pitch;etp=fabs(etp);if(etp>=2){etsump=etsump+etp;detp=etp-etp2;..outputp=kp*etp+ki*etsump+kd*detp;}if((et>=0)&&(et<2)){outputp=24000;}etp2=etp;}voidpid4r(){et=setpoint-roll;//ó?à′??DD?à?yet=fabs(et);if(et
4、>=2){etsum=etsum+et;det=et-et2;output=kp*et+ki*etsum+kd*det;}if((et>=0)&&(et<2)){output=24000;}et2=et;}voidpid4p()//ó?à′??DD?à?ypitch{etp=setpoint-pitch;etp=fabs(etp);if(etp>=2){etsump=etsump+etp;detp=etp-etp2;outputp=kp*etp+ki*etsump+kd*detp;}if((et>=0)&&(et<2)
5、){outputp=24000;}etp2=etp;}voidpid5r(){et=setpoint-roll;//ó?à′??DD?à?yif(et>0){etsum=etsum+et;det=et-et2;output=kp*et+ki*etsum+kd*det;et2=et;}if(et<=0)..{output=24900;}et2=et;}voidpid5p()//ó?à′??DD?à?ypitch{etp=setpoint-pitch;if(etp>0){etsump=etsump+etp;detp=etp
6、-etp2;outputp=kp*etp+ki*etsump+kd*detp;etp2=etp;}if(etp<=0){outputp=24900;}etp2=etp;}voidinit_all(){NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);delay_init();//?óê±oˉêy3?ê??ˉuart_init(500000);//′??ú3?ê??ˉ?a9600usmart_dev.init(72);LED_Init();//3?ê??ˉó?LEDá??óμ?
7、ó2?t?ó?úKEY_Init();//3?ê??ˉ°′?üOLED_Init();//3?ê??ˉLCDMPU_Init();//3?ê??ˉMPU6050mpu_dmp_init();TIM3_OC1PWM_Init(59999,2);TIM3_OC2PWM_Init(59999,2);TIM3_OC3PWM_Init(59999,2);TIM3_OC4PWM_Init(59999,2);OLED_ShowString(8,0,"WaveByWind");OLED_Refresh_Gram();while(mpu
8、_dmp_init()){OLED_Clear();OLED_ShowString(8,0,"6050Error");OLED_Refresh_Gram();..delay_ms(400);}OLED_Clear();}intmain(void){init_all();while(1)//1
9、?ü?????£ê?{OLED_Sho