Download - Dispenser Programming Guide (LabVIEW for LEGO … · Dispenser Programming Guide (LabVIEW™ for LEGO ... In this case, the code should stop the robot, update the

Transcript

190

Dispenser Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

Introduction:

Inthisguide,theRangerBotwillbeprogrammedtowaituntilanobjectisloadedintothedispenser.Itthenfollowsalineanddepositstheobjectintoabox.ThisguideisforusewiththeLabVIEW™forLEGO®MINDSTORMS®programminglanguage.

Review:

•ToreviewthebasicprinciplesofconnectingtotheNXTBrickandconfiguringLabVIEWforLEGOMINDSTORMSforusewithvarioussensorsandmotors,reviewtheProgrammingGuidesandTutorialVideosfromLessons2and3.

•ToreviewthebasicprinciplesofprogramminginLabVIEWforLEGOMINDSTORMS,reviewtheProgrammingGuidesandTutorialVideosfromtheLineFollowerProgrammingExtension.

•ThesematerialscontaindetailedinformationabouthowtousetheSchematicEditorandhowtocreatethestructures,functions,constants,andwiresthatarepresentedinthisguide.

•ThisprogrammakesuseoftheScreen Update SubVI,providedontheTETRIX®GettingStartedGuideDVD.ThisfunctionusestheNXTtodisplaycustomtextaswellaslightandultrasonicsensorreadings.

•Usethesestepstoaddthefunctiontotheprogram:a.FromtheRobotProjectCenter,pressthe Add VIbutton.

b.NavigatetotheScreenUpdateSubVIprovidedontheDVDandclick OK toaddtheVItotheRobotFileslist.

c.Double-clicktheScreen Update SubVIfromthelisttoopenit.

d.Clickanddragtheiconinthetop-rightcornerofthefrontpaneltotheblockdiagramoftheprogram.

Getting Started:

1.CreateanewRangerprojectfileandnametheproject“Dispenser.”

2.UsingtheSchematicEditor,configuretherobottohaveaTETRIX180°servomotorattachedtoServoPort1.

3.CreateanewVI.

ExtensionsTETRIX®GettingStartedGuide

191

Dispenser Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

Initialize the Servo and Wait for a Ball to Be Loaded:

4.Thecodeinvolvesfirstinitializingtheservopositionandthenwaitinguntilballsareloaded.

a.Createthecodeshown,beginningwiththeMove Servosfunction,andthenRead Touch(inPressedmode).

b.NotethatthereisalargeWhileLoopenclosingtheReadTouchfunctionbutnotenclosingtheMoveServosfunction.CreatethisWhile Loopandensurethatitiswideenoughtocontainallofthecodethatfollows.

c.Theresultofthe Read Touchisfalsewhennoballsareloaded.Inthiscase,thecodeshouldstoptherobot,updatetheNXTdisplay,andwaituntilaballisloaded.ThisisachievedbyusingaWhile LoopinsidetheFalsecaseoftheCase structure,asshown.

TETRIX®GettingStartedGuideExtensions

d.Ifaballisloadedalready,thentheresultoftheRead TouchisTrue.Inthiscase,thecodeshouldcontinue.ThisisachievedbyplacingnocodeinsidetheTruecaseoftheCase structure,asshown.

192

Follow Line Until Object Is Detected, Then Dispense Code:

5.Inthenextsectionofcode,theultrasonicsensorisreadandcomparedtoathresholdvaluetodeterminewhetheratargethasbeenfound.

a.Createthecodeshown,usingaScreen Update SubVItodisplaythemessage“Searching For Target,”andaComparisonfunctionasshown.

b.UsetheoutputoftheComparison FunctionasaninputtoaCasestructureinthenextsection.

6.Inthefinalsectionofcode,aCasestructureisusedtoeitherfollowthelineifnoobjectisfoundordispensetheobjectifoneis.CreatethecodeshowninsidetheTruecase:

a.AScreen Update SubVIisusedtodisplaythemessage“Found! Dispensing...”andaMove Motorstostoptherobot,followedbyaoneseconddelay.

b.Next,aFor Loop isusedtolowertheservofrom10to75units,instepsof1withaonemilliseconddelaybetweensteps.

Note:A+1(increment)functionisusedbecausethevalueoftheindexterminalstartsatzero.

c.Immediatelyafterthat,asimilarFor Loopisusedtoraisetheservobackupfrom75to10.

d.Finally,aWhile Loopisusedtoreadtheultrasonicsensorpositionandrepeatuntilatargethasmovedmorethan10cmaway.

e.Whenthecodeiscomplete,theouterWhileLoopwillrepeatandwillagainwaitforballstobeloaded.

f.NoticetheRead NXT ButtonsfunctionthatiswiredtotheconditionterminaloftheouterWhileLoop.ThiswillensurethatthecoderunsuntiltheEnterbuttonoftheNXTispressed.

Dispenser Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

ExtensionsTETRIX®GettingStartedGuide

193

7.InsidetheFalse caseoftheCase structure,thelinefollowercodeisplaced:

a.Thelightsensorreadingiscomparedtoathreshold,andaCasestructureisusedtosetthedrivemotorstoturnrightorleft,asshown.

Dispenser Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

TETRIX®GettingStartedGuideExtensions