应用指南.docx
《应用指南.docx》由会员分享,可在线阅读,更多相关《应用指南.docx(10页珍藏版)》请在冰点文库上搜索。
应用指南
SharpGP2D12
Applicationnoteforaninfrared,triangultation-baseddistancesensorwithananalog,non-linearoutput
|Backtohomepage|Displaynavigationbar|
∙Overview
ThisapplicationnoteisintendedtoprovideagoodoverviewoftheSharpGP2D12sensor(Fig.1)anditsuse,especiallyfordynamicsapplication.Ihopeitwillhelpsomerobotiststomakethissensorworkquiteeasilyandtoavoidcertainpitfalls.Thisrangefinderisoneofthemostcommonlyusedinautonomousroboticsapplicationsforhobbyistsandalsoinacademicresearch.Thereasonsforthisareessentiallyitslowprice(about14$atAcroname,forexample),itscompact(~40x14x13mm)andlightweightpackage(acomparisonbetweenseveralsensorsmaybefoundhere).TheGP2D12isbasedonthetriangulationprinciplewithacollimatedinfraredLEDfortheemittingelementandaPSD(PositionSensingDevice)whichconstitutesthereceiver.
Fig.1-SharpGP2D12distancesensor
Fig.2-SharpGP2D12outputpattern
Althoughitexistsaverysimilarsensorwithadigitaloutput(theGP2D02),IwillfocusonlyontheGP2D12whichhasananalogoutput(seeFig.2).ThemainmotivationforthischoiceisthatthedigitalversionisalmosttwiceslowerthantheGP2D12(updateperiodabout75msagainst40msfortheanalogversion).Table1givesabriefoverviewoftheGP2D12specifications(Hereisthefullandlatestofficialdatasheet).
Range:
10to80cm
Updatefrequency/period:
25Hz/40ms
Directionofthemeasureddistance:
Verydirectional,duetotheIRLED
Maxadmissibleangleonflatsurface:
>40°
Powersupplyvoltage:
4.5to5.5V
Noiseontheanalogoutput:
<200mV
Meanconsumption:
35mA
Peakconsumption:
about200mA
Table1-OverviewoftheSharpGP2D12specifications
Note:
itisveryimportanttoputagoodcapacitor(somethinglike22uF)betweenGNDandVcc,directlyonthesensoritself,inordertoreducethenoiseonthe5VpowersupplyduetothecurrentrequiredbytheemittingLED.Intheotherhand,avoidtheuseofacapacitorbetweenthesignaloutputandGNDorVcc:
itmaydramaticallyreducethesensordynamics(lowpassfilter).Below,wewillseehowtonumericallyfilterthisoutputinordertoimprovetheprecisionwithoutdecreasingthedynamics.
∙ADconversionofthesensoranalogoutput
Whenpoweredwitha5Vpotential,theSharpsensorhasamaximumoutputvoltageofabout2.45V,forclosedistances.Thehighestuseabledistancegivesapproximately0.45V(seeFig.2).ItisthereforewisetouseanADconverterwithtwoexternaladjustablevoltagereferences:
VrefandCOM(theoneIemployedistheMAX148BCAP).Inordertoobtainthebestprecision,thehighestlimitoftheconverter(255on8bits)shouldmoreorlesscorrespondtothehighestoutputvoltageofthesensor,thatisthelowestmeasurabledistance,andviceversa.Indoingso,thefullscaleoftheconverterisused.Fig.3showsthemeasuredresult.
Fig.3-GP2D12outputpatternafterADconversion(0->~0.45V&250->~2.45V)
Basedonthesemeasurements,alookuptablecanbeimplementedinamicrocontroller.Formyownapplication,IusedaUbicomSX52microcontrollerwitha256entrieslookuptable.
∙Statisticalanalysisofthesensoroutput
Inordertomeasurethenoisepresentonthesensoroutput,ImadesometestsandstatisticswithaGP2D12sensorplacedatabout25cminfrontofaflatwhitewall.Thedistributionof10'000successivevaluesacquiredbythemicrocontroller(at1kHz)isshownonFig.4.
Fig.4-StatisticalanalysisoftheSharpGP2D12output
ThevaluespresentedherearecharacteristicoftheGP2D12output.Inparticular,thestandarddeviationdoesnotdependonthemeasureddistance.However,theprecisionofthedistancecannotbedirectlydeducedbecausetheoutputisnonlinear.Aconstantstandarddeviationoverthefullrangeofthesensoroutputdoesnotleadtoaconstantprecisionofthecomputeddistance.
Thisgraph(Fig.4)showsthatthenoiseoftheSharpsensoroutputfollowsanormal-likedistributionlaw.Therefore,itwouldbewisetoaverageseveralsuccessiveoutputvaluestoimprovetheprecision.
Notethatthisquiteimportantnoiseisessentiallyduetothesensoritself(electronicnoise).Thenoiseintroducedbytheconverterismarginal.SeeFig.8bellowtoconvinceyourself.
∙Lookuptableforlinearization&Precisionevaluation
Astheemployed8-bitmicrocontrollerisnotabletoefficientlyhandlemultiplicationsanddivisions,alookuptablepreferabletoconverttheoutputvaluesofthesensorsintodistances(anotherapproach,usingapowerregression,isexplainedhere).AstheconvertedvaluesfromtheADconverterare8-bitcoded,thebestwecandoistousealookuptablewith256entries.Themicrocontrolleroffersthepossibilitytostore12-bitdataintheprogrammemory.Itisthereforeeasytostorethedistancesinmillimeters(from100to800)thatwouldrequire10bits.
Asthemicrocontrollerhasnotalotofprogrammemory,inthecaseoftheuseofseveralGP2D12,itseemswisetohaveasingletableforallthesensors.Thefollowinggraph(Fig.5)showsthemeasuredoutputpatternsof4differentsensorsredsimultaneouslyandseveraltimesatthesamedistance(onlytheaverageforeachdistancesandeachsensorsareshown).
Fig.5-CharacteristicsoffourdifferentSharpGP2D12sensors
40referencedistancesforeachsensorhavebeendefinedinordertoplotthesegraphs.Alinearapproximationbetweeneachpairofsuccessivepointsismade.Onthefollowinggraph(Fig.6),onlytheactuallymeasuredpoints(foroneofthefoursensors)andtheircorrespondingstandarddeviationareshown.
Fig.6-Setof40measuredvaluesandtheircorrespondingstandarddeviation
Basedonthisgraph,arapidevaluationoftheprecisioncanbedone.Itiseasytounderstandthatthevaluesabove700mmarealmostunusable.At600mm,theprecisionisonly20mmandbecomesbetterwithcloserdistance(about2mmat200mm).Ofcourse,usingauniquelookuptableforseveralsensorsslightlydecreasestheprecision,buthowevermustrepresentagoodcompromiseincertaincases.
∙Dynamicdistancemeasurement
TheanalogoutputoftheSharpGP2D12sensorsmovesinvoltagestepswhenthemeasureddistancechanges.Thesestepslastabout40ms(seeFig.7).
Fig.7-SharpGP2D12operationovertime
Thisbehavioriscertainlyduetothefactthatitprocessesanoutputsignalbyinternallyaveragingsuccessivevalues.Let'sassumethatthebestwaytointerpretthissignalistotakethesteplevelasthevaluemeasuredatitsmiddle.Becausethereissomenoiseonthesensoroutput,wecangetanimprovedvalueofthedistancebyaveragingtheoutputalongthestep.
Fig.8showsthetypicalsensoroutputduringafastmovementofthetargetobject.Asyoucansee,thenoiseonthestepscanreachabout±100mV.
Fig.8-Sharpsensoroutputduringdynamicmeasurement(200mVand20msperdivision)
Whatismoreinterestingforusisthesamesignalseenbythemicrocontroller(Fig.9).
Fig.9-Sharpsensoroutputseenbythemicrocontrollerduringdynamicmeasurement
Thereadingfrequencyoftheconverteris1kHz.Thereforetheprocessorcanhaveanupdatedvalueevery1msandthusabout40valuesperstep.These40valueswillbeaveragedovertimeinordertoobtainagoodapproximationofthesteplevelwithoutnoise(thisprocedureactslikeadigitallow-passfilter).Toachievethis,thepointsbelongingtothesamestepsmustberecognizedandclustered.
Thereareessentiallytwocriteriatoachievethisclustering.Thefirstiscertainlythedifferencebetweensuccessivedata.Ifthedifferenceisgreaterthanaspecifiedthreshold,theprocessorcanknowthatitisthenextstep.Thesecondoneisthemaximumtimeallowableforastep.Iftwoofthemaremerged,wecanendthesetofsuccessivevaluesbelongingtothesamestepbyknowingthemaximumlengthofthisset.Themaximumnumberofconversionduringastepis43.Soifthereisnosignificanttransitionafter43readings,wecanassumethatfuturedataarepartofthenextstep.Ifsomedataarenotwellclassified,inthiscase,thisisnotsoimportantbecauseitwillnotsignificantlychangethemeanvalueofthesteps.
Ifallthestepsareatthesameheight(staticcase),thisclusteringprocesswilllosethesynchronization.But,assoonasatransitionappears,thealgorithmwillautomaticallysynchronizeagain.
Thisalgorithmhasbeenimplementedinthemicrocontroller.ThecomputedmeansofthestepsarerepresentedinblackonFig.10.Pleasenotethattheclusteringisappliedtotheroughsensorvaluesandnottothedistancesafterconversionthroughthelookuptable.Thisalgorithmisintendedtofilterthenoiseofthesensoroutput,whichisconstantoverthefullscaleofdistances.Ifthesuccessivevaluesfromthesensorwerefirstconvertedintodistances,thenoisewouldhavenotalwaysthesamemagnitude.
Fig.10-Resultoftheclusteringprocess
Thethresholdforthedifferenceissetto15andthemaximumnumberofpointsbelongingtothesamestepwas43.
Wecanseethattherewasnotenoughdifferencebetweenthefourthandthefifthsteps.Thereforethe43firstpointshavebeenallocatedtothefourthstep.Andthelastpoints(actually38)beforethenextrecognizedtransitionarepartofthefifthstep.
Notethatthecomputationofthisaveragedoesnotrequire40or43registersinmemory.Asumvariableon16-bitisupdatedateachreadingoftheconverter.Whentheendofaclusterisdetected,thesumisdividedbythenumberofdataintheset.Eachcomputedaveragewillbethentransformedintoadistanceviathelookuptable.Thisdistanceistime