Transcript

159

Harvester and Transporter Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

Introduction:

Inthisguide,theRangerBotwillbeprogrammedtofollowaline,pickupanobjectusingtheharvester,andputtheobjectintothetransporter.Itwillalsocountthenumberofobjectscollected.ThisguideisforusewiththeLabVIEW™forLEGO®MINDSTORMS®programminglanguage.

Review:

•To reviewthebasicprinciplesofconnectingtotheNXTBrickandconfiguringLabVIEWforLEGOMINDSTORMSforusewithvarioussensorsandmotors,reviewtheProgrammingGuidesandTutorialVideosfromLessons2and3.

•ToreviewthebasicprinciplesofprogramminginLabVIEWforLEGOMINDSTORMS,reviewtheProgrammingGuidesandTutorialVideosfromtheLineFollowerProgrammingExtension.

•ThesematerialscontaindetailedinformationabouthowtousetheSchematicEditor,andhowtocreatethestructures,functions,constants,andwiresthatarepresentedinthisguide.

•ThisprogrammakesuseoftheScreen Update SubVI,providedontheTETRIX® Getting Started GuideDVD.ThisfunctionusestheNXTtodisplaycustomtextaswellaslightandultrasonicsensorreadings.

•Usethesestepstoaddthefunctiontotheprogram:

a.Withintheblockdiagram,right-clicktobringuptheFunctionspaletteandchooseSelect a VI.

b.ThennavigatetowheretheScreen Update SubVIissaved.

Note:IftheScreenUpdateSubVIhasnotbeensavedonthecomputerinaspecificlocationalready,downloaditfromtheDVDbynavigatingtotheResourcestabandselectingtheScreen Update SubVI Program (LabVIEW for LEGO MINDSTORMS)button.

c.OncetheScreenUpdateSubVIhasbeenlocated,openitandplaceitontheblockdiagram.

Getting Started:

1.Openanewprojectfileandgototheblockdiagram.

a.CreateanewRangerrobotprojectandnameitHarvester and Transporter.

b.UsingtheSchematicEditor,configuretherobottohaveaTETRIX180°ServoMotorattachedtoServoPort1.

c.CreateanewVI.

TETRIX®GettingStartedGuideExtensions

160

Initialize the Servo:

2.Thecodeinvolvesfirstinitializingtheservoposition,delayingforonesecond,andthenenteringthemaincodeWhileLoop.

a.Createthecodeshown,beginningwiththeMove Servos function,thenthe Wait for Time (sec)function.

b.NotethatthereisalargeWhileLoopenclosingtheremainderofthecode.CreatethisWhile Loopandensureitiswideenoughtocontainallthecodethatfollows.

Line Follower Code:

3.InsidetheWhileLoop,thecodedisplaysthecurrentballcountandthenperformsaline-followingfunctionwithaspeedthatvariesbasedontheproximitytotheultrasonicsensor.

a.Createthecodeshown,beginningwiththeScreen Update SubVI,thentheRead Touch (Count)functionandthentheDraw NumberfunctiontodisplaythecurrentballcountontotheNXTBrickdisplay.

b.Next,theultrasonicsensoriscomparedtoathresholdtodeterminethemotorspeedwhichissenttoeithertherightorleftmotor,dependingonwhetherthelightsensorreadingshowsthattherobotisontheline.

Harvester and Transporter Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

ExtensionsTETRIX®GettingStartedGuide

161

Harvester and Transporter Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

Harvest Ball When Detected Code:

4.Next,theproximitytoanobjectischeckedagain.Iftheobjectisveryclose,thentherobotentersharvestingmodebystopping,raisingtheservotocollectaball,andwaitingforaballtoenterthetransporter.

a.Createthecodeshown,beginningwiththethresholdcomparisonandtheCase structure.Then,usethe Align Text Centerfunctiontowrite“Found!”totheNXTdisplay,theMotor Move command,andtheWait for Time (sec)function.

b.Next,aForLoopisusedtoraisetheservofrom150to30unitsinstepsof1witha10-milliseconddelaybetweensteps.

Note:A +1(increment) functionisusedbecausethevalueoftheindexterminalstartsatzero.

c.Next,the Read Touch (count)functionisplacedinsidea While Loop,readingcontinuouslyuntiltheballcounthasincreasedovertheinitialreadingatthestartoftheWhileLoop.

5.Oncetheballcounthasincreased,therobotpauses,backsup,andthenlowersitsarm.

a.Createthecodeshown,beginningwiththeWait for Time (sec)function,followedbytheMove Motorsfunction,anotherWaitforTime(sec),andthenaMoveMotorstostopthemotors.

b.Next,aFor Loop isusedtolowertheservobackdownfrom30to150units,instepsof1witha10-milliseconddelaybetweensteps.

Note:A+1(increment)functionisusedbecausethevalueoftheindexterminalstartsatzero.

c.Then,aone-seconddelayexecutesbeforethelooprepeats.

TETRIX®GettingStartedGuideExtensions

162

Harvester and Transporter Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

d.Noticethe Read NXT ButtonsfunctionwiredtotheconditionterminaloftheouterWhileLoop.ThisensuresthatthecoderunsuntiltheEnterbuttonoftheNXTispressed.

6.Finally,iftheCase structureconditionisFalse,indicatingthatnoobjectisdetected,thennocodeisexecutedbytheCasestructure,andtherobotwillcontinueitsline-followingbehavior.

ExtensionsTETRIX®GettingStartedGuide


Top Related