Professional Documents
Culture Documents
TableofContents
1 Objective 1.1 Credits 1.2 GeneralComment(s) TestingyourMotorswithMATLAB 2.2.1 SetuptheGyroforMATLAB 2.3 Step3:Uploadthesrv_gyro.pdeServer 2.3.1 HowitWorks 2.4 Step4:Addarduino.mtoMATLABPath 2.4.1 HowitWorks 2.5 Step5:InstantiatetheMATLABArduinoClass 2.5.1 FindingtheSerialPort 2.6 Step6MatlabMotorLab UsingtheMATLABGUI 3.1 Help LabDeliverable(s) FutureWork
3 4 5
Objective
InthislabyouwillimplementaMATLABGUItocontrolyourDCmotorsandthestepper motor.Specifically,youwillcreateacontrolpanelwithtwoslidersandbuttons.Asyou increase(moveup)theslidersyouwillbeabletoseethespeedofyourDCmotors increase.Youwillalsobeabletocontrolthesteppermotorwithpushbuttonsforleftand rightpanning.Thesesimplecontrolsallowyoutomanuallytestthemotorsofyourrover andhavealittlefundrivingitaround. Forthislabyouwillneedthefollowingmaterials: AssembledRoverfromBuild Instructions USBCable MATLABSoftware Version2008orhigher
1.1
Credits
ThislabwasoriginallywrittenbyJuanCadenaandElizabethSandoval(Veterans)during theFall2011semester.Additionalcontributor'sincludeKevinNguyen(GyroneersS11)and
NicFlenghi(RangeRoverF11).Thislatestrevisionreflectsthecommentsprovidedbythe Spring2011class.
1.2
GeneralComment(s)
Whenindoubt,closeeverythingandunplugeverythingtostartfromsquareone.
TestingyourMotorswithMATLAB
InstructionalVideo http://www.mathworks.com/company/events/webinars/wbnr43537.html 2
2.1 2.2
Step1:CheckSoftwareVersion Step2:DownloadFiles
TocompletethislabyoumusthaveMATLAB2008orhigher.
For the s r v . p d e sketch to compile correctly, the Adafruit Motor Shield library must first be installed.DownloadthelibraryfromAdafruit,
Extract the files, and place them in a new folder (AFMotor) in the Arduino libraries folder (usually: My Documents\Arduino\libraries\AFMotor), as per the instructions at LadyAda.Youcan findthe
The MATLAB support packageis required for serial communications with the Arduino,which is availableatMathWorkswebsite(usetheblueDownloadAllbuttonatthetopright).
2.2.1 SetuptheGyroforMATLAB
For the s r v _ g y r o . p d e sketch to compile correctly, thePololu L3G4200Dlibrarymustfirstbe installed.DownloadthelibraryfromPololu.
NOTE:Makesuretodownloadeveryfile,notjustthe.hfiles,tothelibraryfolderfromthe abovelinks.
DownloadandExtractthefilesintheG y r o _ m a t l a b _ c o d e . z i p filesincludedinthisfolder.The extractedfoldershouldincludethefollowingfiles. 1. s r v _ g y r o . p d e 2. i n s t a l l _ a r d u i n o . m 3. a r d u i n o . m 4. g y r o _ t e s t . m Note:Whilesomeofthefilesnamesinthefilesdownloadedhavethesamenamesasthose foundatMathworksNichasmodifiedthemforourclass.
2.3
Step3:Uploadthes r v _ g y r o . p d e Server
IfyouhaveneveruploadedanArduinosketch(i.e.,program),Iwouldhighlyrecommendyou completetheLesson1:Lettherebeblink!ArduinoTutorialfoundhere. Uploads r v _ g y r o . p d e (ors r v . p d e ifyouskippedstep2.1.1)toyourArduino.TheAdafruit motorlibraryandPololuL3G4200(s r v _ g y r o . p d e o n l y )mustbeinstalledforthistocompile. Thes r v _ g y r o . p d e programcontainsallofthecommandsnecessarytorunthemotors, read/writetoports,andreadfromourgyro.ThisArduinoprogramactsasaservertointerface withMATLAB.
2.3.1 HowitWorks
MATLAB(ortheserialmonitorintheArduinoIDE)sendsanalphanumericcodetoindicatewhich
2.4
Step4:Adda r d u i n o . m toMATLABPath
2.4.1 HowitWorks
Thea r d u i n o . m filetakescareofsendingandreceivingcommandsanddatafromtheArduino server(s r v _ g y r o . p d e ).ItalsogivesusacollectionofMATLABfunctionstouseinsteadof manuallyenteringthealphanumericcodes.Forexample,a . g y r o R e a d ( z ) sendsthecode G z overtheserialinterfaceandlistensforthevaluesentbackfromtheboard. Ifyouarerunningsrv_gyro.pdemakesuretousethearduino.mfiledownloadedwiththis software.
2.5
Step5:InstantiatetheMATLABArduinoClass
Note:TheMATLABMotorServerfoldermustbeopenwhenperformingcommandssuchas instantiatingtheArduino(Figure7).
2.5.1 FindingtheSerialPort
5
2.6
Step6MatlabMotorLab
OpenMATLABandrunthea r d u i n o . m file.
Youshouldgetthefollowingwindowoncearduino.mfileisrun
D i g i t a l P i n 0 2 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 0 3 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 0 4 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 0 5 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 0 6 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 0 7 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 0 8 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 0 9 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 0 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 1 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 2 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 3 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 4 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 5 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 6 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 7 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 8 i s c u r r e n t l y U N A S S I G N E D D i g i t a l P i n 1 9 i s c u r r e n t l y U N A S S I G N E D P i n I O M e t h o d s : p i n M o d e d i g i t a l R e a d d i g i t a l W r i t e a n a l o g R e a d a n a l o g W r i t e
ClickonmotorRunforMatlabcodingexamples.
LetstakeacloserlookattheinstanceandargumentsofmotorRun.
a . m o t o r R u n ( n u m , d i r ) r u n s a g i v e n D C m o t o r .
AddthefollowinglinesofcodetomakesureyouhavecommunicationandthatMatlabis workingproperly.
E D U > > a . m o t o r S p e e d ( 1 , 1 0 0 )
UsingtheMATLABGUI
executingthesteppermovingrightorleft
% h a n d l e s s t r u c t u r e w i t h h a n d l e s a n d u s e r d a t a ( s e e G U I D A T A ) h a n d l e s . a . s t e p p e r S p e e d ( 2 , 5 0 ) h a n d l e s . a . s t e p p e r S t e p ( 2 , ' f o r w a r d ' , ' i n t e r l e a v e ' , 1 0 )
3.1
Help
LabDeliverable(s)
1. Demonstratetheoperationofyourrover 2. Findandrecordinyourlabnotebooksthestallspeedofyourrover
FutureWork
11