Upload
mrinal-kanti-sarkar
View
271
Download
0
Embed Size (px)
DESCRIPTION
help
Citation preview
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 1/26
SearchControlTutorialsEffectsTips
INTRODUCTION CRUISECONTROL MOTORSPEED MOTORPOSITION SUSPENSION
TIPS ABOUT BASICS HARDWARE INDEX NEXT
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 2/26
Introduction:SimulinkControl
RelatedTutorialLinks
Temperature
ControlActivity
Motor Speed
ControlActivity
Simulink
Interaction with
MATLAB
RelatedExternalLinks
Modeling
ChallengesVideo
Contents
Theopenloopplantmodel
ImplementingaPIDcontrollerinSimulink
Runningtheclosedloopmodel
ExtractingamodelintoMATLAB
ControllerdesignwithinSimulink
SYSTEM
MODELING
ANALYSIS
CONTROL
PID
ROOTLOCUS
FREQUENCY
STATESPACE
DIGITAL
SIMULINK
MODELING
CONTROL
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 3/26
Theopenloopplantmodel
In theIntroduction:SimulinkModelingpagewedemonstratedhowSimulink canbeemployed to simulatea
physicalsystem.Moregenerally,Simulinkcanalsosimulatethecompletecontrolsystem,includingthecontrol
algorithminadditiontothephysicalplant.Asmentionedpreviously,Simulinkisespeciallyusefulforgenerating
the approximate solutions ofmathematicalmodels thatmay be prohibitively difficult to solve "by hand." For
example,considerthatyouhaveanonlinearplant.Acommonapproachistogeneratealinearapproximationof
theplantand thenuse the linearizedmodel todesignacontrollerusinganalytical techniques.Simulinkcan
thenbeemployed to simulate the performance of your controller when applied to the full nonlinearmodel.
SimulinkcanbeemployedforgeneratingthelinearizedmodelandMATLABcanbeemployedfordesigningthe
controllerasdescribedintheotherIntroductionpages.VariouscontroldesignfacilitiesofMATLABcanalsobe
accesseddirectlyfromwithinSimulink.Wewilldemonstratebothapproachesinthispage.
Recall the Simulinkmodel of the toy train system derived in the Introduction: SimulinkModeling page and
picturedbelow.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 4/26
Youcangeneratethismodelyourself,oryoucandownloadthecompletedmodelhere.Assumingthatthetrain
onlytravelsinonedimension(alongthetrack),wewanttoapplycontroltothetrainenginesothatitstartsand
comestorestsmoothly,andsothatitcantrackaconstantspeedcommandwithminimalerrorinsteadystate.
ImplementingaPIDcontrollerinSimulink
LetusfirstcreatethestructureforsimulatingthetrainsysteminunityfeedbackwithaPIDcontroller.Inorderto
makeourSimulinkmodelmoreunderstandable,wewillfirstsavethetrainmodelintoitsownsubsystemblock.
Toaccomplishthis,deletethethreescopeblocksandreplaceeachonebyanOut1blockfromtheSinkslibrary.
LabeleachOut1blockwiththecorrespondingvariablename,"x1_dot","x1",and"x2".ThendeletetheSignal
Generator block and replace itwith an In1 block from theSources library. Label this input "F" for the force
generatedbetweenthetrainengineandtherailroadtrack.Yourmodelshouldnowappearasfollows.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 5/26
Nextselectalloftheblocksinyourmodel(CtrlA)andselectCreateSubsystemfromtheEditmenuatthetop
ofthemodelwindow.Withalittlerearrangingandrelabeling,yourmodelwillappearasshownbelow.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 6/26
Nowwecanaddacontrollertooursystem.WewillemployaPIDcontrollerwhichcanbeimplementedusinga
PIDController block from theContinuous library.Placing this block in serieswith the train subsystem, your
modelwillappearasfollows.Inthefollowing,wemodelthecontrollerasgeneratingtheforce"F"directly.This
neglects the dynamics with which the train engine generates the torque applied to the wheels, and
subsequentlyneglectsthedynamicsofhowtheforceisgeneratedatthewheel/trackinterface.Thissimplified
approachistakenatthispointsinceweonlywishtointroducethebasicfunctionalityofSimulinkforcontroller
designandanalysis.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 7/26
DoubleclickingonthePIDControllerblock,wewillinitiallysettheIntegral(I)gainfieldequalto0andwillleave
theProportional(P)andDerivative(D)gainsastheirdefaultsof1and0,respectively.NextaddaSumblock
fromtheMathOperationslibrary.DoubleclickonthisblockandmodifytheListofsignsfieldto"|+".Sincewe
wishtocontrolthevelocityofthetoytrainengine,wewillfeedbacktheengine'svelocity.Thisisaccomplished
by4ringalineoffofthe"x1_dot"signalandconnectingittothenegativesignoftheSumblock.Theoutputofthe
Sum block will be the velocity error for the train engine and should be connected to the input of the PID
Controllerblock.Connectingtheblocksasdescribedandaddinglabels,yourmodelshouldappearasfollows.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 8/26
NextaddaSignalBuilderblockfromtheSourceslibrarytorepresentthevelocitycommandedtothetrain.Since
wewish todesignacontroller tobring the trainsmoothlyup tospeedandsmoothly to rest,wewill test the
systemwithavelocitycommandthatstepsupto1m/sfollowedbyastepbackdownto0m/s(recallthatour
systemisatoytrain).Togeneratethistypeofcommandsignal,doubleclickontheSignalBuilderblock.Then
chooseChangetimerangefromtheAxesmenuatthetopoftheblock'sdialogwindow.SettheMaxtimefield
to"300"seconds.Next,setthestepuptooccurat10secondsandthestepdowntooccurat150seconds.This
isaccomplishedbyclickingonthecorrespondingportionsofthesignalgraph(leftandrightverticallines)and
eitherdraggingthelinetothedesiredposition,orenteringthedesiredtimeintheTfieldatthebottomofthe
window.Whendone,yoursignalshouldappearasfollows.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 9/26
Also add a Scope block from the Sinks library and use it to replace theOut1 block for the train's velocity.
Relabelingtheblocks,yourmodelwillappearasfollows.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 10/26
Wearenowreadytoruntheclosedloopsimulation.Ifyouwishtoskiptheabovesteps,youmaydownloadthe
completedmodelwithcontrolhere.
Runningtheclosedloopmodel
Beforerunningthemodel,weneedtoassignnumericalvaluestoeachofthevariablesusedinthemodel.For
thetrainsystem,wewillemploythefollowingvalues.
=1kg
=0.5kg
=1N/sec
=1N
=0.02sec/m
=9.8m/s^2
Createanewmfileandenterthefollowingcommands.
M1=1;
M2=0.5;
k=1;
F=1;
mu=0.02;
g=9.8;
Execute yourmfile in theMATLABcommandwindow todefine thesevalues.Simulinkwill recognize these
MATLABvariablesforuseinthemodel.Nextweneedtosetthetimeforwhichoursimulationwillruntomatch
thetimerangeofthecommandfromtheSignalBuilderblock.ThisisaccomplishedbyselectingParameters
fromtheSimulationmenuatthetopofthemodelwindowandchangingtheStopTimefieldto"300".Now,run
thesimulationandopenthe"x1_dot"scopetoexaminethevelocityoutput(hitautoscale).Theresultasshown
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 11/26
belowdemonstratesthattheclosedloopsystemisunstableforthiscontroller.
Since the performance achieved above is unsatisfactory, we need to redesign our controller. We will first
demonstrate how to extract a model from Simulink into MATLAB for analysis and design. Then we will
demonstratehowtodesignthecontrolfromdirectlywithinSimulink.
ExtractingamodelintoMATLAB
TheSimulinkControlDesigntoolboxoffersthefunctionalitytoextractamodelfromSimulinkintotheMATLAB
workspace.This is especially useful for complicated, or nonlinear simulationmodels. This is also useful for
generatingdiscretetime(sampled)models.Forthisexample,letusextractacontinoustimemodelofourtrain
subsystem.Firstweneedtoidentifytheinputsandoutputsofthemodelwewishtoextract.Theinputtothetrain
systemistheforce .Wecandesignatethisfactbyrightclickingonthesignalrepresenting"F"(outputofthe
PID block) and choosing Linearization Points > Input Point from the resulting menu. Likewise, we can
designate theoutput of the train systemby rightclickingon the "x1_dot" signal and choosingLinearization
Points>OutputPointfromtheresultingmenu.Theseinputsandoutputswillnowbeindicatedbysmallarrow
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 12/26
Points>OutputPointfromtheresultingmenu.Theseinputsandoutputswillnowbeindicatedbysmallarrow
symbolsasshowninthefollowingfigure.Sincewewishtoextractamodelofthetrainbyitself,withoutcontrol,
weneedto furtherdeletethefeedbacksignal,otherwisewewillextract theclosedloopmodel from to .
Yourmodelshouldnowappearasfollows.
WecannowextractthemodelbyopeningtheLinearAnalysisTool.ThisisaccomplishedbyselectingControl
Design>LinearAnalysisfromundertheToolsmenuatthetopofthemodelwindow.Followingthesestepswill
openthewindowshownbelow.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 13/26
ThistoolgeneratesanLTIobjectfroma(possiblynonlinear)Simulinkmodelandallowsyoutospecifythepoint
aboutwhichthelinearizationisperformed.SinceourSimulinkmodelisalreadylinear,ourchoiceofoperating
pointwillhavenoeffectandwecanleaveitasthedefaultModelInitialCondition.Inordertogeneratethe
linearizedmodel,selecttheLinearizebuttonintheabovefigure,whichisindicatedbythegreentriangle.The
LinearAnalysisToolwindowshouldnowappearasshownbelow.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 14/26
Inspectingtheabove,thestepresponseofthelinearizedmodelwasautomaticallygenerated.Comparingthis
stepresponsetotheonegeneratedbythesimulationoftheopenlooptrainsystemintheIntroduction:Simulink
Modelingpage,youcanseethattheresponsesareidentical.Thismakessensesincethesimulationmodelwas
already linear. Additionally, the linearization process generated the object linsys1 shown in the Linear
AnalysisWorkspaceabove.ThisLTIobjectcanbeexportedforusewithinMATLABbysimplydraggingthe
objectintotheMATLABWorkspacewindow.
Havingextractedthismodel,wecannowemployallofthefacilitiesthatMATLABoffersforcontrollerdesign.For
example,letusemploythefollowingcommandstogenerateandanalyzetheclosedloopsystemreflectingthe
Simulinkmodelcreatedabove.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 15/26
sys_cl=feedback(linsys1,1);
pole(sys_cl)
ans=
1.5261
0.0000
0.0670+1.1977i
0.06701.1977i
Examinationoftheabovedemonstratesthattheclosedloopsysteminitscurrentstatehaspoleswithpositive
realpartand,therefore,isunstable.Thisagreeswiththeresultofourclosedloopsimulationfromabove.We
can thenemployMATLAB todesign a new controller. Instead,wewill demonstrate how to access someof
MATLAB'sfunctionalityfromdirectlywithinSimulink.
ControllerdesignwithinSimulink
Rather than performing the controller design in MATLAB, we can also launch interactive tools to tune our
controllerfromwithinSimulink.OnemannerinwhichthiscanbedoneistodoubleclickonthePIDControllerin
themodelandselecttheTunebuttontolaunchthePIDTunerGUI.Ratherthandothis,will launchthemore
generalSimulinkControlDesignGUIby selectingLinearAnalysis>CompensatorDesign fromunder the
Toolsmenulocatedatthetopofthemodelwindow.FollowingthesestepswillopentheControlandEstimation
ToolsManagerwindowshownbelow.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 16/26
Thefirstthingthatneedstobedoneistoidentifythecontrollerblockthatistobetuned.Thisisaccomplishedby
firstclickingontheSelectBlocksbutton,andthenselectingthePIDControllerblockfromtheresultingwindow
asshownbelow.NextclicktheOKbutton.Notethatcontrollersrepresentedinothertypesofblocks(Transfer
Function,StateSpace,etc.)canalsobetuned.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 17/26
Beforeweproceedtotuneourcontroller,wemustfirstidentifytheinputsandoutputsoftheclosedloopsystem
we wish to analyze. This is done in the same manner we did when extracting a model into MATLAB.
Specifically, rightclick on the velocity command signal (output of the Signal Builder block) and choose
LinearizationPoints > Input Point from the resultingmenu to identify the input of our closedloop system.
Similarly,rightclickonthetrainenginevelocitysignal("x1_dot")andselectLinearizationPoints>OutputPoint
fromthemenutochoosetheoutputofoursystem.Yourmodelshouldnowappearasfollowswherethesmall
arrowsymbolsidentifytheinputandoutputofthemodel.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 18/26
Nowthatwehaveidentifiedtheblocktotuneandour inputandoutputsignals,wecannowcommencewith
tuning thecontroller.Select theTuneBlocksbutton in theControlandEstimationToolsManagerwindow.
ThiswillopentheDesignConfigurationWindowshownbelowwhichprovidessome introductiononhow to
employtheinteractivedesigntool.Inessence,thisGUIistheSISODesignTool that isavailable fromwithin
MATLABaswell.
ClickingtheNextbutton,wewillchoosethedesignplotswewishtoemployfordesigningourcontroller.Inthis
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 19/26
example,wewillemployarootlocusdesignapproachandhencewillchooseaPlotTypeofRootLocus for
Plot1asshownbelow.Sincetherootlocusapproachtodesignemploysaplotfromtheopenloopsystemfor
placingtheclosedlooppoles,wewillleavethechoiceofOpen/ClosedLoopsasOpenLoop1(thisisouronly
choice!).
ClickingtheNextbuttonagainwill allowus tochooseouranalysisplots.Weuse thestep responseplot to
assesshowwellweareabletomeetourgoalofbringingthetrainuptospeedsmoothlywithminimalsteady
stateerrortoaconstantspeedcommand.Therefore,wewillchooseaPlotTypeofStepfromthedropdown
menuunderPlot1asshownbelow.WewillalsoselectPlot1underthePlotContentsportionofthewindowfor
theonlysystemthatisdefined.Thereisonlyonesystemavailablebecausewehavedefinedonlyasingleinput
andsingleoutputforoursystem.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 20/26
SelectingtheNextButtonwillthenopentheSISODesignToolwitharootlocusplotandastepresponseplot.
Therootlocusplotshownbelowdisplaystheclosedlooppolelocationsofthetrainsystemplantundersimple
proportionalcontrol.Examiningtheplot,onecanseethatmanyvaluesofloopgainwillplaceclosedlooppoles
intherighthalfplaneleadingtoanunstableresponse.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 21/26
Ifwedecreasetheloopgainsufficiently,wecanmovetheclosedlooppolesintothelefthalfplaneandwecan
stabilizeoursystem.Thiscanbeaccomplishedgraphicallyby"grabbing"thepinkboxesmarkingtheclosed
looppole locationsanddragging them toward theopenlooppole locations (markedbyx's).A loopgainof
approximately 0.1will stabilize the system. Examining the corresponding step response,whichwill change
automaticallyinresponsetothegainchangeiftheRealTimeUpdateboxischeckedintheLTIViewerwindow,
youcanseethatwhiletheresponseisstableitssteadystateerrorisquitelarge.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 22/26
(1)
Recallthataddingintegralcontrolisonewaytoreducethesteadystateerrorforasystem.Inthiscase,adding
anintegratorviathecontrollerwillmakethesystemtype1,wheretype1systemscantrackstepreferenceswith
zerosteadystateerror.RecallthefollowingformofaPIcontroller.
Therefore, aPI controllerwill add an integrator anda zero to our openloop system.The integrator can be
addedtothesystembyrightclickinginthefieldoftherootlocusplotandselectingAddPole/Zero>Integrator
fromtheresultingmenu.Similarly,thezerocanbeaddedbyrightclickingontherootlocusplotandselecting
AddPole/Zero>Realzerofromtheresultingmenu.Thenclickwherealongtherealaxisyouwishtoplacethe
zero.Wewillplacethezerojusttotherightoftheplantpoleontherealaxis.Youcanmovethezerobyclicking
onitanddraggingittoanewlocation.Onceyouhaveplacedthezero,thengrabthepinkboxesrepresenting
theclosedlooppolesandattempt to line the threedominantpolesupso that theyhave thesamerealpart.
Therealsowillbearealclosedlooppoletotheleftthatis"faster"thantherest,andaclosedlooppoleatthe
originthatiscancelledbyaclosedloopzeroattheorigin.Theresultingrootlocusplotisshownbelow.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 23/26
Thecompensatorcanalsobeeditedbydirectlytypinginpoleandzerolocations.Thiscanbedonebychoosing
EditCompensatorfromtheDesignmenulocatedatthetopoftheSISODesignTaskwindow.Thewindowthat
opensisshownbelow.Wewillmorepreciselyplacethezeroat0.15andwillchoosealoopgainequalto0.01.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 24/26
Theresultingclosedloopstepresponseplotisshownbelowdemonstratingthatthetrainengineisbroughtto
speedsmoothlyandwithzerosteadystateerrorforaconstantspeedcommand.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 25/26
Thecontrolgains thathavebeenchosencan thenbeapplied to theSimulinkmodelbyclicking theUpdate
SimulinkBlockParametersbuttonundertheCompensatorEditor tabof theControlandEstimationTools
Managerwindow(seeabove).Thesimulationcanthenberunwiththisnewlytunedcontroller.Clickingonthe
Scopeblockforthetrainengine'svelocityandselectingautoscalewillproduceaplotliketheoneshownbelow.
20/01/2016 ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SimulinkControl 26/26
Overall this responseseems tomeetourgoalsofbringing the trainup tospeedand to restsmoothly,while
maintainingminimalsteadystateerror.ThisresponsematchestheresultgeneratedwiththeSISODesignTool
abovebecausethatanalysisandtheSimulinkmodelusedtheexactsamelinearmodel.
PublishedwithMATLAB7.14
AllcontentslicensedunderaCreativeCommonsAttributionShareAlike4.0InternationalLicense.