labview™ for lego® mindstorms - tetrix® robotics

4
159 Harvester and Transporter Programming Guide (LabVIEW for LEGO ® MINDSTORMS ® ) Introduction: In this guide, the Ranger Bot will be programmed to follow a line, pick up an object using the harvester, and put the object into the transporter. It will also count the number of objects collected. 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. Within the block diagram, right-click to bring up the Functions palette and choose Select a VI. b. Then navigate to where the Screen Update SubVI is saved. Note: If the Screen Update SubVI has not been saved on the computer in a specific location already, download it from the DVD by navigating to the Resources tab and selecting the Screen Update SubVI Program (LabVIEW for LEGO MINDSTORMS) button. c. Once the Screen Update SubVI has been located, open it and place it on the block diagram. Getting Started: 1. Open a new project file and go to the block diagram. a. Create a new Ranger robot project and name it Harvester and Transporter. b. Using the Schematic Editor, configure the robot to have a TETRIX 180° Servo Motor attached to Servo Port 1. c. Create a new VI. TETRIX ® Getting Started Guide Extensions

Upload: others

Post on 26-Mar-2022

30 views

Category:

Documents


0 download

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