Servo Control - MATLAB & Simulink Example PDF
Servo Control - MATLAB & Simulink Example PDF
a2560_servocontrol_sweep
rArduinoMega2560andcanberunonanyoftheboradlistedinthe"Supported
getHardware"parameterintheconfigurationparametersofthemodelas
ardwareenablesyoutocreateandrunSimulinkmodelsonArduinoboard.The
ksforconfiguringandaccessingArduinosensors,actuatorsandcommunication
ateSimulinkmodelthatcontrolsastandardservomotor.Inastandardservo
yset,usuallybetween0and180degrees.Servomotorsareusedinmany
tionsandproducts.
tedwithArduinoHardwareexample.
lowinghardware:
ortedArduinoHardware
boardisnotArduinoMega2560hardware.
forthesupportedArduinoboard.
RunonTargetHardware>Options....
pageopensup,settheTargethardwareparametertoyourrequiredArduino
eArduinoBoard
otheArduinoboard.Servomotorshavethreewires:power,ground,andsignal.
tothe5Vpin.
ck)tothegroundpin.
ge)todigitalpin4.RefertoPinMappingonArduinoBlocksinthedocumentation
viaanInternalSource
servomotorshaftusinganinternalsource.Theshaftanglewillvarybetween0
ck.Theblocksetsthenewangleoftheservomotorshaftevery0.01second.
RunonTargetHardware>Options.
pageopensup,settheTargethardwareparametertosupportedArduino
mputer.Donotchangeanyothersettings.
oyToHardwarebuttononthetoolbar.
Arduinoboard,observethemotorshaftpositionsweepingbetween0and180
ionviaaPotentiometer
servomotorshaftmanually,usingapotentiometer.Connecttheouter
pinsonyourArduinoboard.Connectthemiddleterminaltoanaloginputpin0.As
ncechanges.Asaresult,thevoltageattheanaloginputpinchangesaswell.Your
ortionaltothisvoltage.
SimulinkModel.
pt.ThisopenstheSimulinkLibraryBrowser.
SimulinkSupportPackageforArduinoHardware>Common.
model.DoubleclicktheblockandsetthePinnumberto0,andtheSampletimeto
intothemodel.DoubleclicktheblockandsetthePinnumberto4.
ndardServoWriteblocks.
y,dragtheGainblockintothemodelanddropitonthelineconnectingtheAnalog
ck.DoubleclicktheGainblockandsetitsvalueto0.1760(maximumservomotor
loginputdigitalresolutioni.e.180/1023).
RunonTargetHardware>PrepareToRun....
pageopensup,settheTargethardwareparametertosupportedArduino
ployToHardwarebuttononthetoolbar.Themodelwillnowbedeployedtothe
duinoboard,observethemotorshaftsweepingbetween0and180degrees.
sdescribedabove,youcanusetheServoControlmodel.
ionviaaPhotocell
etsthepositionoftheservomotoraccordingtolightintensitydetectedbya
shouldbepositionedat0degrees,whileinabrightroomitshouldbepositioned
thepotentiometeryouusedinTask4.Connectoneendofthephotocelltothe5V
oneendoftheresistortotheGNDpinontheboard.Connecttheotherendsofthe
hentotheanaloginputpin0ontheboard.
CONTENTS
Close
dinTask4.
inoblocklibrary.Forexample:
motorshaftpositiondependingontheexternalcontrolsignalorsignals.
readthemotorshaftpositionandcompareitwiththedesiredposition.
mulinkSupportPackageforArduinoHardwaretocontrolastandardservomotor.
outosettheservomotorshaftposition,usuallyintherangefrom0to180degrees.
tageappliedtoanArduinoanaloginputpin.Varietyofsensorscanbeattachedto