4
190 Dispenser Programming Guide (LabVIEW for LEGO ® MINDSTORMS ® ) Introduction: In this guide, the Ranger Bot will be programmed to wait until an object is loaded into the dispenser. It then follows a line and deposits the object into a box. This guide is for use with the LabVIEW for LEGO ® MINDSTORMS ® programming language. Review: • To review the basic principles of connecting to the NXT Brick and configuring LabVIEW for LEGO MINDSTORMS for use with various sensors and motors, review the Programming Guides and Tutorial Videos from Lessons 2 and 3. •To review the basic principles of programming in LabVIEW for LEGO MINDSTORMS, review the Programming Guides and Tutorial Videos from the Line Follower Programming Extension. • These materials contain detailed information about how to use the Schematic Editor and how to create the structures, functions, constants, and wires that are presented in this guide. • This program makes use of the Screen Update SubVI, provided on the TETRIX ® Getting Started Guide DVD. This function uses the NXT to display custom text as well as light and ultrasonic sensor readings. • Use these steps to add the function to the program: a. From the Robot Project Center, press the Add VI button. b. Navigate to the Screen Update SubVI provided on the DVD and click OK to add the VI to the Robot Files list. c. Double-click the Screen Update SubVI from the list to open it. d. Click and drag the icon in the top-right corner of the front panel to the block diagram of the program. Getting Started: 1. Create a new Ranger project file and name the project “Dispenser.” 2. Using the Schematic Editor, configure the robot to have a TETRIX 180° servo motor attached to Servo Port 1. 3. Create a new VI. Extensions TETRIX ® Getting Started Guide

Dispenser Programming Guide (LabVIEW for LEGO MINDSTORMS · 191 Dispenser Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®) Initialize the Servo and Wait for a Ball to Be Loaded:

Embed Size (px)

Citation preview

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