2023全国大学生电子设计竞赛设计报告B题-风力摆控制系统.docx
2023年全国高校生电子设计竞赛风力摆限制系统(B题)参赛学校:长安高校队伍编号:XZ 015参赛队员:崔曜东、马若斯、李宝才指导老师:2023年8月15日2、程序的设计(1)程序功能描述与设计思路1、程序功能描述依据题目要求软件部分主要实现键盘的设置和显示。1)键盘实现功能:2)显示部分:2、程序设计思路MPU-6050STM32fl 03轴流风机风力摆机械平台LCD显示模块(2)程序流程图1、主程序流程图各模块初始化按键扫描进入直线起振进入直线起振风力摆制动四、测试方案与测试结果1、测试方案(1)电路功能测试 每块电路板分开进行功能测试,进行逐项功能的测试。(2)机械结构测试搭建好机械结构后,利用等重负载进行负载承重和摇摆振动测试。(3)硬件软件联调驱动风力摆工作,使激光稳定地在地面画出一条长度不短于50cm的直线段,来回 五次,记录其由静止至起先自由摆时间及最大偏差距离。测试结果如表1所示。2、测试条件与仪器测试条件:检查多次,仿真电路和硬件电路必需与系统原理图完全相同,并且检查 无误,硬件电路保证无虚焊。机械结构通过负载测试和电机振动测试。测试仪器:数字示波器,数字万用表,卷尺,量角器,方向角度图纸3、测试结果及分析(1)测试结果(数据)(2)测试分析与结论依据上述测试数据,由此可以得出以下结论:综上所述,本设计达到设计要求。五、结论与心得本次电子设计竞赛,通过对此系统前期的方案设计、方案的选择、方案论证,中期 的机械结构的的搭建,硬件的设计和详细程序的实现和后期系统的测试,最终基本能达 到要求,通过这次课程设计小组成员之间的分工和合作,沟通协作,各项工作有序的进 行,完成这次的设计,我没每个人都有许多的收获,但最大的收获不是这个结果,而是 在这个过程中,每个人都学到了许多的新学问,提升了解决问题的实力和如何与他人很 好的合作。无论最终测评的结果如何,我们都该为此次竞赛感到兴奋和满意。六、参考文献1童诗白,华程英.模拟电子技术基础(第四版)M.北京:高等教化出版社,2023.2阎石.数字电子技术基础(第五版)M.北京:高等教化出版社,2023.3黄智伟,王彦,陈文光等.全国高校生电子设计竞赛训练教程M.北京:电子工业出版 社,2023.4高祥瑞,唐朝京.全国高校生电子设计竞赛培训系列教程(电子仪器仪表设计)M. 北京:电子工业出版社,2023.5张友德、赵志英、涂时亮.单片微型机原理、应用与实践(第五版)M.上海:复 旦高校出版社,2023.6郭天祥.新概念51单片机C语言教程.入门、提高、开发M.北京:电子工业出版 社,2023.7梁明理.电子线路(第五版)M.北京:高等教化出版社,2023.8谭浩强.C语言程序设计M.北京:清华高校出版社,2023附录1:电路原理图Ta. iIBUzm >AO3»:nMi (Mima m、,i"MQ)«MZ>r imTe rMVnm K4AXJC14<DO TrF 14 7Z九工>A!0WTUT KikAvrt KRKMCT1 FCI5WO2 FDOO*» roioarovT xwrr KOAZCIi P3口 R7 wri: io wnJM . 9 e p/ 1” _ 匕诵轻掌 a 小 x :vu 2加,nwcm h PWTtMl oG?exo D< tornF»-tXL«DATIMa OC n»rxi «a-nM».an FBMX1 MAVMOam SP Pt44NTKnWLt.>Ax> 0 HWWD.tat3.CK nrnw E5 fxcd ck(t> foM TXWIOCK K1IV<|tX%0ttj>5sir ADomc.oa.m -mr .an TFe_nwiW4.Tx wtoji:f*i AxriTXT.ar Tr nr P4S TXADCilbL tTDKS OD MMJ11LXADO4M oMt1>D 3 via 一VDOP1SRI21K/MA. 42 CML.,AM/nX«lX VDO VM ,仆 maexD rAiicAN Txcuicra nt Fajican kxusaXM nwi'cHaK5AMU03QHW OD/RMB OCN fbi ADcvnw-cmTBa-oia FB?»nonF»HIX2_KLU> IX hhi txjwvcijac vu,413 tXTXMi'CW MvrwnMrac hum CHlWtO R9IM MDD 3 K*T1MI-OU tSCEH*RTg MCXTMI*aC weolorZ.E MCKTIMI (WWW IMFX?MT.Ma< ta: ®TMI obw nru wottoriMi.cicK E,g «CXTJ.CX7B<1.nnxta rr> m >ci a ka »eKi! “ Wx 国ojc s i'USThicp LCT_2>Ltt 111TTITTm HB&Y附图LI MCU部分原理图F L FTUH»,kTHeader 6vccIIC SCLU2" cn&F11PU INTRc20 2420 12120GND«|LriLfcMPU AtX9GNDSCLRESVSDARESVNTRESVAUX CLNC NCAUX_DANCCLKINNC NCFSYNCNCADONCNCVLCX3IC VDD REGOUTGNDCPOUTXTPU6O5O附图L2 MPU-6050模块原理图19H16lZL<-OT1附图L3驱动模块原理图附录2:源程序#include nsys.hn#include nusart.hH#include ndelay.hH#include nled.hn#include Hlcd.hH#include nkey.hH#include nmpu6050.hH#include nusmart.hH#include ninv_mpu.hn#include ''inv_mpu_dmp_motion_driver.h''#include <math.h>/ Error/ Error-1/ Error-2static float Error=0;static float LastError=0;static float PrevError=0;static float d_Error=0,dd_Error=0;#define pi 3.141592653f;int Kp = 10;int Ki = 0;int Kd = 0;u8 t=09report=l;/A-.Eiia2EoEI±-u8 key;doublestand_len=1.055,ll=0.75;/|ii¥i»Ax/A-A-Q/OEUEDO-EWWfloat pitch,roll,yaw;short aacx,aacy,aacz;short gyrox,gyroy,gyrozj/ZIOAYOCO-EEyY short temp;float first_yaw=0;float current_yaw=0;float x=0.15;/zUl-0EIl5dxOu/c:Oa*0EI|LiAxO*uvoid usartl_send_char(u8 c)while(USARTl->SR&0X40)=0);/|iiEzyEid» t-0EHe±iUSARTl->DR=c;)/<<EIEy%YA0AaAuEAOaEii>>>>uEiI)(V2.6o2e±%)/funlAUxd. 0XA0-0XAF/data:Ey%Y»°x2eC0,xi(|a28xOU!/len:dataC0ODD§Ey%Y5dEyvoid usartl_niming_report(u8 fun,u8*data,u8 len)u8 send_buf32;u8 i;if(len>28)return; /x?|a28xOViUEy%Y send_buflen+3=0; /DfNeEyOAAa send_buf0=0X88; /O;I- send_bufl=fun; /AUxO send_buf2=len; /Ey%YE for(i=0;i<len;i+)send_buf3+i=datai;for(i=0;i<len+3;i+)send_buflen+3+=send_bufi; /2EEaD£Ne°I for(i=0;i<len+4;i+)usartl_send_char(send_bufi); /*EIEy%YU1 )/aacx,aacy,aaczixzEydAidEiAaepAOEUEdiii/gyrox,gyroy,gyroz:x,y,zEy5delIdEIAaepAIOAYOOpvoid mpu6050_send_data(short aacx,short aacy,short aacz,short gyrox,short gyroy,short gyroz)u8 tbuf12;tbuf0=(aacx»8)&0XFF;tbufl=aacx&OXFF;tbuf2=(aacy»8)&0XFF;tbuf3=aacy&0XFF;tbuf4=(aacz»8)&0XFF;tbuf5=aacz&0XFF;tbuf6=(gyrox»8)&0XFF;tbuf7=gyrox&0XFF;tbuf8=(gyroy»8)&0XFF;tbuf9=gyroy&0XFF;tbuf10=(gyroz»8)&0XFF;tbufll=gyroz&OXFF;usartl_niming_report(OXAl,tbuf42);/xO(|,dadi9OXAl )f而± %£ 而。6nAx J£y%R0|nqA。/aacx,aacy,aaczzxzEydidEIAaepAOEUllEdiLi/gyrox9gyroy,gyroz:x?y9zEyAd*l6IdEIAae|LiAIOAYOQOp/rollaWQ.iLiWO.OlEif -18000 -> 18000 66 -180.00 -> ISO.OOE/pitch:,©NoQ.|li¥I» 0.01(氏&9000 - 9000 OOj -90.00 -> 90.00/yaw:°IdC.|Li¥I»ia0.1(|fE 0 -> 3600 (|fO6| 0 -> 360.0(|Evoid usartl_report_imu(short aacx,short aacy,short aacz,short gyrox,short gyroy,short gyroz9short roll,short pitch,short yaw)(u8 tbuf28;u8 i;for(i=0;i<28;i+)tbufi=0;/Qa0tbuf0=(aacx»8)&0XFF;tbufl=aacx&0XFF;tbuf2=(aacy»8)&0XFF;tbuf3=aacy&0XFF;tbuf4=(aacz»8)&0XFF;tbuf5=aacz&0XFF;tbuf6=(gyrox»8)&0XFF;tbuf7=gyrox&0XFF;tbuf8=(gyroy»8)&0XFF;tbuf9=gyroy&0XFF;tbuf10=(gyroz»8)&0XFF;tbufll=gyroz&0XFF;tbuf18=(roll»8)&0XFF;tbuf19=roll&0XFF;tbuf20=(pitch»8)&0XFF;tbuf21=pitch&0XFF;tbuf22=(yaw»8)&0XFF;tbuf23=yaw&0XFF;usartl_niming_report(OXAF4buf28);/*E0idE%d;9OXAF)llllllllllllllllllllllllllllllllllllllllllllllllllllllvoid TIM2_PWM_Init(u 16 arr,ul6 psc)(/99999999JQ999RCC->APB1ENR|=1«O; /TIM2?RCC->APB2ENR|=1«2;/?PORTA?RCC->APB2ENR|=1«3;/?PORTB?/ GPIOB->CRL&=OXFFOFFFFF;/PB5?GPIOB->CRL&=0XFFFF0FFF; /PB3?GPIOB->CRH&=0XFFFF00FF; /PB10/PB11?GPIOA->CRH&=OXOFFFFFFF; /PA15?/ GPIOB->CRL|=0X00B00000; /PB5?GPIOB->CRL|=OXOOOOBOOO; /PB3?GPIOB->CRH|=OXOOOOBBOO; /PB10/PB11?GPIOA->CRH|=OXBOOOOOOO;/PA15?RCC->APB2ENR|=l«0; /?/ AFIO->MAPR&=OXFFFFF3FF; /?MAPR?ll:10AFIO->MAPR&=OXFFFFFCFF;/?MAPR?9:8/ AFIO->MAPR|=1«11;/?,TIM3_CH2->PB5AFIO->MAPR|=0X02000300;/?JTAG-DP?SW-DP?TIM2->ARR=arr; /?TIM2->PSC=psc; /?/CH2 PWM2?/CH2 PWM2?/CH2?/ TIM2->CCMR11=7«12;TIM2->CCMR1 |=0X7070;/ TIM2->CCMR11=1«11;/CH2?/*?,PB1O/PB11?PWM*/OC2 ?/OC2 ?/ARPE?/9999?3TIM2->CCMR1 |=0X0808; TIM2->CCMR2|=0X7878; / TIM2->CCER|=1«4; TIM2->CCER|=OX1111;TIM2->CRl=0x0080;TIM2->CR1 |=0x01;J/CH1 PA15/CH2 PB3/CH3 PB10/CH4 9B11/short get_gyrox( float first_yaw, double point, short current_gyrox,short current_gyroy)(double p;畔double pd;生。double plUIuCEUEcurrent_gyrox=current_gyrox/(16.384);/|iiA|LiV21EU(|Epd=atan(point/stand_len);/2®UIii1Q(Ep=asin(sqrt(sin(current_gyrox)sin(current_gyrox)+sin(current_gyroy)H:sin(curr ent_gyroy); 畔 ©。%01立pl=sqrt(19.6/ll*(cos(p)-cos(pd);摘 要本系统为由STM32单片机限制模块、姿态采集模块、风力摆模块、人及 交互系统以及风力摆机械结构组成的闭环限制系统。MPU-6050陀螺仪传感器实 时采集风力摆的姿态角及角速度,STM32H03单片机通过PID算法调整轴流电 机转速以限制风力摆。风力摆能够实现快速起摆、画线、复原静止的功能,并能 精确画圆。同时系统可以通过键盘设定运行模式和相关角度值,风力摆的角度和 运行时间由液晶显示,具有较好人机界面。系统设计结构简洁,制作成本低,限 制精度高。关键词:STM32fl03、MPU-6050 模块、PWM 调速AbstractThis system is composed of STM32 control module, attitude acquisition module, wind force model, human and interactive system, and the closed-loop control system composed of wind force. The attitude and angular velocity of the MPU-6050 gyroscope sensor are acquired in real time, and the speed of the motor is controlled by the PID algorithm, and the speed of the motor is controlled by the STM32f 103 algorithm. Wind power can be achieved quickly, draw lines, restore the function of static, and can accurately draw circle. At the same time, the system can set up the operating mode and the relevant angle value, and the angle of the wind force and the running time of the system are displayed by the LCD. The system has the advantages of simple structure, low cost and high control precision.Key words: MPU-6050, STM32f103 module, PWM speed controlif(fabs(p)vfabs(pd)/feqi(i|Li土元 Di。把。笛於CT 立(gyrox=asin(sin(pl)*cos(yaw);/2EUIupAX1/2EU<|E if(current_gyrox>0)gyrox=fabs(gyrox);else ( gyrox="fabs(gyrox);)else(gyrox=-asin(sin(p)cos(yaw);)return gyrox;)short get_gyroy( float first_yaw, double point,short current_gyroy,short current-gyrox)(double p;畔double pd;生。位hA%D%Cdouble plUIuQEUEcurrent_gyroy=current_gyroy/(16.384);/|nA|n1QEU(|IE pd=atan(point/stand_len)*180/pi;/|iiA|Li11Q(EdLi p=asin(sqrt(sin(current_gyrox)*sin(curreiit_gyrox)+sin(current_gyroy)Hssin(curr ent_gyroy); 畔C°%C帼pl=sqrt(19.6/ll*(cos(p)-cos(pd);if(fabs(p)<fabs(pd)(gyroy=asin(sin(pl)*sin(yaw);/2EUIu|LiAY1/6EU(|fE if(current_gyroy>0)gyroy=fabs(gyroy);else ( gyroy="fabs(gyroy);)else(gyroy="asin(sin(p)*sin(yaw);)return gyroy;double PID_gyrox(short Set_pitch,short current_pitch,int kpjnt ki,int kd)static double Speed_gyrox=0;Error = Set_pitch - current_pitch;/if(Error<=0)Error=-Error;d Error = Error - LastError;dd_Error = d_Error - PrevError;LastError = Error;PrevError = d Error;/ ;ve(k)/ i+e(k)i+e(kl)Speed_gyrox + +=kp* Error ki * d_Error kd* dd Error;return Speed_gyrox; )double PID_gyroy(short Set_gyroy,short current_gyroy9int kp,int ki,int kd) (static double Speed_gyroy=0;Error = Set_gyroy - current_gyroy;/if(Error<=0)Error=-Error;d Error = Error - LastError;dd_Error = d_Error - PrevError;LastError = Error;/ i+e(k)PrevError = d_Error;/ ;-re(k)-;4-e(k-l)Speed_gyroy + +=kp* Error ki * d_Error kd* dd Error;return Speed_gyroy; )void speed_control()short a,b;ul6 max=1000,min=500,mid=750;ul6 speedl,speed2,speed3,speed4;MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);a=get_gyrox(09x9gyrox,gyroy);/2®UIu|iAXb=get_gyroy(09x,gyroy,gyrox);/UIu|LiAYspeedl=PID_gyrox(a,gyrox9Kp9Ki9Kd);speed2=-PID_gyrox(a,gyrox9Kp,Ki9Kd);speed3=PID_gyroy(b,gyroy,Kp9Ki,Kd);speed4=-PID_gyroy(b,gyroy9Kp,Ki,Kd);if(speedl>=max)speedl=max;if(speedl<=min)speedl=min;if(speed2>=-max)speed2=-max;if(speed2<=-mm)speed2="min;if(speed3>=max)speed3=max;if(speed3<=min)speed3=min;if(speed4>=-max)speed4=-max;if(speed4<=-min)speed4=-min;TIM_SetComparel(TIM2,speedl+mid); /PA15TIM_SetCompare2(TIM2,speed2+mid);/PB3TIM_SetCompare3(TIM2,speed3+mid); /PB10TIM_SetCompare4(TIM29speed4+mid); /PB11)/void TIM3_Int_Init(ul6 arr,ul6 psc) (TIM_TimeBaseInitTypeDef TIM-TimeBaseStructure;NVICJnitTypeDefNVICJnitStructure;RCC_APBlPeriphClockCmd(RCC_APBlPeriph_TIM3,ENABLE);人/ 人 /ElOOEUTIM TimeBaseStructure.TIM Period=arr;/EedAOUiAO>>5d5uDAEAt)xoEe>>i(ir pAxOraevOUUgAdin以把仓介於5000俨500msTIM_TimeBaseStructure.TIM_Prescaler=psc;/EeOAOAA xviaTIMxE±d6pAE3yEygAOn dpd|ii 10Khz|nAEy|LiAETIM TimeBaseStructure.TIM ClockDivision = 0; /EeOAE±OO O i:TDTS = Tck_timTIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; /TIMioEIEyAfETIM_TimeBaseInit(TIM39&TIM_TimeBaseStructure);/5u%YTIM_TimeBaseInitStructODOJ jLiA4EyE TIMxiLiAaiiEyiLiTIM_ITConfig( /ExAU>>ddBE§AUd J pATIMODflTIM3, /TIM2TIM_IT_Update, ENABLE /EU );NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; /TIMSODINVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;/lEOUOAIEO1NVICJnitStructure.NVICJRQChannelSubPriority = 3; /OOAIEP1NVICJnitStructure.NVICJRQChannelCmd = ENABLE; /IRQr |iiA±»E1AU NVICJnit(&NVICJnitStructure);/uYNVICJnitStructODOJ |LiA2IEy36Ei4>> laEeNVICATIM_Cmd(TIM3, ENABLE); /EUTIMxIaEevoid TIM3_IRQHandler(void)TIM3。丽(if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)/UPeOJ pATIMODIEu6eii:TIM ODIOTIM_ClearITPendingBit(TIM3,TIM_IT_Update);/CyTIMxjLiAdDfl y |Ait»:TIM ODIO speed_control();)int main(void)NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); delayJnitO;/NOE±0- Ey36E14»-uart_init(500000);总%»- r96Oousmart_dev.init(72);/36EU»- USMARTMPU_Init();/36E»- MPU6050TIM2_PWM_Init(1000J199);/PA2 TIM_SetComparel(TIM24); /PA15TIM_SetCompare2(TIM24000); /PB3 TIM_SetCompare3(TIM29l); /PB10TIM_SetCompare4(TIM24000); /PB11delay_ms(300);/60dLCD_Init();/36EU»- LCDPOINT COLOR=RED; /EeOAxdlaIaoiE«LCD_ShowString(30,50,200,16,16JMiiii STM32n);LCD_ShowString(30J0,20046J6;,MPU6050 TEST”);LCD_ShowString(30,90,200,16,16;,ATOMALIENTEKH);LCD_ShowString(30410,2004646;,2023/4/18H); while(mpu_dmp_init() (LCD_ShowString(3(M30,200J6J6JMPU6050 Error'');delay_ms(200);LCD.Fill(30430,239,130+16,WHITE);delay_ms(200);)LCD_ShowString(30,130,200J6J6JMPU6050 OK”);LCD_ShowString(30J50,200J6J6JKEY0:UPLOAD ON/OFFn); POINT_COLOR=BLUE;/EedAxdiaIaA(ffE«LCD_ShowString(30J70,200,16,16,nUPLOAD ON n);LCD_ShowString(30,200,200J6J6J Temp: . C''); LCD_ShowString(309220,20046,16;,Pitch:. Cn);LCD_ShowString(30,240,200J6J6J Roll:. CH);LCD_ShowString(30,260,200,16,16,“ Yaw :. Cn);while(l) (key=KEY_Scan(0);if(key=KEYO_PRES) ( report=!report;if(report)LCD_ShowString(30,170,200,16,16JUPLOAD ON else LCD_ShowString(30J70,200J6J6'UPLOAD OFF1); ) if(mpu_dmp_get_data(&pitch&roIl9&yaw)=0) temp=MPU_Get_Temperature();/pAjLiViiAEOgMPU_Get_Accelerometer(&aacx9&aacy,&aacz);/liiAiLiW4OEUEDvEyYMPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);/|LiA|Lil6AY6CEy%Yif(report)mpu6050_send_data(aacx9aacy9aacz9gyrox9gyroy9gyroz);/OAx6(| OaOjEIOEUEIOAYdCO-EW%Yif(report)usartl_report_imu(aacx,aacy9aacz9gyrox9gyroy9gyrozXint)(rolllOO)/int)(pi tch*100),(int)(yaw*10);if(t%10)=0) ( if(temp<0) (LCD_ShowChar(30+48,200;-;16,0);/IOE%/°Atemp=-temp;/xaFOyEyelse LCD_ShowChar(30+48,200; 16,0);/E¥|ii6/OALCD_ShowNum(30+48+8,2009temp/100346); 人 人人/IOE%OuEy2OLCD_ShowNum(30+48+40,2009temp%10446); /IOE%DjEy2iOtemp=gy rox* 10;if(temp<0)(LCD_ShowChar(30+48,220;-16,0); /IOE%5OOA temp=-temp; /xaIaOyEy else LCD_ShowChar(30+48,220; 16,0); /E¥pd/OA LCD_ShowNum(30+48+8,220,temp/168.34,5,16); 人 人人/IOE%OuEy2i-OLCD_ShowNum(30+48+40,2204emp%10446);/nOE%D;Ey2iOtemp=gyroy*10; if(temp<0) (LCD_ShowChar(30+48,240;-16,0); /IOE%5OOA temp=-temp; /xaFOyEy else LCD_ShowChar(30+489240; 16,0);/E¥|ii6/OALCD_ShowNum(30+48+8,240,temp/168.34,546); 人 人人/IOE%OuEyOLCD_ShowNum(30+48+40,240,temp%10446); /nOE%D;Ey2iOtemp=gyroz*10;if(temp<0)LCD_ShowChar(30+48,260;-16,0); /aOE/oAtemp=-temp; /xaIaOyEyelse LCD_ShowChar(30+489260; 16,0);/E¥|i65ooALCD_ShowNum(30+48+8,260,temp/168.34,5,16); .人 人人/lOE%OuEyOLCD_ShowNum(30+48+40,260,temp%10446);/IOE%D;Ey2i-Ot=0;LEDO=!LEDO;/LEDEAE5) t+;一、系统方案11、主限制器件的论证与选择11.1限制器选用12、角度测量模块的论证与选择23、风扇驱动模块的论证与选择24、电源方案的论证与选择2二、系统理论分析与计算31、风力摆状态的测量与计算的分析3(1)姿态采集分析3