Top Banner
ADVANCED EV3 PROGRAMMING LESSON Gyro Sensor Revisited By Sanjay and Arvind Seshan
17

Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

Mar 07, 2018

Download

Documents

DinhThuy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ADVANCEDEV3PROGRAMMINGLESSON

GyroSensorRevisitedBySanjayandArvindSeshan

Page 2: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

1. Learnabouthowolderandnewergenerationsofgyrosensorseffectthecalibrationprocess

2. Learnhowtohowtodealwithgyrodriftwiththisupdatedinformationaboutthegyrosensor.

Prerequisites:Datawires,Loops,Logic&ComparisonBlocks,IntroductiontoGyro

©2017EV3Lessons.com,Lastedit8/12/2017

LessonObjectives

2

Page 3: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì Reset:Currentvalueofthegyrosensorangleissetto“0”.Thisiswhatthegyroblockwithmodesetto“reset”does.

ì Calibration:Thegyrocalibrateswhatitconsiderstobe“still”.Thissetsboththecurrentgyrosensorrateandangleto“0”.Thistypicallyoccurswhenthegyroisconnected.

ì Somepeoplerefertocalibrationasa“hardreset”.Wewillcallthiscalibratethroughthislessontoreducetheamountofconfusion.

©2017EV3Lessons.com,Lastedit8/12/2017 3

TermstoKnow

Page 4: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì IthasbeenbroughttoourattentionbyMr.SamLastfromNorthCarolinathatcertaingyrosareactingdifferently.

ì Oncertaingyrosensors,thecommonlyusedcalibrationcodeforthegyro(switchingbetweenangleandrate),doesnotwork(i.e.doesnotcausethegyrotoperformarecalibration).

ì Thisisabigissueforanyoneusingoneofthegyrosensorsthatdoesnotrecalibratewiththiscode.

©2017EV3Lessons.com,Lastedit8/12/2017

WhyRevisittheGyro?

Strategy1:

Strategy2:

Strategy3:

Strategy4:

4

RecalibrationMethodsfrom“IntrotoGyro”

Page 5: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì 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

Page 6: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì 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

Page 7: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì Method1:YoucanlookforthetinycodeprintedonthegyrosensorsandlookatthelasttwoLetter-Digitcombination

ì Method2:YoucanrunthetestcodewehaveprovidedforyouonEV3Lessonsanditwilltellyouwhichsensoryouhaveandifthetraditionalrecalibrationoranalternativerecalibrationmethodisneeded.

©2017EV3Lessons.com,Lastedit8/12/2017

WhatSensorVersionDoYouOwn?

7

PhotoCredit:ThomasMadeya

“N5”“N3”

Seenextslideforzoomedinversions

Page 8: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

©2017EV3Lessons.com,Lastedit8/12/2017 8

CloseupViewoftheSampleCodes

PhotoCredit:“N5”and“N6”ImagesbyThomasMadeya

“N5”“N3” “N4” “N6”

• WhereverthispresentationmentionsN4,theresulthasbeenconfirmedforN5 andN6aswell.

• WhereverthispresentationmentionsN3,theresulthasbeenconfirmedforN2aswell.

Page 9: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

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

Page 10: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

©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.

Page 11: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

©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.

Page 12: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

©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)

Page 13: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

©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.

Page 14: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì 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

Page 15: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì 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

Page 16: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì Lechner believesthatwithN4,N5andN6sensors,sincetherearenew(hidden)modesthatmeasurerotationaroundadifferentaxis,thesensornolongerresetswhenswitchingmodesfromangletorate.

ì TheIRSensorBlockworksinoursolutioncodebecauseitforcesthesensorcommunicationtotimeoutandcausesthesensortoreset.ThisisbecausetheLEGOfirmwarehandlestheIRsensordifferently(longertimeout).

©2017EV3Lessons.com,Lastedit8/12/2017 16

WhatDoesThisMeanforCalibration?

Credit:ThisinformationonthisslidewasprovidedbyDavidLechner andJorgePereira

Page 17: Gyro Sensor Revisited - EV3 Lessonsev3lessons.com/translations/en-us/advanced/GyroRevisited.pdf · Gyro Sensor Revisited ... ì The IR Sensor Block works in our solution code because

ì 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