STEM Challenge Programming Guide (LabVIEW™ for LEGO

4
265 STEM Challenge Programming Guide (LabVIEW for LEGO ® MINDSTORMS ® ) Introduction: In this guide, the Ranger Bot will be programmed to follow a line, pick up an object, move until it detects a wall, and then turn away from it. 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 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. Create a new Ranger robot project and name it STEM Challenge. 2. Using the Schematic Editor, configure the robot to have two TETRIX 180° Servo Motors, attached to Servo Ports 1 and 2. The first servo will be called Gripper, and the second servo will be called Arm. 3. Create a new VI. TETRIX ® Getting Started Guide Challenges

Transcript of STEM Challenge Programming Guide (LabVIEW™ for LEGO

265

STEM Challenge Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

Introduction:

Inthisguide,theRangerBotwillbeprogrammedtofollowaline,pickupanobject,moveuntilitdetectsawall,andthenturnawayfromit.ThisguideisforusewiththeLabVIEW™forLEGO®MINDSTORMS®programminglanguage.

Review:

•ToreviewthebasicprinciplesofconnectingtotheNXTBrickandconfiguringLabVIEWforLEGOMINDSTORMSforusewithvarioussensorsandmotors,reviewtheProgrammingGuidesandTutorialVideosfromLessons2and3.

•ToreviewthebasicprinciplesofprogramminginLabVIEWforLEGOMINDSTORMS,reviewtheProgrammingGuidesandTutorialVideosfromLineFollowerProgrammingExtension.

•ThesematerialscontaindetailedinformationabouthowtousetheSchematicEditorandhowtocreatethestructures,functions,constants,andwiresthatarepresentedinthisguide.

•Thisprogrammakesuseofthe Screen Update SubVI,providedontheTETRIX®GettingStartedGuideDVD.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.CreateanewRanger robot projectandnameit STEM Challenge.

2.UsingtheSchematicEditor,configuretherobottohavetwoTETRIX180°ServoMotors,attachedtoServoPorts1and2.ThefirstservowillbecalledGripper,andthesecondservowillbecalledArm.

3.CreateanewVI.

TETRIX®GettingStartedGuideChallenges

266

STEM Challenge Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

Initialize the Servos:

4.Thecodeinvolvesfirstinitializingtheservopositions,delayingforonesecond,andthenenteringthemaincodeWhileLoop.

a.Createthecodeshown,beginningwiththe Move Servos function,thentheWait for Time (sec) function.

b.NotethatthereisalargeWhileLoopenclosingtheremainderofthecode.CreatethisWhile Loop andensurethatitiswideenoughtocontainallofthecodethatfollows.

Check for an Object, Grip When Found Code:

5.InsidetheWhileLoop,thecodeupdatesthedisplayandthencheckstheultrasonicreadingtodetermineifanobjectisnearby.Ifanobjectisnearby,thecodestopstherobotandlowersthearm.Toachievethis:

a.Createthecodeshown,beginningwiththeScreen Update SubVI,followedbya Less? comparisonfunction.WiretheresulttotheconditionalterminalofaCase structure.

b.TheTruecaseoftheCasestructureindicatesthatanobjectwasfound.InsidetheCasestructure,placeanotherScreen Update SubVI,thenaMove Motorsfunction,andthenaWait For Time (sec)functionasshown.

c.Next,a For Loopisusedtolowertheservofrom100to180units,instepsof1witha10milliseconddelaybetweensteps.

Note:A+1(increment)functionisusedbecausethevalueoftheindexterminalstartsatzero.

ChallengesTETRIX®GettingStartedGuide

267

6.Next,afterloweringthearm,therobotdelaysfor0.5seconds,closesthegripperservo,delaysagain,andthenraisesthearm.Toachievethis:

a.Createthecodeshown,beginningwiththeWait For Time (sec)function,followedbyaFor Looptoclosethegripperservofrom180to100units,instepsof1witha10milliseconddelaybetweensteps.

Note:A+1 (increment) functionisusedbecausethevalueoftheindexterminalstartsatzero.

b.Createanotherdelayfor0.5secondswiththeWait For Time (sec)functionanduseaFor Looptomovethearmservofromposition160to25units,instepsof1witha10milliseconddelaybetweenthesteps.

7.TheCasestructurecodecompleteswithaverificationthattheobjectwassuccessfullygripped,usingthetouchsensor.Thenthentherobotwillmoveinastraightlinetoapproachanobjectfor30secondsandstartturningifitgetstooclosetotheobject.Toachievethis:

a.UseaRead Touch Sensor (pressed) functionandconnecttheresulttotheconditionalterminalofanotherCasestructure.

b.IntheTruecase,usetheScreen Update SubVItodisplay“Status: Got It!”,thenplayatoneanddelayonesecond,asshown.

c.Then,createaWhileLoopandplaceaScreen Update SubVI,thenaCase structure,andaMove Motorsfunction.

d.WirethesonardistanceoutputoftheScreenUpdateSubVItotheCasestructureandcreatecasesfor“..27”,“28..50”,and“51.."

e.CreatenumericconstantsinthecasesasseenandwiretheMoveDCMotorsfunction.

f.PlaceaTick Count (ms)functionoutsidetheWhileLoopandoneinsidetheWhileLoop.

g.Subtractthevaluesfromeachother,asshownandusethe Greater?functiontocomparetheresultto30,000.Wiretheconditionalterminalasshown.

h.PlaceaMove DC MotorsfunctiontostoptherobotandaMove Servosfunctiontoreleasetheobject.

i.IntheFalsecase,display“Status: Missed It!”anddelay0.5seconds

STEM Challenge Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

TETRIX®GettingStartedGuideChallenges

268

STEM Challenge Programming Guide (LabVIEW™ for LEGO® MINDSTORMS®)

j.TheRead NXT ButtonsfunctionandtheGreater?functionarewiredtoanOrfunctionwhichiswiredtotheconditionalterminaloftheouterWhileLoop.ThiswillensurethatthecoderunsuntiltheEnterbuttonoftheNXTispressed.

Line Follower When No Object Detected Code:

8.Finally,the False caseoftheouterCasestructureexecutesaspeed-adjustedlinefollowercodewhennoobjectisdetectedincloseproximity.

a.Toachievethis,usea Greater? comparisonfunctionontheUltrasonicreading,aCasestructuretodeterminespeed,andthenaLess? comparison functionontheLightSensorreadingtodeterminewhichmotortodrive,asshown.

ChallengesTETRIX®GettingStartedGuide