Squaring or Aligning on a Line - EV3...
Transcript of Squaring or Aligning on a Line - EV3...
ADVANCEDEV3PROGRAMMINGLESSON
SquaringorAligningonaLineBySanjayandArvindSeshan
ì Learnhowtogetyourrobottosquareup(straightenout)whenitcomestoaline
ì Learnhowsquaring(alsoknownasaligningonaline)canhelptherobotnavigate
ì Learnhowtoimproveinitialcodeforaligningbyrepeatingatechnique
ì PracticecreatingausefulMyBlock
ì Prerequisites:MyBlockswithInputs&Outputs,DataWires,ParallelBeams,ParallelBeamsSynchronization
©2016EV3Lessons.com,Lastedit06/19/2016
LessonObjectives
ì MoveSteeringletsyoucontrolbothmotorsatthesametime
ì Whatifyouwanttomoveorstoponemotoratatime?ì UsetheLargeMotorBlock
©2016EV3Lessons.com,Lastedit06/19/2016
Review:MotorMovements
LargeMotorBlock LargemotorblockinONmode/OFFmode
ì Aligningonalinehelpstherobotnavigateì Robotsgetangledastheytravelfartheror
turn(theerroraccumulates)ì Aligningonalinecanstraightenoutarobot.ì Aligningcantellarobotwhereitiswhenit
hastotravelfar
ì ExampleGoal:YourrobotmustdeliveranobjectonlyinsideasmallENDarea.Thedistancebetweenstartandendis8feetì Doyouthinkyourrobotcantravel8feetand
continuetobestraight?
©2016EV3Lessons.com,Lastedit06/19/2016
WhyAlignonaLine?
Start
8ft
Challenge:Maketherobotstraightenout(align/squareup)
©2016EV3Lessons.com,Lastedit06/19/2016
ThreeEasyStepstoAlign
STEP1:Startbothmotors
STEP2:Stoponemotorwhenthesensoronthecorrespondingsideseestheline
STEP3:Stopmovingthesecondmotorwhenthesensoronthatsideseestheline
Hints:UseaLargeMotorBlock,UseParallelBeams,UsetheLargeMotorBlock (Thisslideisanimated)
©2016EV3Lessons.com,Lastedit06/19/2016
WhatAligningShouldLookLike
©2016EV3Lessons.com,Lastedit06/19/2016
NotesAboutOurSolution:
ì Oursolutionuses2ColorSensors(connectedinPorts1and4).
ì Oursolutionassumesthatthecolorsensoronport1isnexttothewheelonmotorportBandcolorsensoronport4isnexttothewheelonmotorportC.
ì Youshouldadjusttheportsasneeded
ì YourcolorsensorsshouldNOTbeplacedrightnexttoeachother(Seeredboxesbelowinrobotimage.Thesearethecolorsensors.)
©2016EV3Lessons.com,Lastedit06/19/2016
BasicSolution:MovingUntilLine
ì Whenyouhavetwoormorebeamsyoudonotknowwheneachbeamwillfinish.
ì Ifyouwantedtomoveafterthealignfinishesyoumighttrytoaddamoveblockattheendofoneofthebeams.ì Note:ThiswillnotworkbecauseEV3codewillplayyourmoveblock
withoutwaitingfortheotherbeamtofinish.ì Solution:Youneedtosynchronizeyourbeams.Tolearnmoreabout
synchronizationandsolutionsgototheAdvancedEV3Lessons.comLessononSyncBeams
ì TheproblemofsynchronizationcanalsobesolvedbymakingaMyBlockoutofthealigncode(refertoMyBlocklessoninIntermediate)ì MyBlocksalwayswaitforbothbeamstofinishbeforeexiting
©2016EV3Lessons.com,Lastedit06/19/2016
Note:Synchronization&ParallelBeams
ì Whatdoyounoticeaboutthesolutionwejustpresented?ì Therobotisn’tquitestraight(aligned)attheendofit.ì Bothcolorsensorsareontheline,buttherobotstopsatan
angle.
ì ChallengeContinued:Thinkabouthowyoucanimprovethiscodesothattherobotendsstraighter
©2016EV3Lessons.com,Lastedit06/19/2016
ImprovingYourAlignCode
ì Youwillgetbetterresultsì ….ifyourcolorsensorsareabout4mm-12mmfromtheground
(seeColorSensorPlacementLessoninRobotDesignLessons)ì ….ifyoudon’tcomeatthelineatsteepanglesì ….ifyoukeepyourcolorsensorsspreadapart
©2016EV3Lessons.com,Lastedit06/19/2016
TipsforSuccess
ì ThistutorialwascreatedbySanjaySeshan andArvindSeshan
ì Morelessonsatwww.ev3lessons.com
©2016EV3Lessons.com,Lastedit06/19/2016
Credits
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.