15
ADVANCED EV3 PROGRAMMING LESSON Gyro Turns By Sanjay and Arvind Seshan © 2016 EV3Lessons.com, Last edit 7/19/2016 1

Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

ADVANCEDEV3PROGRAMMINGLESSON

GyroTurnsBySanjayandArvindSeshan

©2016EV3Lessons.com,Lastedit7/19/2016 1

Page 2: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

1. LearnwhatGyroLagis

2. Learnonewaytocorrectforthislag

3. Understandwhyitisimportanttoexplorealternativesolutionstoaproblem

ì Pre-requisites:MyBlockswithInputsandOutputs,Datawires,MathBlocks,Loops

©2016EV3Lessons.com,Lastedit7/19/2016 2

LessonObjectives

Page 3: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

ì Whatislag?ì Thegyrosensorreadingslagbehindthetruevaluesometimes

ì Whentheturnstarts,ittakestimeforthegyrotobeginchanging

ì Thislessonpresentsonewaytodealwithlaginaturn: reducetheamountofanglethatyouturntocompensateforlag

©2016EV3Lessons.com,Lastedit7/19/2016 3

GyroProblem2:Lag

Page 4: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 4

ChangeModeinWaitBlock

1. InthislessonweusetheWaitBlock(gyrosensor)inChangeMode

2. AdvantagesoverCompareMode:• Youdonotneedtoresetthegyrobeforehand• Youcanmeasureifthevaluehaschangedthe

targetdegreesbybothdecreasingorincreasing(noneedtochangethewaitblockforaleftturn)

3. Direction(thefirstinput)defines:• 0– checkifthevaluehasincreasedthedesired

degrees• 1– checkifthevaluehasdecreasedthedesired

degrees• 2– checkifthevaluehaseitherincreasedor

decreasedthedesireddegrees

Page 5: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

STEP1:CreateasimpleGyroTurnprogramthatturns90degreesusingtheWaitforGyroblockinChangeMode

Remember toCalibrate theGyrobeforetheWaitForBlock(seeGyroLessonforhelp)

STEP2:CompensateforLag

A. Compensateforthelagbyreducingtheamountofangletoturnbasedonyourrobot(e.g 86degreesinsteadof90degrees)

B. UseaMathBlocktocreateanautomaticcalculatortocompensateforlag

STEP3:CreateandWiretheMyBlock

STEP4:RepeatthestepstomakeoneforLeftTurnsvs.oneforRightTurns.

©2016EV3Lessons.com,Lastedit7/19/2016 5

GyroTurninFourEasySteps

Page 6: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 6

Step1:SimpleGyroTurn

Page 7: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 7

Step2A:DealingwithLag

Page 8: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 8

Step2B:AutomaticallyCorrectforLag

Page 9: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 9

Step3A:CreateaMyBlock

A. HighlightalltheblocksthengotoMyBlockBuilder

B. Add2inputs:oneforpowerandoneforanddegrees

RefertotheMyBlockswithInputs&OutputslessonifyouneedhelpsettinguptheMyBlock

B

A

Page 10: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 10

Stage3B:WiretheMyBlock

degrees

power

Connectthedegreesvalueintothemathblockandthepowerintothemovesteeringblock

Page 11: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 11

Stage4:UsingtheMyBlock

Page 12: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 12

Step4:TurnDegreesRight

Page 13: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

©2016EV3Lessons.com,Lastedit7/19/2016 13

Step4:TurnDegreesLeft

Page 14: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

ì Whatisgyrolag?Ans.Thegyrosensor’sreadinglagsbehindthetruereading

ì Whatisonewaytocompensateforlag?Ans:Reducethenumberofdegreesthatyouturn

©2016EV3Lessons.com,Lastedit7/19/2016 14

Discussion

Page 15: Gyro Turns - EV3 Lessons · 3. Direction (the first input) defines: • 0 –check if the value has increased the desired degrees • 1 –check if the value has decreased the desired

ì ThistutorialwaswrittenbySanjaySeshan andArvindSeshan

ì Morelessonsatwww.ev3lessons.com

©2016EV3Lessons.com,Lastedit7/19/2016 15

Credits

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.