ADVANCED EV3 PROGRAMMING LESSON Gyro Sensor Revisited By Sanjay and Arvind Seshan
ADVANCEDEV3PROGRAMMINGLESSON
GyroSensorRevisitedBySanjayandArvindSeshan
1. Learnabouthowolderandnewergenerationsofgyrosensorseffectthecalibrationprocess
2. Learnhowtohowtodealwithgyrodriftwiththisupdatedinformationaboutthegyrosensor.
Prerequisites:Datawires,Loops,Logic&ComparisonBlocks,IntroductiontoGyro
©2017EV3Lessons.com,Lastedit8/12/2017
LessonObjectives
2
ì Reset:Currentvalueofthegyrosensorangleissetto“0”.Thisiswhatthegyroblockwithmodesetto“reset”does.
ì Calibration:Thegyrocalibrateswhatitconsiderstobe“still”.Thissetsboththecurrentgyrosensorrateandangleto“0”.Thistypicallyoccurswhenthegyroisconnected.
ì Somepeoplerefertocalibrationasa“hardreset”.Wewillcallthiscalibratethroughthislessontoreducetheamountofconfusion.
©2017EV3Lessons.com,Lastedit8/12/2017 3
TermstoKnow
ì IthasbeenbroughttoourattentionbyMr.SamLastfromNorthCarolinathatcertaingyrosareactingdifferently.
ì Oncertaingyrosensors,thecommonlyusedcalibrationcodeforthegyro(switchingbetweenangleandrate),doesnotwork(i.e.doesnotcausethegyrotoperformarecalibration).
ì Thisisabigissueforanyoneusingoneofthegyrosensorsthatdoesnotrecalibratewiththiscode.
©2017EV3Lessons.com,Lastedit8/12/2017
WhyRevisittheGyro?
Strategy1:
Strategy2:
Strategy3:
Strategy4:
4
RecalibrationMethodsfrom“IntrotoGyro”
ì Weobtaineddatafrom30+gyrosensorspurchasedinvariousyearsaroundtheworld
ì Strategy4code(fromIntroductiontoGyroLesson)providesasimplewaytotestifyouhaveasensorthatsupportsrecalibrationornot.ì Onsensorsthatperformtherecalibration,it
takes3secondstorunthiscode.ì Onsensorsthatdonotperformthe
recalibration,thecoderunsin<.1seconds.ì Weaddedsometimercodetotestagyro
sensorsbyrunningthreerecalibrationsandaveragingtoseehowlongtheytake.
ì Wethoughttheproblemmayberelatedtothecodeonthebottomofthegyro(showninredcircle)– so,werecordedthisaswell.
©2017EV3Lessons.com,Lastedit8/12/2017
TestingtheGyroSensors
5
ì Thereisacorrelationwiththecodesprintedonthegyrosthemselves andwhetherornottheyrecalibratecorrectly.
ì AllgyrosensorsendinginN2andN3worked.AllgyrosensorsendinginN4,N5andN6didnotwork.
ì WeonlyownN3andN4.Testsontheotherswereconductedbyfriends.
ì Note:Ifyoucompletethislessonanddiscovernewnumberstoaddtothelist,[email protected].
©2017EV3Lessons.com,Lastedit8/12/2017
Results
6
18N220N248N2
01N302N303N304N305N306N316N317N319N342N343N344N345N347N349N350N351N3
SampleGyroSensorCodes
09N415N420N421N438N439N450N4
13N517N521N522N527N528N536N545N5
OldType NewType03N605N606N615N617N620N621N623N6
ì Method1:YoucanlookforthetinycodeprintedonthegyrosensorsandlookatthelasttwoLetter-Digitcombination
ì Method2:YoucanrunthetestcodewehaveprovidedforyouonEV3Lessonsanditwilltellyouwhichsensoryouhaveandifthetraditionalrecalibrationoranalternativerecalibrationmethodisneeded.
©2017EV3Lessons.com,Lastedit8/12/2017
WhatSensorVersionDoYouOwn?
7
PhotoCredit:ThomasMadeya
“N5”“N3”
Seenextslideforzoomedinversions
©2017EV3Lessons.com,Lastedit8/12/2017 8
CloseupViewoftheSampleCodes
PhotoCredit:“N5”and“N6”ImagesbyThomasMadeya
“N5”“N3” “N4” “N6”
• WhereverthispresentationmentionsN4,theresulthasbeenconfirmedforN5 andN6aswell.
• WhereverthispresentationmentionsN3,theresulthasbeenconfirmedforN2aswell.
WhatifDon’tOwnanN2/N3Sensor?*
HardwareSolutionì Unplugandre-plugyourgyro
sensorwhilemakingsureyourrobotisstill
ì ThistechniquerequiresaccesstotheEV3portsandispronetofailuresinceyoumayshaketherobotasyoure-plugthewire.
SoftwareSolutionì Ifyoureadtheportthegyrois
connectedtoasaninfraredsensorandthenreaditagainasagyrosensor,itseemstoforcearecalibrationofthegyro.
ì Seethenext4slidesforupdatedrecalibrationcodeforthe“N4”andupsensors.(Canbeusedwith“N3”andbelowaswell.)
ì Note:Didnotworkreadingthesensorascolor,ultrasonic,touchortemperature.
©2017EV3Lessons.com,Lastedit8/12/2017
*Aswediscovermoresolutions,thisslidewillbeupdated.9
©2017EV3Lessons.com,Lastedit8/12/2017
RecalibrationStrategy5
10
First,readingthegyroasanIRsensorandthenasagyrocausesthegyrotorecalibrate.
Second,addawaitblocktogivethesensorabitoftimetofullyrecalibrate.Ourmeasurementsshowthat4 secondsissafe.NotethattheStrategy1codeinIntrotoGyro,recalibrationonlytook0.1seconds.
Notefor“N3”sensorusers:intherestofyourprogram,youshouldonlyusethe“angle”modesofthegyro.Usingthe“rate”or“rateandangle”modewillcausethegyrotorecalibrate.“N4”sensoruserscanchangemodeswithoutcausingarecalibration.Modechangesdo“reset”theangleto0.
©2017EV3Lessons.com,Lastedit8/12/2017 11
RecalibrationStrategy6
Thisversionofthecalibrationleavesthegyroinrate+angle mode.Thisisusefulfor“N3”usersifyouusetherateoutput.
Thisversiontakesalittlebitlonger(4vs.3seconds)thantheStrategy2codeinIntrotoGyro.
Notefor“N3”sensorusers:intherestofyourprogram,youshouldonlyusethe“rate+angle”modesofthegyro.Usingthe"angle"or“rate”modewillcausethegyrotorecalibrate.Also,***DONOT***usethegyroresetmode- thisforcesthegyrointoanglemodewhichwillcausealong3secondrecalibration.“N4”sensoruserscanchangemodeswithoutcausingarecalibration.Modechangesdo“reset”theangleto0.
©2017EV3Lessons.com,Lastedit8/12/2017 12
RecalibrationStrategy7
Notefor“N3”sensorusers:intherestofyourprogram,youshouldonlyusethe“angle”modesofthegyro.Usingthe“rate”or“rateandangle”modewillcausethegyrotorecalibrate.“N4”sensoruserscanchangemodeswithoutcausingarecalibration.Modechangesdo“reset”theangleto0.
Thisversionofthecalibrationleavesthegyroinanglemode.Thisisprobablythemostcommonwaytousethegyro.Thiscodetakesabout4sectorun(vs.0.1secfortheStrategy3codeinIntrotoGyro)
©2017EV3Lessons.com,Lastedit8/12/2017 13
RecalibrationStrategy8
Notefor“N3”sensorusers:intherestofyourprogram,youshouldonlyusethe“rate+angle”modesofthegyro.Usingthe"angle"or“rate”modewillcausethegyrotorecalibrate.Also,***DONOT***usethegyroreset- thisforcesthegyrointoanglemodewhichwillcausealong3secondrecalibration.“N4”sensoruserscanchangemodeswithoutcausingarecalibration.Modechangesdo“reset”theangleto0.
Thisversionofthecalibrationleavesthegyroinrate+anglemode.Thisisusefulfor“N3”usersifyouusetherateoutput.
ì ThenewgyrocalibrationstrategiesinthislessonworkforeithertheN2-N3orN4-N6sensors
ì Notethatallthenewrecalibrationstakeabout3-4seconds.Thisissignificantlymorethanthepreviousstrategy1and3(intheIntrotoGyrolesson)whichleftthegyroinanglereadingmode(0.1secvs.3-4secs)ì Therefore,ifyouhaveolderN2andN3gyros,youmightwanttouse
theoldcodethattooklesstimetorecalibrate.
ì ThenewerN4-N6sensorsallowyoutousedifferentgyromodesinsideaprogramwithoutcausingarecalibration.
ì Conclusion:TherewasahardwarechangebetweentheN3andN4gyros.TheoldergyroslikelyuseISZ-655(asingle axis gyro chip).
©2017EV3Lessons.com,Lastedit8/12/2017 14
Discussion
ì Thankstothecommunitysendinginallthecodesonthegyrosensors,itdoesappearthatthereisadatecodeoneverygyrosensor.45N5 =[Week][Factory/Electronics][Year]=Week45,N,2015
ì ByrunningEV3Dev,DavidLechner,wasabletoidentifythatnewersensorshavesomeadditionalsecretmodesenabledbythenewhardwareinsidethesensor.Thenewersensorshaveadual-axisgyrochipsoitcanmeasureangleandrateaboutasecondaxis(paralleltothecable)
ì Note:Thesemodesarenotaccessible throughthestandardEV3-GGyroblockevenifyouownthenewergyrosensors.Themodesarereferredtoas"TILT-ANG"and"TILT-RATE”inthesensoritself.ì Watchhttps://youtu.be/KjlT0BUJr-w forhowDavidLechner discovered
thedifferentmodes.
©2017EV3Lessons.com,Lastedit8/12/2017 15
WhatisGoingOn?
Credit:ThisinformationonthisslidewasprovidedbyDavidLechner andJorgePereira
ì Lechner believesthatwithN4,N5andN6sensors,sincetherearenew(hidden)modesthatmeasurerotationaroundadifferentaxis,thesensornolongerresetswhenswitchingmodesfromangletorate.
ì TheIRSensorBlockworksinoursolutioncodebecauseitforcesthesensorcommunicationtotimeoutandcausesthesensortoreset.ThisisbecausetheLEGOfirmwarehandlestheIRsensordifferently(longertimeout).
©2017EV3Lessons.com,Lastedit8/12/2017 16
WhatDoesThisMeanforCalibration?
Credit:ThisinformationonthisslidewasprovidedbyDavidLechner andJorgePereira
ì ThistutorialwaswrittenbySanjaySeshanandArvindSeshan
ì Morelessonsatwww.ev3lessons.com
ì ThankyoutoMr.SamLastforfirstreportingthisissuetous.
ì ThankyoutoDavidLechner forinvestigatinganddiscoveringthehiddenmodesofthenewersensor.
©2017EV3Lessons.com,Lastedit8/12/2017
Credits
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
17