ElectronicDesignEngineering19Vol.1913No.1320117Jul.2011STM32(430070):,,,STM32,uCOS-II,、、、。LCD,。、、,,,。:;STM32;;;uCOS-II:TP242:A1674-6236(2011)13-0103-04Two-wheeledself-balancevehiclebasedonSTM32ZHANGZhi-qiang(WuhanUniversityofTechnolgoy,Wuhan430070,China)Abstract:Thepriceofself-balancevehiclesonthemarketsaretooexpensive,simplexfunction.Anditcannotautomaticallyrestorebalanceafterlostbalance.Accordingtothoseproblems,aself-balancevehiclebasedonSTM32ispresented,whichusesreal-timeoperatingsystemuCOS-IIwithgyroscopes,accelerometer,steeringgearcontroller,encodersconstitutingaself-balancingsystem.ThissystemhasthefunctionofremotecontrolsLCDdisplayandrestorationofbalance.Byobservingthegyroscopedata,itshowsthatthesystemisrunningsmoothly.Also,itismultifunctional,lowcost.Keywords:two-wheeledself-balancevehicle;STM32;gyroscope;accelerometer;uCOS-II,:,,,。·(DeanKamen)DEKA(DEKAResearchandDevelopmentCorp.),Segway。:7。,。,ARM32STM32,CPU72MHz,,,,。1[1-2],,,:、、、。,,,1。,,,::MRL=HTL-HL(1)JRL=GL+HTLR(2),xRM:(m);MRL:(kg);HL:(N);HTL::2011-04-24:201104117:(2010-ZY-JS-028):(1978—),,,,。:。1Fig.1MechanicalmodelxRL··θRL··-103-《》2011132Fig.2Schematicdiagramofsystemcomponents(N);θRL:(rad);JRL:Z(kgm2);CL:(kg·m);R:(m)。:Mp=HL+HR(3)Mp=VL+VR-Mpg(4)Jpθ=(VL+VR)Lsinθp-(HL+HR)Lcosθp-(CL+CR)(5),xp:(m);yp:(m);Mp:(kg);VL,VR:(N);HL,HR:(N);L:(m);θp:y(rad);Jpθ:z(kg·m2);CL,CR:(kg·m).,sinθP≈θp,cosθp≈1;(1)(2)(3)(4)(5),:(2MRL+2JRLR+MPL+MPR)θRL=-1R(Jpθ+MpL2)+Mp≈≈Lθp+gMpL1Rθp)(6)2(6),,θp,,。。,θp。,,,θpθp。。2。,,。Kalman[3],,,3,。,,PID,。。,,,,,LCD。,,M1M2,,,。3STM32F103ZE[4],ARMCortex-M3,、、、。STM32F103ZE:72MHz,90DMips,1.25DMips/MHz。512k,64kSRAM。:、ADC、SPI、I2C、USARTUSB。MMA7260QT[5],MMA7260QT1.5g、2g、4g、6g4,1.5g,800mV/g,。MMA7260QTxySTM32AD,,,12AD0.8mV,1μs。ADXRS300[6],±300°/s,0.1%,FPGA,。0.5°,0.6°。,16,,PWM。MG995,0.17s/60°(4.8V),13kg·cm,4μs。,2.5kΩ。PT2262PT2272,,PT2272STM32Remote1~Remote4(PC8~PC11),4Remote1~Remote4,STM32。,:。,,。ST150,ST1505μs、0.4mm、1μA、0.25mA,。ST15090°,。74HC14STM32Encode1~Encode4(PC4~PC7)。yp··xp··ep··θp··θRL··..-104-4Fig.4Designofmastercontroller3。LCDILI9320,SPISTM32。,STM324。USART2USTAR3,USART2USART3MAX3232TTLRS232,RS232-15~+15V,。4uCOS-II[7]STM32,3。,。5。3Fig.3Encoder5Fig.5BlockdiagramofsoftwareSTM32,。PLL、SPI、、A/D、I/O、DMA、、,,,。uCOS-II3,:1),Kalman,。,。2),(Balace_sem),PID,。(Unbalace_sem),。3),,SPILCD。,:1)2;2)3;STM32-105-《》2011133)I/O;4)4I/O。AD。,AD,。6。5ARMRealViewMDK[8],LogicAnalyzer。,,LogicAnalyzer,Gyro_degreeθp,LogicAnalyzer7。Gyro_degree,θp-5°≤θp≤5°,。,S,:-5°≤θp≤5°,LCD。θp>25°,θp<-25°,。M1M2,-5°≤θp≤5°,。,1500,Segway。6STM32,,uCOS-II,,。,,,,,。:[1]CrasserF,D’ArrigoA,ColombiS,etal.JOE:Amobile,invertedpendulum[J].IEEETransactionsonIndustrialElec-tronics,2002,49(1):107-114.[2],,,.[J].,2008,27(4):117-120.CHENWei,YANWen-jie,ZHOUChao-ying.Controlsystemdesignoftwowheelsself-balancerobot[J].TransducerandMicrosystemTechnologies,2008,27(4):117-120.[3].[D].:,2006:22-31.[4]STMicroelectronicsIntegratedProducts.STM32Referencemanual[EB/OL].(2011-01-01)[2011-04-01].[5]FreescaleIntegratedProducts.MMA7260QT[EB/OL].(2008-05-03)[2011-04-01].=1&sr=1.[6]AnalogDevicesIntegratedProducts.ADXRS300[EB/OL].(2004-01-01)[2011-04-01].=Datasheets-4&file=DSA-67061.pdf&scan=.[7]LabrosseJJ.μC\OS-[M].,.:,2003.[8].ARMRealViewMDK[M].:,2008.6Fig.6Flowchartofsystemsoftware7LogicAnalyzerFig.7DataofLogicAnalyzer:CN61-1477/TN:ISSN1674-6236:http://mag.ieechina.comad@ieechina.com():2105-1-3:710082≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤≤-106-