colin lea mapping and remote operation
TRANSCRIPT
-
8/8/2019 Colin Lea Mapping and Remote Operation
1/56
State University of New York at BuffaloDepartment of Mechanical and Aerospace Engineering
MappingandRemoteOperationofthe
LegoMindstormsNXTPlatform
by
ColinLea
Fundedby
Gustav and Greta Zimmer Research Scholar Award
NSF Research Experience for Undergraduates
Advisor:Dr.VenkatKroviFall2008
-
8/8/2019 Colin Lea Mapping and Remote Operation
2/56
2
TableofContents Pages
MappingandRemoteOperationoftheLegoMindstormsNXTPlatform
Abstract 3
Chapter1:Introduction 4
1.1Background 41.2FIRSTRobotics 5
Chapter2:Equipmentandsoftware 7
2.1Software 7
2.2RemoteControl 8 2.3Goals 92.4SettinguptheLegoMindstormsNXT 112.5ProgrammingtheNXTinMatlab 11 2.6ProgrammingtheWiimoteinMatlab 12
Chapter3:MechanicalDesign 14
Chapter4:SoftwareDesign 18
4.1VersionHistory 18
4.2FeatureImplementation 21 4.3Modes 28 4.4ObjectAvoidance 34
Chapter5:InternetOperation 37 5.1Server 37 5.2Webpage 38
Chapter6:FinalRemarks/FutureWork 41
AppendixA:BluetoothSetup 42
AppendixB:InternetOperationCode
nxtControl.php 53 update.php 54
DuetolengthofMatlabcode,itisavailableseparately.
-
8/8/2019 Colin Lea Mapping and Remote Operation
3/56
3
Abstract.
ThisexperiencereportdocumentsmyapplicationoftheLegoMindstorms
NXTroboticplatformandNintendoWiicontrollerwithinMatlabtocreatea
mappingandremotelyoperatedsystem.UsingsensorinputsfromtheNXTIhave
createdasystemtoidentifyobstaclesinfrontoftherobotandstorethemto
memory.Withthisinformation,theNXTiscapableofavoidingpreviouslydetected
obstacles.Mappingisamethodofstoringinformationaboutalocation.Therobot
canbeusedtosurveyanareaandprovidefeedbacktothecomputer.Emphasishas
beenputonuserinput.Itispossibletocontrolusing(1)aNintendoWiicontroller,
(2)agraphicaluserinterface,and(3)viatheInternet.
-
8/8/2019 Colin Lea Mapping and Remote Operation
4/56
4
Chapter1:Introduction
Creatingarobotfromscratchtakesalotoftime,money,intelligence,and
craftsmanship.Todevelop,manufacture,andcodeawholeplatformbyyourselfis
beyondthescopeofaonesemesterproject.Inordertofocusonasingleaspectof
roboticsonemustisolatetheirareaofinterest.Thiscouldinvolvecreatingarobotic
vehicle,creatingasystemofelectronics,orinmycaseprogrammingamostly
prebuiltroboticplatform.
1.1Background
Therearemanyroboticplatformsonthemarket.Manyofthesearesoldas
kitsthatallowuserstocreatearobotoftheirowndesign.TheLegoMindstorms
NXTandVexRoboticsDesignSystemaresuchplatforms.Includedinthesekitsare
wheels,motors,sensors,connectors,andotherpieces.Thesetypesofkitsenableall
sortsofrobotstobemade.Otherroboticsplatformscanbelessmodular,only
allowingforafewconfigurations.Forexample,theParallaxScribblersbodycannot
bechanged.ItusesaBasicStamp2plussensorstoallowuserstoprogram
movementoftherobot.Differentroboticplatformsaremeantfordifferentlevelsof
controlandfunctionality.
Figure1Lego
MindstormsNXT
Figure2VexSystem Figure3Parallax
Scribbler
-
8/8/2019 Colin Lea Mapping and Remote Operation
5/56
5
MyprojectstemmedfrominterestintheFIRSTTechChallenge(FTC).Thisis
asixweekcompetitionduringwhichteamsof10highschoolstudentsplusmentors
worktocompeteinaroboticcompetition.TeamsuseaLegoMindstormsNXT,
motors,andotherpartstocreateasemiautonomousrobotabletocarryoutatask.
Mygoalwastogetmorefamiliarwiththesystemandhopefullyactasastudent
mentorforalocalschool.
1.2FIRSTRobotics
ThegoalofFIRSTistogetkidsinterestedinscience,technology,engineering,
andmath(STEM)throughroboticscompetitions.Differentchallengesexistfor
differentages.TheJuniorFIRSTLegoLeague(Jr.FLL)isforages69andinvolves
basicresearchonatopicandmodelingusingLegobricks.TheFIRSTLegoLeague
(FLL)isforages914andinvolvesdesigningandbuildinganautonomousrobot
usingtheLegoMindstormsNXTplatform.Thestudentscompeteinafriendly
competitionwherelearningisstressedoverwinning.TheFIRSTTechChallenge
(FTC)isforhighschoolagedstudentsandislikeamoreadvancedversionofthe
FLL.ItusestheLegoMindstorms,motors,andothermechanicalpiecestocompete
inacompetition.TheFIRSTRoboticsChallenge(FRC)isalsoforhighschool
studentsandusesaNationalInstrumentsCompactRioplatform,motors,andother
partstocreateanautonomousrobot.ThisismuchmorecostlythantheFTC.The
-
8/8/2019 Colin Lea Mapping and Remote Operation
6/56
6
studentsareexpectedtodotheworkbutadultandstudentmentorsshouldbe
availabletoguideandteach.
Afewproblemssurfacedthatthwartedmyinitialeffortstogetinvolvedwith
theFTC.First,therearenolocalteamscurrentlycompetingtheclosestschoolis
morethananhouraway.Second,thekickoffwasSeptember13thwhichdidntallow
enoughtimetotrytoorganizeateamatalocalschool.
BecauseofmyinitialresearchintoFIRSTIwasalreadyfamiliarwiththe
capabilitiesoftheLegoMindstormsNXTplatform.Combinedwiththelargeuser
baseandplethoraofonlinedocumentationtheNXTwasasuitableplatformtodo
myownresearch.
-
8/8/2019 Colin Lea Mapping and Remote Operation
7/56
7
Chapter2:EquipmentandSoftware
TheNXThasanopenprogramminginterfacewhichmakesitrelativelyeasy
fordeveloperstointeract.Legooffersasoftwaredevelopmentkit(SDK),hardware
developmentkit(HDK)andBluetoothdevelopmentkit(BDK)ontheofficial
website.Thismeansthatwiththenecessaryskillanyonecanbuildtheirown
languagethatiscapableofworkingwiththeNXTplatform.Developershavetaken
fulladvantageoftheSDKandHDKallowingmuchgreatercapabilitiesandmore
advancedrobots.
2.1Software
OneoftheadvantagesoftheNXTisitslargesupportinthesoftware
community.Independentdevelopersanduniversitystudentshavecreatedmany
programminglanguagesandlibrariestointerfacewiththeNXT.Thesoftware
includedisinadequateforanythingmorethanbasicmanipulationanddata
acquisition.SeverallanguageshavebeencreatedthattakeadvantageofCandJava
libraries.Whiletherearedozensofworkinglanguages,onlyahandfulofthem
continuetohavemuchsupport.SomemorepopularonesincludeRobotC,LeJos,
MatlabandtheLabviewToolkit
Likewise,becauseofLegosopenhardwaredevelopmentkit,companiesareable
tocreateadditionalsensorsandmotorstointegratewiththeMindstormsNXT.
HiTechnic,Vernier,andothercompaniesselladditionaladaptorsforproximity
-
8/8/2019 Colin Lea Mapping and Remote Operation
8/56
8
detection,orientationandcolorsensing.Vernieroffersmanysensorsforgeneral
dataacquisitionsuchasaflowratesensor,barometer,andthermocouple.Itiseven
possibletocreateyourownsensorsandattachthemusingaconnectoravailable
throughLego.
2.2RemoteControl
WhiletheMindstormsNXTisfullycapableofworkingautonomously,itisnot
alwaysideal.Therearemanysolutionsavailabletoprovidesuchcontrol.However,
usingMatlablimitsthenumberofusablecontrollers.Anyunsupportedcontroller
wouldrequireanewlibrarytobewritten.Therearesomepopulardevicesthathave
lotsofsupportanddocumentationonline.Forconvenience,Ichosesomethingthat
isalreadysupported.
OnepopulardeviceistheNintendoWiicontroller(Wiimote).Itfeaturesan
ADXL3303axisaccelerometer,aPixArtopticalsensorforinfrareddetection,a
directionpad,and7pushbuttons.
ItisalsocapableofconnectingwithaNunchuckcontrollerattachment.This
Figure4NintendoWiimote Figure5NintendoNunchuck
-
8/8/2019 Colin Lea Mapping and Remote Operation
9/56
9
providesanadditional3axisaccelerometer,ananalogstickfordirectionalcontrol,
andtwopushbuttons.TheWiimotehasgainedalotofattentionoverthelastcouple
ofyears.Whilenothingaboutthecontrolleriscompletelyrevolutionary,its
significanceisinbringingmotioncontrolintotheeyeofthepublic.Becauseofits
compact,capabledesignandinexpensiveprice,theWiimoteisbeingusedinmany
roboticslabsacrosstheworld.Forexample,researchon3Dtrackingfordesktop
virtualdisplayswasrecentlydonebyGraduatestudentsattheHumanComputer
InteractionlabatCarnegieMellon1.
TheuniqueabilitiesalongwithavailableMatlabdriversanddocumentation
madetheWiimoteapracticalchoice.
2.3Goals
AftertinkeringwiththeNXTandWiimoteforaweekorsoIdeviseda
generalgoalforwhatIwantedtoaccomplish.Isoughttotakeadvantageofwhat
bothproductshadtooffer.Ihadexperimentedwiththeaccelerometerdatafrom
theWiimotebutwantedtoimplementsomethingonamorebroadlevel.Iwanted
somethingthatcouldtakeinformationfromtheWiimote,manipulateit,take
informationfromsensorsontheNXT,andcombinethedatainMatlabtoperforma
functionontherobot.Ialsowantedtobeabletotakeinformationfromthe
accelerometerandothercontrolbuttonsontheWiimoteaswellastakeinputfroma
1http://www.cs.cmu.edu/~johnny/projects/wii/
-
8/8/2019 Colin Lea Mapping and Remote Operation
10/56
10
graphicaluserinterface(GUI)onacomputerallowingforpossiblefuture
developmentusingnetworkingtocontroltherobotfromasecondcomputer.With
allofthedataIwantedtoshowtheuserwhatwashappeningwiththesystemonthe
GUI.
Idecidedtocreateasystemformappingandremotecontrol.Thegoalwasto
createasystemthatdepictedwheretherobotwasinrelationtoobstacles.Themap
isusedtostoreinformationaboutanareasuchasthelocationofobstacles.
Obstaclesshouldbeabletobeinputtedeitherbytheuserordetectedbytherobot.I
wantedthreemodes:
WiiNav:ControlledusingthedatafromtheaccelerometerontheWiimote FineControl:ControlusingthedirectionalpadontheWiimoteorusing
controlsontheGUI.Itallowsfortherobottoturnleft,turnright,goforward
asetdistance,andgobackwardasetdistance.
PointFind:Theuserinputsapointandtherobothastomovetothatlocation Attheendofcreatingthissystem,Idecidedtosetupremotecontroloverthe
Internet.IhadlittleexperiencewithwebdevelopmentsoIlearnedhowtosetupa
server,scriptwithPHP,andcontrolthisinputthroughMatlab.
IstartedwithbasicknowledgeofMatlabfromanintroprogrammingfornon
computerscienceengineerscoursefromfreshmanyear(EAS230).Accomplishing
mygoalsnotonlyrequiredsolvingtheproblemsofcontrollingtheNXTbutalso
learningMatlabingreaterdetail.
-
8/8/2019 Colin Lea Mapping and Remote Operation
11/56
11
2.4SettinguptheLegoMindstormsNXT
OneadvantagesoftheNXTisitsabilitytocommunicatewithacomputer
overmultipleprotocols.ItispossibletoconnectusingUSBaswellasviaBluetooth.
WithNXTGitispossibletodownloadprogramsdirectlytotheNXTunitusing
eithermethod.BeingabletouseBluetootheliminatesproblemswithwiresand
makestestingmoreconvenient.Unfortunately,currentMatlablibrariesonly
transferdataoverBluetooth.IhadseveralproblemsgettingtheNXTsetuponmy
MacbookPro.DetaileddocumentationofhowIgotittoworkislocatedinAppendix
A.WhileitworkedsporadicallywiththeBluetoothcardinmylaptop,mybest
resultswerewithusingaBroadcamadapter.
2.5ProgrammingtheNXTinMatlab
WhileMathworks,acompanyrenownedforitsexcellenthelpsystem,created
theMatlabNXTlibrary,thereisnotalotofdocumentationabouthowtocontrolthe
robot.Thedocumentationthatdoesexistdoesnotprovideenoughdetailed
information.ItwouldbehelpfultohavepreviousexperiencehandlingCOMports.
ThebestplacetogetstartedisonablogentrywrittenbyaMathworksemployee2.
Basiccontrolsarelistedbelow.
2http://blogs.mathworks.com/loren/2008/06/30/legomindstormsnxtinteaching/
-
8/8/2019 Colin Lea Mapping and Remote Operation
12/56
12
Function Description
NXT = legoNXT('COM18') InitiatesNXThandle(COM#determinedbytheBluetooth)
Left_Motor = NXT.portB Initiatesvariabletooutputport.OutputportisABorC.
Start(Left_Motor, p) Startsmotorwithpowerpwherepisanumber0100
Stop(Left_Motor) Stopsmotor
Ultrasonic = NXT.port1 Initiatesvariabletoinputport.Inputportis12or3.
set(NXT.Port4, 'type','distance');
Initializeultrasonicsensor
Ultrasonicdata =getdata(nxt.Port1) Getinputdata
2.6ProgrammingofaWiimoteinMatlab
TwoprominentMatlablibrariesfortheWiimotearefWIIneandWiiLAB.
fWIIneisanopensourceprojectthathasntbeenupdatedrecently.WiiLABwas
developedduringasummerundergraduateresearchprogramsponsoredbythe
NationalScienceFoundationatNotreDameUniversity.WiiLABprovidesample
controlthroughfunctionsthatenableaccelerometerdataacquisition,button
readingsandinfrareddetection.Itisalsocapableofgatheringdatafromthe
Nunchuckaddon.
-
8/8/2019 Colin Lea Mapping and Remote Operation
13/56
13
MfileslocatedintheWiilab_Matlabfolderarewelldocumentedandprovide
enoughinformationtostartusingtheWiimotewithlittleadditionalresearch.Basic
controlsareshownbelow.
Function Description
initializeWiimote() InitializesWiimotes.
isWiimoteConnected() ReturnstrueifaWiimoteisconnected.
[x y z] = getWiimoteAccel() Getsaccelerometerdata.Itisarangefrom10to10.Valuesarereturnedtovariablesxyandz.
isButtonPressed('A') ChecksifbuttononWiimoteispressed(Availablebuttons:A,B,ONE,TWO,UP,DOWN,LEFT,RIGHT,Minus,Plus,Home)
-
8/8/2019 Colin Lea Mapping and Remote Operation
14/56
14
Chapter3:MechanicalDesign
TheLegokitincludesamanualwithinstructionsonhowtobuildarobot
capableofmovingaroundandswingingagolfclublikeLegopiece.Iputthis
togetherratherquicklysothatIcouldstartsettingitupinMatlab.AtthebeginningI
wasinterestedintheautonomousaspectoftheprojectmorethanthemechanicsof
thephysicalrobot.Therobothadamyriadofsensorsbutdidnothavegreat
mobility.Itfeaturedtwomotorstomovetherobot,onemotortoswingthegolf
clublikepiece,abumpsensoronthebacktostopitifitranintoawall,anaudio
sensorinfronttodetectnoises,alightsensortodetectbrightnesslevels,andan
ultrasonicsensorpointedforwardtodetectobstaclesintherobotsway.I
constructedthisrobotwithoutanyofmyownadditionssoIcouldbegin
programming.
Figure5InitialDesign(http://www.symbian-freak.com)
ProblemsarosebeforeIevenstarteddevelopingmymappingsystem.While
testing,Inoticedthattherobotdidnotturnwell.Itwasinconsistentandwobbled
someofthetime.Thedrivetrainworkedusingtwomotorscontrollingthefront
-
8/8/2019 Colin Lea Mapping and Remote Operation
15/56
15
wheelsandathirduncontrolledwheelintheback.Unlikeanomnidirectional
wheel,thebackwheelmustbealignedwiththedirectionoftheturninorderto
rotateeffectively.Ifthewheelwasperpendiculartotheturn,themovementwould
notbesmoothandthewholerobotwouldwobble.Insteadofarollingmotionfrom
thewheel,itincreasesfriction,whichcreatesdragonthevehicle.Thisisabig
problembecausethewheelisperpendiculareverytimethattherobotmoves
forwardorbackward.Evenifthewheelisatthecorrectangletoturn,thereare
problemswhentherobotthenhastomoveforward.
Figure6Three-wheeledrobot
Theproblemwasfixedbychangingthewholedesignoftherobot.Ioptedfor
askidsteerdrivetrainandonlyoneadditionalsensor.Skidsteerworksbyisolating
theleftandrightsetsofwheels.Thefrontandbackofeachsideareconnectedso
bothwheelsmovesimultaneously.Thismovesthecenterofrotationinward,
-
8/8/2019 Colin Lea Mapping and Remote Operation
16/56
16
allowingtherobottoturnonapoint.Thissolutionisnotperfectbutallowsforgood
movementusingonlytwomotors.
Figure7SkidSteerrobot
Normallyaxlesareconnectedwithchainsheldonbygears.TheMindstorms
kitdoesnotcomewithanythinglikethissoIhadtocomeupwithmyownsolution.
Iattachedrubberbandstohubsfixedtoeachaxleandgotdesirableresults.Itdoes
notworkperfectlybutissatisfactoryformyneeds.Rubberbandsoffermoreslack
thanchainsbecausetheonlythingholdingtheminplaceisfriction.Onmyrobot,the
motorsareattachedtothefrontaxles.Byexperimenting,Ifoundthatthefrontand
backwheelsmovedatthesamerateaswhenitwasdrivenbythemotors.Ifyou
manuallyturnthebackwheels,thefrontwheelsmoveataslowerrate.Thisis
becausethemotorsaddagreaterresistanceforcethanthefrictionalforceinthe
rubberbands.
-
8/8/2019 Colin Lea Mapping and Remote Operation
17/56
17
Inlargervehicles,askidsteerdrivetraincancauseexcessivewobbling.
BecausemyrobothasalowweighttosizeratioIhavenotnoticedsignificant
problems.
Figure8FinalDesign
-
8/8/2019 Colin Lea Mapping and Remote Operation
18/56
18
Chapter4:SoftwareDesign
Thefinalprogramwastheproductofseveraliterationsofcode.Each
revisionusedanewapproachandbroughtnewinsightintohowtouseMatlabmore
effectively.Iwillbrieflyexplainthedifferentiterationsandthentalkabout
individualcomponentsofthefinalprogram.Adiagramofhowthepartsofthe
systemworkisbelow.
Figure9SystemOverview
4.1Versionhistory
TheprogramstartedfromthecodeIwrotewhileplayingaroundwiththe
NXTandWiimote.Everythingwascrudelyimplemented.Ihadasystemtocontrol
themotorsontheNXTbasedontheaccelerometerdataanddirectionpad(dpad)
-
8/8/2019 Colin Lea Mapping and Remote Operation
19/56
19
fromtheWiimote.AccelerometerdatafromtheWiimoteandthepositionofthe
robotweredisplayedonseparatefigures.AllofthecodewaskeptinoneMatlabfile,
whichrancontinuouslywiththeuseofawhileloop.
Version2Functionbased
Irealizedhowinefficientandunreadablethecodewasinsomeareas.I
removedmuchofthecodefromthemainMatlabfileandcreatedroutinesthatwere
storedinnewmfiles.Ihadamainwhileloopthatcalledseparatefunctionsfor
differentoperationmodes.Ialsoaddedcommentstothefilesforbetterreadability.
Version3GUIDEbased
Atthispoint,Iwasconcernedaboutoverallusability.Themainstructureof
theprogramhadbeencreatedbutitwasntintuitiveandreliedonthecommandline
forrelayinginformationtotheuser.Ispentalotoftimelearningabouthowto
createGUIsinMatlabsoIcouldcreateoneunifiedinterface.MatlabsGraphicalUser
InterfaceDesignEnvironment(GUIDE)helpssimplifythecreationofGUIs.It
includedseveraltypesofbuttons,sliders,andothercontrolsthatallowtheuserto
interfacewiththeprogram.
-
8/8/2019 Colin Lea Mapping and Remote Operation
20/56
20
Theproblemwiththiswasthatitrequiredacompleteoverhaulofmycode.
Itworksbyrunningcallbackfunctionswheneverabuttonispressed.Thereisa
functionforinitializingvariablesandcommandsandthentheprogramrunsthrough
therestofthecoderepeatedlyuntilitisstopped.Insteadofrunningthrougha
whileloop,checkingwhethercertainmodeshavebeenselected,theprogramis
interruptedbybuttonpresses.Mybiggestproblemwasallowingforcontrolthrough
theWiimoteandonscreenatthesametime.IcouldntpolltheWiimoteusinga
whileloopbecauseitwouldessentiallystoptheprogramfromprocessingother
information.Thisrequiredtheimplementationofatimer.Atimerissettoruna
certainfunctionatasetinterval.Forexample,mytimerchecksforWiimotebutton
pressesevery0.5seconds.
Version4InternetControl
Figure10GUIDesignEnvironment
-
8/8/2019 Colin Lea Mapping and Remote Operation
21/56
21
ThelastrevisiondealswithremotelyaccessingtherobotovertheInternet.I
setupaserverinWindowsthatcanbeaccessedfromanyInternetconnection.This
isdiscussedindetailinchapter6.
4.2FeatureImplementation
4.2.1Handle
ThehandleisthebasisofanygraphicaluserinterfacecreatedwithGUIDE.It
actsasastructureforallinformationintheinterface.Inmyprogram,everythingis
storedinthehandleincludingthemap,robotinformation,andbuttondata.The
storedvariablesareinthetablebelow.
Variable Description
clearMap Button:ClearscurrentmapMap Plotofmap
DistanceText Text:showsvalueofdistanceslider
DistanceSlider Slider:Controlsdistancerobottravels
Turn_Right Functionforturningright
Turn_Left Function
text10 Text:Xposition
ExitMode Function
Heading Text
Ypos Text
Xpos Text
WiimoteControl Function
ExitProgram Function
RIGHT Button:
LEFT Button:DOWN Button:
UP Button:
text5 Text:RobotPosition
text11 Text:Yposition
text3 Text:Distance
Ultrasonic Plot
WiiY Plot
text2 Text:YAxis
text1 Text:XAxis
-
8/8/2019 Colin Lea Mapping and Remote Operation
22/56
22
WiiX Plot
internet_mode Function
PointFind_indicator Indicator
Internet_indicator Indicator
WiiNav_indicator Indicator
Point_Find_Mode Function
NXT_Connected_indicator Indicator
Wii_Connect_indicator Indicatortext4 Text:WiimoteConnection
text6 Text:NXTConnection
output Unusedpartofhandle
MODE Variable:1forWiiNav,2forFineControl,3forPointFind
EXITPROGRAM Variable1onexit,0whilerunning
NXT_Connect Variable:trueifNXTisconnected
Lmotor Variable:Storestheporttheleftmotorisattachedto
Rmotor Variable:Storestheporttheleftmotorisattachedto
wii:[1x1Wii] Wiistructure;includesaccelerometerdata
map_length Variable:previouslydefinedlengthofmap
map_height Variable:previouslydefinedheightofmap
robotX Variable:CurrentXcoordinate
robotY Variable:CurrentYcoordinate
robotH: Variable:Currentheading
object_Up Avoidance:1ifobjectabovetherobot
object_Down Avoidance:1ifobjectbelowtherobot
object_Left Avoidance:1ifobjecttoleftofrobot
object_Right Avoidance:1ifobjecttorightofrobot
object Avoidance:1ifobjectwithinsurroundingareaofrobot
Clk Variable:storesprevioustime;usedtofindchangeintime
T Timer:Getsdatafromwiimoteandrunswiifunctions
internet_timer Timer:Getsinformationfrom
timeInit Variable:Getscputimeatinitialization
Theprocessofusingthehandleduringacallbackisunique.Atthebeginning
ofthecallbackitmustbereassignedtoanewvariable.Togettheinformationyou
mustusethefunctionhandles = guidata(hObject).Variablescanthenbe
accessedintheformathandles.[variable].Forexample,theXpositionofthe
robotwouldbehandles.robotX.Attheendofthecallbackthehandlemustbesaved
usingthefunctionguidata(hObject, handles).
4.2.2Initialize
AtthebeginningoftheprogramtheNXT,Wiimote,timer,map,andvariables
mustbeinitialized.Theseareallassignedtothehandletobestoredforlateruse.
-
8/8/2019 Colin Lea Mapping and Remote Operation
23/56
23
FortestingpurposesthereneededtobeawaytousetheprogramwithouttheNXT
orWiimoteconnected.Withoutsomemethodofdetection,thereisanerrorandthe
programstops.IftheNXTisdetected,motorsandtheultrasonicsensorare
initialized.Ifitisnotthemotorsmustbesettodummyvalues.
tryNXT = legoNXT('COM16'); %try to initialize the NXThandles.Lmotor = NXT.portB; %assign ports to left and right motorshandles.Rmotor = NXT.portC;handles.NXT_Connect = 1; %used to check for NXT in routines
set(NXT.portB, 'StopType', 'brake'); %motors stop immediately%instead of coming to a rolling stop
set(NXT.portC, 'StopType', 'brake');
set(NXT.Port4, 'type', 'distance'); %initialize ultrasonic sensor
start(wii.Lmotor, 0); %initializes motors to a speed of 0start(wii.Rmotor, 0);
catch E1 % if the NXT is not connected set dummy variablesdisp('NXT not connected')set(handles.NXT_Connected_indicator, 'BackgroundColor', 'r')
handles.NXT_Connect = 0;handles.Lmotor = 0;handles.Rmotor = 0;
end
ThecommandinitializeWiimote()takescareoferrorsanddoesnotcause
anyproblems.Othervariablesareassignedinthefollowingformat.
handles.wii = Wii(handles.Lmotor, handles.Rmotor, 2, -4);handles.map = Coordinates(70, 50, 30, 10); %(Size X, Size Y, X robot
position, Y robot position)
-
8/8/2019 Colin Lea Mapping and Remote Operation
24/56
24
4.2.3Map
Figure11GUIoverview
TheMapisarguablythemostimportantpartoftheGUI.Itisusedtoshow
wheretherobotis,whereobstaclesare,andwheretheboundariesare.Allofthe
informationforthemapiscontainedinadoubleindexedarraywithapredefined
widthandheight.ZeroesandOnesareusedtoidentifywhereobstaclesarelocated.
Themapisprintedtothescreenusingtheplot()command.Thewholemapisonly
printedatthestartoftheprogramandwhentheClearMapbuttoniscalled.
Wheneveranobjectisfoundortherobotmovesthemapsarrayismodifiedbut
onlythenewpointisplotted.Thissavesprocessingtimebecausethemapdoesnt
-
8/8/2019 Colin Lea Mapping and Remote Operation
25/56
25
havetoreloadeverytimeaneweventoccurs.Bluediamondssignifyobstaclesand
bordersandredcirclessignifythepositionoftherobot.Previousrobotstates
remainshowntoremindtheuserwheretherobothasalreadybeen.
Whiletesting,oneannoyanceIfoundwasresettingtheprogramwhenever
themapbecameclutteredorImovedtherobot.InordertoclearthemapIhadto
exittheprogramandrestart,aprocessthattakesatleast10seconds.Thiscanbea
hindrancetoanybodyplayingwiththerobotinmultipleenvironmentsortestingit
withdifferentobstaclesorindifferentscenarios.ThisiswhyIincludedthefunction
ClearMap.Thisbuttonzeroesthemapsarray,addsanewborder,andredraws
themap.
Obstacleavoidanceisoneofthemainreasonsforcreatingthemapping
system.WhenIdidnthavetheNXTconnected,Ineededawaytotestiftherobot
couldsuccessfullyevadeobjects.Ialsothoughtitwouldbeusefultobeabletoadd
knownobjectstohelpeliminateerrorsintheobjectdetectionsystem.Iwanteda
systemthatwasquickandintuitivetoaddobjectsonthefly.ThemethodI
implementedallowsyoutoclickanywhereonthemapanditwillimmediatelyadd
anobjectinthatlocation.Whenyouclick,thefigure1_WindowButtonDownFcn()
callbackisinitiated.Itgetsinformationfromthefigurewindowtofindtheposition
ofthemouseonthemap.Thisvalueisturnedintoanintegertobestoredinthe
mapsarray.Thepointisthenplottedinthefigure.
-
8/8/2019 Colin Lea Mapping and Remote Operation
26/56
26
pos = get(H.Map, 'CurrentPoint');x = uint8(pos(1)); %uint8 used to get integer valuey = uint8(pos(1,2));H.map.map(x, y) = 1;plot(H.Map, x,y, 'bd')
OnefeatureIwouldliketoseeaddedisanexpandablemap.Currentlywhen
therobotgoesoutsideoftheboundary,itcreatesanerror.ThisisthereasonIadded
boundarymarkers.Anewnumberingsystemwouldhavetobeusedbecausean
arraydoesnotacceptnegativenumbers.
4.2.4Datagraphs:
ThegraphsprovidevisualoutputofdatafromtheWiimote.Itisusefulfor
testingandmonitoringinputs.Itdisplaysthelast10secondsofdata.Originally,I
plottedtheXandYvaluesfromtheWiimoteandtheUltrasonicdatafromtheNXT.
TheUltrasonicdatadidnotappeartobeusefulsoIreplaceditwiththeZvalues
fromtheWiimote.TheZdataisnotcurrentlyusedbutmightbeinthefuture.
Figure12GUIgraphs
-
8/8/2019 Colin Lea Mapping and Remote Operation
27/56
27
4.2.5Timer:
ThetimerisusedtochecktheWiimoteforinformationevery0.5second.If
theA,B,orOnebuttonsaretriggereditswitchesthemode.Ihadtrouble
settingthetimerup.ThefunctionIusedwashandles.T = timer('TimerFcn',
@(h, ev) timer_callback(hObject, eventdata),'execution', 'fixedRate',
'Period', .5). Itmustthenbestartedusing start(handles.T). Myproblem
hadtodowiththeinputarguments.Thetimerchecksforthecurrentmodeandruns
WiinavandFineControlwhennecessary.Whentheprogramquitsthetimermust
bestoppedanddeletedusingstop(handle.T)anddelete(handle.T).
4.2.6OtherGUIElements:
Severalindicatorsareinplacetoincreaseusability.Whenamodeisselected,
thecorrespondinglightturnsfromredtogreen.Thisdesignaspectissimplyusedto
remindtheuserofthecurrentmode.Therobotspositionisalsousedtogivean
exactlocationsotheuserdoesnthavetoestimateavaluebasedonthemap.
TheExitProgramcallbackstopsrunningprocessesanddeletesthefigure.
Itchangesthehandle.MODEto0whichstopsothermodesfromrunning.Itstops
anddeletestimersthatotherwisewouldcontinueinthebackground.
-
8/8/2019 Colin Lea Mapping and Remote Operation
28/56
28
4.3Modes:
4.3.1Wiimotecontrol
ControllingtheNXTthroughtheWiimotewasoneofmyfirstgoals.Using
Wiilab,itwaseasytoacquiresensordatafromtheWii.Iwantedtobeableto
controltherobotusingbothaccelerometerdata(allowingtheusertotiltthe
controllertomove)andmovebypressingdirectionsonthedpad.Becausethere
aremultipleoptionsthereneedstobeawaytoaccesseachmode.Every0.5seconds
MatlabpollstheWiimoteforbuttondata.
IftheAbuttonispresseditenablesWiiControlMode.Whenthisis
enabled,MatlabrepeatedlypollstheWiimoteforaccelerometerdata.Figuringout
howtobestusetheaccelerometerdatatooklotsoftesting.Manywaysof
manipulatingtheNXTmotorswiththisdatamakesmovementawkwardorunstable.
Forexample,ifyouusetheXaxisaccelerationforturningcontrolandYaxisfor
forward/backwardcontrolsitisnoteasytogostraight.Itishardtokeepyourhand
steadyenoughthatyoudontdrifttotheleftorright.TocounterthisIimplemented
thresholdstotheturningspeeds.IftheXvalueisbelowathresholditisdisregarded
andifitisabovethethresholditaddsthevaluetooneofthemotors.Thethreshold
is6onascaleof019.6(2*Gravity).
Whengoingstraight,thepowerofbothmotorsissettovel_R = vel_L =
Wii.Y_value*y_multiplier.Theymultiplieris4andwassetempirically.Thex
multiplieris2.Therobotslocationonthemapischangedwiththefunction
H.robotX = (H.robotX + v*cosd(H.robotH)*dt) where vistheaveragevelocity
-
8/8/2019 Colin Lea Mapping and Remote Operation
29/56
29
oftheleftandrightmotors, cosdreturnsthecosineofthefunctionindegrees,and
dtisthetimesincethelastfunction.
Whileturningleftthepowerineachmotorisgivenbyvel_L =
(Wii.Y*y_multiplier) + (Wii.X*x_multiplier - 6)) and vel_R =
Wii.Y*y_multiplier.Turningrightisthereverse.
Whileturning,thechangeinangleiscalculatedbydh = atand((vel_R-
vel_L)/width) thisisaddedtothecurrentanglebythefunctionH.robotH =
mod((H.robotH + (dh*dt)), 360).Theuseofmodreducestheangletoavalueof
0359.ThisangleisusedtofindthenewXandYcoordinatesoftherobot.
OneproblemwithWiiControlModepertainstothemappingsystem.
BecausetheNXTcanmoveatanyangleandatanyspeed,therearesometimes
problemswheretheactuallocationoftherobotdriftsfromthemappedlocation.
Figure13GeometryforChangein
Heading
-
8/8/2019 Colin Lea Mapping and Remote Operation
30/56
30
Thisisinpartduetowheelslippageanderrorsvarywiththefloorssurface.Adding
adigitalcompasscouldhelpeliminatepartofthisproblem.
IftheOnebuttonispresseditenablesFineControl.Inthismode,users
canmovetherobotforwardorbackwardorturnitleftorrightusingthedpadon
theWiimote.AswithWiiControlMode,MatlabrepeatedlypollstheWiimotefor
buttonpressesfromalldirectionsonthedpad.WhenpushingUporDownthe
robotmovesadistanceof5centimeters.LeftorRightturnstherobot90degrees
counterclockwiseorclockwise.Thisusesthesameroutinestalkedaboutlaterinthe
FineControlsection.
Regardlessofwhichmodeitsin,MatlabalsopollstheBbutton.TheB
buttonisusedtoexitamode.WhileinWiiControlModeexitingimmediatelystops
theNXT.WhileinFineControlthepreviousactionisfinishedbeforestopping.
4.3.2FineControl:
ThismodeacceptsinputfromtheGUIandWiimote.Itsuseittoaccurately
movetherobotadefineddistance.Bydefault,therobotmoves5cmatatime.This
canbechangedwithasliderontheGUIbutisunchangeableviatheWiimote.
-
8/8/2019 Colin Lea Mapping and Remote Operation
31/56
31
Figure14DistanceSlider
OntheWiimote,thedpadcontrolsarerelative.TheUpbuttoncallsthe
forward()function,Downisbackward(),Leftisturn_Left,andRightis
turn_Right().Forexampleiftherobotisturnedleft,pushingUpwillmoveittothe
leftonthemap.OntheGUI,controlsareabsolute.Eachbuttonrunsitsowncallback
function.Theorientationischeckedandifitisnotfacingthedirectionchosenthenit
turnsleftbeforemovingforward.
% --- Executes on button press in UP.function UP_Callback(hObject, eventdata, handles)
H = guidata(hObject); %handlewhile (H.robotH ~= 90) %if the heading isnt 90 degree turn left
H = turn_Left(H);end
H = forward(H); %move forwardplot(H.Map, H.robotX, H.robotY, 'or') %plot the new location
guidata(hObject, H); %save the handle
Becauseitisnonholonomic(meaningitcanonlymoveinthedirectionthat
-
8/8/2019 Colin Lea Mapping and Remote Operation
32/56
32
itispointed),anytimetherobotmovesadistanceitmustusetheforwardor
backwardfunction.forward()andbackward()getthevaluefromtheDistance
slidertodeterminehowlongtoturnthemotorsonfor.Onmytestingsurfacethe
timefunctionwasdeterminedexperimentallytobetime = .094*distance.The
multipliervariesdependingonthefloorstexture.
4.3.3PointFinding:
InPointFindingmode,theuserinputsapairofXandYcoordinatesand
thentherobotmovestothatlocation.Itusesabasicalgorithmtofindthenewpoint.
Thegeneraloutlineofthealgorithmisasfollows.
while (H.robotY ~= H.yInput) || (H.robotX ~= H.xInput)% ^ while the robot isnt at this location, do the following
%if point is higher than current robot position:if (H.yInput > H.robotY) && H.object_Up == 0
while (H.robotH ~= 90) %while not facing up, turnH = turn_Left(H);
end
H = forward(H); %move forward
%if point is lower than current robot position:elseif (H.yInput < H.robotY)&& H.object_Down == 0
while (H.robotH ~= 270) %while not facing down, turnH = turn_Left(H);
end
H = forward(H);
%if point is more left than current robot position:elseif (H.xInput < H.robotX)&& H.object_Left == 0
while (H.robotH ~= 180)%while not facing left, turn
H = turn_Left(H);endH = forward(H);
%if point is more right than current robot position:elseif (H.xInput > H.robotX)&& H.object_Right == 0
while (H.robotH ~= 0)%while not facing right, turnH = turn_Left(H);
endH = forward(H);
endend
-
8/8/2019 Colin Lea Mapping and Remote Operation
33/56
33
Oneknownproblemisthepossibilitythattherobotcangetcorneredinto
obstacles.Theproblemoccurswhenthereareobjectsonthetwofacesclosesttothe
endpoint.Furtherinvestigationintoabetteralgorithmwouldprovidebetterresults
andfewerproblems.Intheimagebelow,theprogramhascrashedbecausethereis
nowayfortherobottogo.
Figure15PointFindError
-
8/8/2019 Colin Lea Mapping and Remote Operation
34/56
34
4.4ObjectAvoidance:
Avoidanceisimplementedwithafunctionthatisruneverytimetherobot
moves.Itspurposeistopreventtherobotfromrunningintoobstacles.Itchecksa
squareareaequaltotwicethetraveldistanceplusoneinlengthandwidth.By
defaultthisisan11x11centimeterarea;therobotmovesfivespacesatatimeand
5x2+1=11.Thefunctionchecksforanynonzeronumberinthemapsarray.
Becauseonlyobjectsinthewayoftherobotspathneedtobeavoidedthereneedsto
beawaytodifferentiatewhichobjectsmatter.TodothisIaddeddifferentzones
withintheavoidancefunction.Theimagebelowshowsthefourzones.Inthecode,
thezonesarehandle.object_Left, handle.object_Up, handle.object_Right,
and handle.object_Down.Inthisexampleobject_Left, object_Up,and
object_Rightequal1.Wheneverthereisanobstacleanywherewithinthezonethe
valueis1,otherwiseitsvalueis0.
Theavoidancefunctioniscalledbeforeeverymovement.Thecallislocated
intheforward,backward,turn_left,andturn_rightmfiles.Mycontrolsystemis
basedontherobotscurrentheadingwhichcreatedproblems.Initiallyiftherewas
anobstacleabovetherobotandyouweremovingright,thesystemwouldthinkthe
-
8/8/2019 Colin Lea Mapping and Remote Operation
35/56
35
objectwasinyourway.Thesystemwastreatingtheforwardandbackward
commandsasabsolutedirections.TofixthisIusedaswitchinbothoftheroutines.
switchhandle.robotH %robotHistherobotsheadingindegrees
case{0,360}
obj=handle.object_Right;
case90
obj=handle.object_Up;
case180
obj=handle.object_Left;
case270
obj=handle.object_Right;
otherwise
obj=handle.object;
end
Thevariableobjisassignedtothedirectionoftherobot.Thiswaythe
commandisonlycheckingforobjectsinthewayofitspath.
OnethingIwouldliketoseedoneisbetterintegrationwiththepointfinding
function.Currentlytheavoidancefunctioniscalledeverytimetherobotmoves.If
thereareobstaclesinthewayoftherobotspath,itmustavoidthem;thisincreases
thetimeittakestotraveltotheendpoint.Ifavoidancewascalculatedbeforeany
movementthenitcouldchoosetotakeamoreefficientpath.Intheexamplebelow,
thereddottedpathshowsthecurrentpaththerobottakestomovetopoint(60,40).
Thegreenlinedepictsabetterpathusingonly90degreeturns.Theyellowlineis
theoverallmostefficientpath.
-
8/8/2019 Colin Lea Mapping and Remote Operation
36/56
36
Figure16OptimalPath
-
8/8/2019 Colin Lea Mapping and Remote Operation
37/56
37
Chapter5:Internetcontrol
AftercompletingthestructureoftheMatlabprogram,Iponderedtheideaof
controllingtherobotovertheInternet.Ihadlittleexperiencewithweb
developmentsotheenddesigncomesfromasomewhatbasicapproach.Duringthe
process,Ilearnedhowtocreateawebserverhostedonmylaptopandhowtouse
HTMLandPHPtocreatescriptsforaccessingandwritingdatatofilesand
controllinguserinput.
5.1Server
ApacheHTTPServerisanopensource,commercialgradeimplementationof
anHTTPwebserver(http://httpd.apache.org/ABOUT_APACHE.html).Itisfreeand
easytosetupforWindowsandLinux.Itrunsinthebackgroundandallowsanyone
toconnecttofileshostedonmycomputerovertheInternet.
PHPisascriptinglanguageforwebdevelopment.Thesescriptscanbe
executedbybuttonpressesorotherinputsfromawebpage.WithPHPitispossible
-
8/8/2019 Colin Lea Mapping and Remote Operation
38/56
38
towritetofilesonthehostcomputer.Inordertoenablethesescripts,PHPmustbe
installedontheserver.IfollowedthisguideforsettingupApacheandPHP
(http://thecodecentral.com/2007/03/24/settingupyourownwebserverwith
apachehttpserverphpandmysqlonawindowsmachine#change_dir).
5.2Webpage
IwantedtherobottomovewithinputovertheInternet.Iaddedtwo
functions:FineControlandPointFind.UsingHTMLIaddedbuttonsforUp,
Down,Left,Right,aswellasXandYinputsforPointFind.Totherightof
thecontrolsisaprintoutoftheGUIfromMatlab.
-
8/8/2019 Colin Lea Mapping and Remote Operation
39/56
39
Eachofthebuttonsopensupdate.phpandpoststhedirectionorcoordinates
selected.update.phpreadstheactionandrewritestextfileupdate.txtintheservers
directory.Anexampleofoneofthebuttonsisbelow.
TheInternetModebuttonontheMatlabGUIstartsatimerthatchecksthis
fileeverysecond.Theformatofthefileis[U][D][L][R][X][Y][Comment]
[Timestamp].IftheDownbuttonispushedthetextmightread01000000(UP,
DOWN,LEFT,RIGHT|X,YCOORD)1231101682.MatlabwouldthenruntheDown
buttonfunction.Thefunctionsaveas(H.Map, 'C:\...\htdocs\map.jpg') printsa
JPEGimageoftheGUItoafileontheserver.
-
8/8/2019 Colin Lea Mapping and Remote Operation
40/56
40
Refreshingtheimagefortheuserbecameaproblem.Duetotheway
websitescacheimages,theGUIdidntupdateaftereverymovement.Acombination
ofsolutionsprovidedonwebforumsfixedtheissue.IsetJavascripttoruna
functionthatreloadstheimageafter2seconds.Ihadtotrickthepageintothinking
itwasloadingadifferentimagebyappending?r=1totheURLoftheimagewhenit
isfirstloadedand?r=2whenitisreloaded2secondslater.Theletterris
arbitrary.
function reloadPage()
{document.images[0].src="map_old.jpg";document.images[0].src="map.jpg?r=2";}
setTimeout('reloadPage()', 2000);
-
8/8/2019 Colin Lea Mapping and Remote Operation
41/56
41
Chapter6:FinalRemarks/FutureWork
OverthecourseofthisprojectIhavebecomemuchmoreproficientatMatlab
andhaveabetterunderstandingofhowtomixhardwareandsoftwareforremote
operationofarobot.Ithinkithasgivenmesomeofthebasicskillsnecessaryfor
moreadvancedresearch.InthefutureIwouldliketoexpandonthiswork,possibly
implementingthefollowingideas:
AttachaWiimotetotherobot.Thisallowsfordeadreckoning,whichwouldgivemoreaccuratelocationinformation.
ImplementabetteralgorithmintoPointFindmodesotherobotdoesntgetstuckbehindobstacles.
FurtherrefinethewaytherobotmoveswhilecontrollingitwithaWiimote. UseotherNXTsensorstodetectotheractionssuchassound. Obtainadigitalcompass(availablethroughHiTechnic)formoreaccurate
control.
UseanadditionalWiimotetocreatea3Dmappingsystem. Useadditionalrobotstosimulatearobotcollective.
Creatingthissystemhastakenalotofworkbuthasbeenafunexperience
andhassolidifiedmyinterestsinrobotics.Thecombinationofmechanicaland
computerengineeringhaslongintriguedme,butuntilnow,Ihavehadlittle
experiencemixingthetwo.Ilookforwardtodoingmoreworkinthisarea.
-
8/8/2019 Colin Lea Mapping and Remote Operation
42/56
-
8/8/2019 Colin Lea Mapping and Remote Operation
43/56
43
3.1.2ConnectingOSX
ConnectingthroughOSXisrelativelysimplecomparedtoWindows.Before
tryingtoconnect,youmustcloseanypreviousconnectionswiththeNXTthatyou
mighthavewiththatcomputer.Afterclosinganyconnections,youshouldresetthe
NXTbeforetryingtoconnectagain.
ToconnectyoumustfirstopentheBluetoothdeviceswindow,whichcanbe
foundinsystempreferences.ClickSetUpNewDevice
-
8/8/2019 Colin Lea Mapping and Remote Operation
44/56
44
ClickContinueandthenselectAnyDevicewhenaskedwhatdevicetype.Onthe
nextscreenselectNXTandclickcontinue.
OntheNXTitwillaskforapasskey.Itshoulddefaultto1234.Clickthe
orangebuttonforOK.Itwillthenaskforthepasskeyonthecomputer.Ifyouchose
anythingotherthan1234youwillhavetorepeatthepasskeyontheNXT.
ClickcontinueonGatheringmoreinformation.Thenextscreenwillsayit
cannotfindanyinformationaboutthedevice.Thisiscorrect.
YoushouldnowbepairedwiththeNXT.Thisisnotthesamethingasbeing
connected.Atthispointyoucannotcommunicatebetweentheplatforms.
Connectingrequiresonemorestep.IntheBluetoothwindowonyourcomputergo
toEditserialports
-
8/8/2019 Colin Lea Mapping and Remote Operation
45/56
45
Clickthe+toaddaserialout.BydefaultthedeviceserviceshouldbeDevB.
Ifitisnot,changetheservicetype.
-
8/8/2019 Colin Lea Mapping and Remote Operation
46/56
46
TocheckinformationabouttheNXTthereisaprogramcalledNXTBrowser6.
Thisgivesinformationsuchasbatterylifeandfirmwareversionaswellasitallows
youtorunbuiltincommandsontherobot.
IfyougetaLineisBusyerrorontherobotitmeansyoudidnotsetitup
correctlyinOSX.Itmaystillworkintermittentlybutoccasionallyyoumayface
connectionerrors.
3.1.3ConnectingWindowsXP
ConnectingthroughWindowsXPgivesmoreproblemsifyoudontdoit
correctly.Whiletheconnectionmayworktemporarilyevenifyoudontdoitright,it
ismorepronetoflakingout.ToconnectyoumustuseeitherWindowsnative
BluetoothdriversorifyoucompanysupplieddriversifyouhaveaWidcommor
BroadcomBluetoothadapter.
Undermytestsetup(runningWindowsXPthroughVMwareorBootcamp)
connectingcanbetrickyandinconsistent.Thereislittledocumentationonline
aboutusingtheNXTwithVMwareandafterspendingmanyhours,Istillhave
problems.Thereareseveraldifferentmethodsthatwhencombinedwillusually
work.
6http://web.mac.com/carstenm/Lego/NXT/NXT.html
-
8/8/2019 Colin Lea Mapping and Remote Operation
47/56
47
StartbyclosinganyconnectionsinBluetoothDevicesontheNXT,resetting
theNXTandclearinganypreviousNXTBluetoothdevicesfromtheBluetooth
ControlPanelinWindows(whichcanbefoundinthesystemtrayorinthecontrol
panel).
OnWindows,inBluetoothDevicesclickaddundertheDevicespanel.
CheckMydeviceissetupandreadytobefoundandclickNext.
TheNXTshouldshowupasanewdevice.SelectitandclickNext.Ifitisnot
listedmakesuretheNXTisturnedonandclicksearchagain.
-
8/8/2019 Colin Lea Mapping and Remote Operation
48/56
48
Next,selectUsethepasskeyfoundinthedocumentationorLetmechoose
myownpasskey.Eithermethodshouldwork.Enter1234asthepasskey.
-
8/8/2019 Colin Lea Mapping and Remote Operation
49/56
-
8/8/2019 Colin Lea Mapping and Remote Operation
50/56
50
2)InBluetoothDevicesselecttheCOMPortspanel.Thereshouldbetwo
connectionsOnethatisoutgoingandonethatisincoming.
IftheoutgoingismissingthengotoAddatthebottomofthewindow.Select
OutgoingandchangethedevicetoNXTinthedropdownmenu.ChooseDevBand
clickOK
-
8/8/2019 Colin Lea Mapping and Remote Operation
51/56
51
3)GotoBluetoothontheNXTandselectsearch.Youshouldseeyourcomputer
onceitsdonesearching.Selectitandchoseanynumber.ItshouldsayConnecting.
OnceitisdoneitwilleithersayFailed,Lineisbusy,oritwillreturntocomputer
selection.
IfitreturnstothecomputerselectionscreenitmeansthattheNXTis
connected.YoucanchecktheconnectionbygoingbacktoBluetoothontheNXTand
selectingConnections.
IfitsaysFailedresettheNXT,deletetheconnectiononthecomputer,and
tryagain.
IfitsaysLineisbusythenitcanmeanacoupleofthings.Itmayactually
workwiththecomputer.Ifthisisthecaseyoushouldtestusingavailablesoftware.
Ifitdoesntworkthenyouneedtotrysomethingelse.Acombinationoftheother
-
8/8/2019 Colin Lea Mapping and Remote Operation
52/56
52
solutionsmaywork.Inthiscase,theNXTusuallydetectsthecomputerbutis
missingavalidconnection.
TousetheconnectionwithotherprogramsgototheCOMPortspanelin
BluetoothDevicestocheckwhichportisoutgoing.Thisportisneededtosend
commandstotheNXT.
3.1.4Bluetoothremarks
IfyoustillcannotgettheNXTtowork,searchonline.Therearedozensof
webpostsdedicatedtoconnectingtheNXToverBluetooth.Manygounsolvedbut
readingthroughthemmayprovidenewproblemsolvingtechniques.Makesureyou
areusingtherightdriversandhaveacompatibledevice.Ihavefoundcertain
methodswillonlyworksomeofthetime.Accordingtoonlineposts,ifyouhavethe
NXTGsoftwareitissomewhatsimplertosetup.Thissoftwareonlycomeswiththe
consumerNXTset.Itisavailableforabout$50fortheusersoftheEducationalkit.
BluetoothontheNXTisfarfromperfectandasidefromusingitwithLegosown
NXTGdoesnothavethebestsupportfromLego.
Itisworthnotingthatonceyougetaconsistentconnectionyoumaynever
haveproblemsagain.Ikeptthesameconnectionforoveramonthwithno
problems.
-
8/8/2019 Colin Lea Mapping and Remote Operation
53/56
53
AppendixB:InternetOperationCode
nxtControl.php
NXT Control
X:Y:
-
8/8/2019 Colin Lea Mapping and Remote Operation
54/56
54
function reloadPage()
{document.images[0].src="map_old.jpg";document.images[0].src="map.jpg?r=2";}
setTimeout('reloadPage()', 2000);
-
8/8/2019 Colin Lea Mapping and Remote Operation
55/56
55
update.php
Used:update.php?action=Up,update.php?action=Down,update.php?action=Left,
update.php?action=Right,andupdate.php?action=coord&X=x&Y=y
NXT Control
-
8/8/2019 Colin Lea Mapping and Remote Operation
56/56
56
if (strlen($X) == 1) $X = ("0" . $X); //make sure the number has2 digits
if (strlen($X) > 2){$length = strlen($X);$X = $X($length-2) . $X($length-1);}
if (strlen($Y) == 1) $Y = ("0" . $Y);if (strlen($Y) > 2)
{$length = strlen($Y);$Y = $Y($length-2) . $Y($length-1); // /keep digits}
$directions = '0000 ';$coords = $X . ' ' . $Y . ' ';
$comments = '(UP, DOWN, LEFT, RIGHT | X,Y COORD)';$writethis = $directions . $coords . $comments . $time;
}
else{echo "no action data";}
fwrite($file, $writethis);fclose($file);
header("location: nxtControl.php");
?>