HMC5883L标定补偿SW_Routine_Calibration

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

ThisdoucmentoutlinestheimplementationofUserClibrationofthemagneticcompass.Specifically,itdescribesthemathematicalcomputationsinC/C++sourcecode.Thiscalibrationwillcorrectorcompensateforthehardironeffects.Hardironeffectsaremagneticfieldsuperimpositionsontheearth'smagneticfieldthatarefixedinmagnitudeandwhichdonotdependontheorientationofthecompass.Thecompasscalibrationshallbeinitiatedbyausercommandthatputthecompassintothecalibrtionmode.Onceinthatmodethecompassshallberotatedthrough360degreesabouththeForwardorLeftdirectionfollowedbya360rotationabouttheUp-Downdirection.Thatis,therearetwofullrotationsrequiredtocompletethephysicalmovementrequired.Attheendoftherotationsacommandtoendthecalibrationprocessshallbeissedbytheusertothecompass.ItisimportanttokeeptheForward(orLeft)axisleveldiringthefirstrotationandtokeeptheUp-Downaxisverticalduringtheseconcalibrationanduntilthefulcalibrtioniscomplete.Failuretofollowtheseprocesswillresultinlessthanoptimalcalibrationandheadingerrorsarelikely.ForwardDirection(+)LeftDirection(+)UPDirection(+)Figure1First360Rotation2nd360Rotation#defineCalThreshold0intXmax,Xmin,Ymax,Ymin,Zmax,Zmin;voidInitialize_Cal_Variables(intMagX,intMagY,intMagZ)voidCalibrate(intMagX,intMagY,intMagZ)voidCompute_and_Save(void)voidHard_Iron_Correction(intXoff,intYoff,intZoff)voidInitialize_Cal_Variables(intMagX,intMagY,intMagZ){//setMaxandMinvaluesofthemagoutputtothecurrentvaluesXmax=MagX;Xmin=MagX;Ymax=MagY;Ymin=MagY;Zmax=MagZ;Zmin=MagZ;}voidCalibrate(intMagX,intMagY,intMagZ){//thisroutinewillcapturethemaxandminvaluesofthemagX,Y,andZdatawhilethe//compassisbeingrotated360degreesthroughthelevelplaneandtheuprightplane.//i.e.horizontalandverticalcircles.//Thisfunctionshouldbeinvokedwhilemakingcontinuousmeasurements//onthemagnetometersintMagXreading,MagYreading,MagZreading;MagXreading=MagX;//justforclarification...canremovetheselinesMagYreading=MagY;MagZreading=MagZ;if(MagXreadingXmax)Xmax=MagXreading;if(MagXreadingXmin)Xmin=MagXreading;if(MagYreadingYmax)Ymax=MagYreading;if(MagYreadingYmin)Ymin=MagYreading;if(MagZreadingZmax)Zmax=MagZreading;if(MagZreadingZmin)Zmin=MagZreading;}voidCompute_and_Save(void){if(abs(Xmax-Xmin)CalThreshold){Mag_UserCal_Offset_X=(Xmax+Xmin)/2;//SaveparametersinEE}if(abs(Ymax-Ymin)CalThreshold){Mag_UserCal_Offset_Y=(Ymax+Ymin)/2;//SaveparametersinEE}if(abs(Zmax-Zmin)CalThreshold){Mag_UserCal_Offset_Z=(Zmax+Zmin)/2;//SaveparametersinEE}}voidHard_Iron_Correction(intXoff,intYoff,intZoff)//callthisfunctionforcorrection{MagX-=Mag_UserCal_Offset_X;MagY-=Mag_UserCal_Offset_Y;MagZ-=Mag_UserCal_Offset_Z;}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功