Download - STEM Challenge Programming Guide (LabVIEW™ for LEGO

Transcript

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