Вы находитесь на странице: 1из 18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

Tips
TIPS

ABOUT

Effects

BASICS

SearchControlTutorials

HARDWARE

INDEX

NEXT

INTRODUCTION CRUISECONTROL MOTORSPEED

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

1/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl
SYSTEM
MODELING
ANALYSIS

Introduction:Simulink
Control

CONTROL

Related
TutorialLinks

PID
ROOTLOCUS

Temperature
Control

FREQUENCY

Activity

STATESPACE

Motor
DIGITAL

Speed
Control
Activity

SIMULINK

Simulink

MODELING

Interaction

CONTROL

with
MATLAB

Related
External
Links
Modeling
Challenges
Video

Contents
Theopenloopplantmodel
ImplementingaPIDcontrollerinSimulink
Runningtheclosedloopmodel
ExtractingamodelintoMATLAB
ControllerdesignwithinSimulink

Theopenloopplantmodel
In the Introduction: Simulink Modeling page we demonstrated how Simulink
canbeemployedtosimulateaphysicalsystem.Moregenerally,Simulinkcan
alsosimulatethe complete control system, including the control algorithm in
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

2/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

alsosimulatethe complete control system, including the control algorithm in


additiontothephysicalplant.Asmentionedpreviously,Simulinkisespecially
useful for generating the approximate solutions of mathematical models that
maybeprohibitivelydifficulttosolve"byhand."Forexample,considerthatyou
have a nonlinear plant. A common approach is to generate a linear
approximation of the plant and then use the linearized model to design a
controller using analytical techniques. Simulink can then be employed to
simulatetheperformanceofyourcontrollerwhenappliedtothefullnonlinear
model. Simulink can be employed for generating the linearized model and
MATLAB can be employed for designing the controller as described in the
otherIntroductionpages.VariouscontroldesignfacilitiesofMATLABcanalso
be accessed directly from within Simulink. We will demonstrate both
approachesinthispage.
RecalltheSimulinkmodelofthetoytrainsystemderivedintheIntroduction:
SimulinkModelingpageandpicturedbelow.

You can generate this model yourself, or you can download the completed
modelhere.Assumingthatthetrainonlytravelsinonedimension(alongthe
track),wewanttoapplycontroltothetrainenginesothatitstartsandcomesto
restsmoothly,andsothatitcantrackaconstantspeedcommandwithminimal
errorinsteadystate.

ImplementingaPIDcontrollerinSimulink
Letusfirstcreatethestructureforsimulatingthetrainsysteminunityfeedback
with a PID controller. In order to make our Simulink model more
understandable,wewillfirstsavethetrainmodelintoitsownsubsystemblock.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

3/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

understandable,wewillfirstsavethetrainmodelintoitsownsubsystemblock.
Toaccomplishthis,deletethethreescopeblocksandreplaceeachonebyan
Out1 block from the Sinks library. Label each Out1 block with the
correspondingvariablename,"x1_dot","x1",and"x2".ThendeletetheSignal
Generator block and replace it with an In1 block from the Sources library.
Labelthisinput"F"fortheforcegeneratedbetweenthetrainengineandthe
railroadtrack.Yourmodelshouldnowappearasfollows.

Next select all of the blocks in your model (Ctrl A) and select Create
SubsystemfromtheEdit menu at the top of the model window. With a little
rearrangingandrelabeling,yourmodelwillappearasshownbelow.

Nowwecanaddacontrollertooursystem.WewillemployaPIDcontroller

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

4/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

Nowwecanaddacontrollertooursystem.WewillemployaPIDcontroller
whichcanbeimplementedusingaPIDControllerblockfromtheContinuous
library. Placing this block in series with the train subsystem, your model will
appearasfollows.Inthefollowing,wemodelthecontrollerasgeneratingthe
force "F" directly. This neglects the dynamics with which the train engine
generates the torque applied to the wheels, and subsequently neglects the
dynamics of how the force is generated at the wheel/track interface. This
simplifiedapproachistakenatthispointsinceweonlywishtointroducethe
basicfunctionalityofSimulinkforcontrollerdesignandanalysis.

DoubleclickingonthePIDControllerblock,wewillinitiallysettheIntegral(I)
gain field equal to 0 and will leave the Proportional (P) and Derivative (D)
gainsastheirdefaultsof1and0,respectively.NextaddaSumblockfromthe
Math Operations library. Doubleclick on this block and modify the List of
signsfieldto"|+".Sincewewishtocontrolthevelocityofthetoytrainengine,
wewillfeedbacktheengine'svelocity.Thisisaccomplishedby4ringalineoff
ofthe"x1_dot"signalandconnectingittothenegativesignoftheSumblock.
TheoutputoftheSumblockwillbethevelocityerrorforthetrainengineand
shouldbeconnectedtotheinputofthePIDControllerblock.Connectingthe
blocksasdescribedandaddinglabels,yourmodelshouldappearasfollows.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

5/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

Next add a Signal Builder block from the Sources library to represent the
velocitycommandedtothetrain.Sincewewishtodesignacontrollertobring
thetrainsmoothlyuptospeedandsmoothlytorest,wewilltestthesystemwith
avelocitycommandthatstepsupto1m/sfollowedbyastepbackdownto0
m/s (recall that our system is a toy train). To generate this type of command
signal, doubleclick on the Signal Builder block. Then choose Change time
rangefromtheAxesmenuatthetopoftheblock'sdialogwindow.SettheMax
timefieldto"300"seconds.Next,setthestepuptooccurat10secondsand
thestepdowntooccurat150seconds.Thisisaccomplishedbyclickingonthe
corresponding portions of the signal graph (left and right vertical lines) and
eitherdraggingthelinetothedesiredposition,orenteringthedesiredtimein
theTfieldatthebottomofthewindow.Whendone,yoursignalshouldappear
asfollows.

AlsoaddaScopeblockfromtheSinkslibraryanduseittoreplacetheOut1
blockforthetrain'svelocity.Relabelingtheblocks,yourmodelwillappearas
follows.
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

6/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

follows.

We are now ready to run the closedloop simulation. If you wish to skip the
abovesteps,youmaydownloadthecompletedmodelwithcontrolhere.

Runningtheclosedloopmodel
Beforerunningthemodel,weneedtoassignnumericalvaluestoeachofthe
variablesusedinthemodel.Forthetrainsystem,wewillemploythefollowing
values.
=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;

ExecuteyourmfileintheMATLABcommandwindowtodefinethesevalues.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

7/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

ExecuteyourmfileintheMATLABcommandwindowtodefinethesevalues.
SimulinkwillrecognizetheseMATLABvariablesforuseinthemodel.Nextwe
needtosetthetimeforwhichoursimulationwillruntomatchthetimerangeof
thecommandfromtheSignalBuilderblock.Thisisaccomplishedbyselecting
Parameters from the Simulation menu at the top of the model window and
changingtheStopTimefieldto"300".Now,runthesimulationandopenthe
"x1_dot" scope to examine the velocity output (hit autoscale). The result as
shown below demonstrates that the closedloop system is unstable for this
controller.

Sincetheperformanceachievedaboveisunsatisfactory,weneedtoredesign
ourcontroller.WewillfirstdemonstratehowtoextractamodelfromSimulink
intoMATLABforanalysisanddesign.Thenwewilldemonstratehowtodesign
thecontrolfromdirectlywithinSimulink.

ExtractingamodelintoMATLAB
TheSimulinkControlDesigntoolboxoffersthefunctionalitytoextractamodel
from Simulink into the MATLAB workspace. This is especially useful for
complicated,ornonlinearsimulationmodels.Thisisalsousefulforgenerating
discretetime(sampled)models.Forthisexample,letusextractacontinous
time model of our train subsystem. First we need to identify the inputs and
outputs of the model we wish to extract. The input to the train system is the
force .Wecandesignatethisfactbyrightclickingonthesignalrepresenting
"F"(outputofthePIDblock)andchoosingLinearizationPoints>InputPoint
from the resulting menu. Likewise, we can designate the output of the train
system by rightclicking on the "x1_dot" signal and choosing Linearization
Points>OutputPointfromtheresultingmenu.Theseinputsandoutputswill
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

8/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

now be indicated by small arrow symbols as shown in the following figure.


Sincewewishtoextractamodelofthetrainbyitself,withoutcontrol,weneed
tofurtherdeletethefeedbacksignal,otherwisewewillextracttheclosedloop
modelfrom to .Yourmodelshouldnowappearasfollows.

WecannowextractthemodelbyopeningtheLinearAnalysisTool. This is
accomplishedbyselectingControlDesign>LinearAnalysisfromunderthe
Toolsmenuatthetopofthemodelwindow.Followingthesestepswillopen
thewindowshownbelow.

ThistoolgeneratesanLTIobjectfroma(possiblynonlinear)Simulinkmodel
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

9/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

andallowsyoutospecifythepointaboutwhichthelinearizationisperformed.
SinceourSimulinkmodelisalreadylinear,ourchoiceofoperatingpointwill
havenoeffectandwecanleaveitasthedefaultModelInitialCondition.
In order to generate the linearized model, select the Linearize button in the
above figure, which is indicated by the green triangle. The Linear Analysis
Toolwindowshouldnowappearasshownbelow.

Inspecting the above, the step response of the linearized model was
automaticallygenerated.Comparingthisstepresponsetotheonegenerated
by the simulation of the openloop train system in the Introduction: Simulink
Modeling page, you can see that the responses are identical. This makes
sense since the simulation model was already linear. Additionally, the
linearization process generated the object linsys1 shown in the Linear
AnalysisWorkspace above. This LTI object can be exported for use within
MATLABbysimplydraggingtheobjectintotheMATLABWorkspacewindow.
Having extracted this model, we can now employ all of the facilities that
MATLABoffersforcontrollerdesign.Forexample,letusemploythefollowing
commands to generate and analyze the closedloop system reflecting the
Simulinkmodelcreatedabove.

sys_cl=feedback(linsys1,1);
pole(sys_cl)

ans=

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

10/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

ans=

1.5261
0.0000
0.0670+1.1977i
0.06701.1977i

Examination of the above demonstrates that the closedloop system in its


currentstatehaspoleswithpositiverealpartand,therefore,isunstable.This
agreeswiththeresultofourclosedloopsimulationfromabove.Wecanthen
employMATLABtodesignanewcontroller.Instead,wewilldemonstratehow
toaccesssomeofMATLAB'sfunctionalityfromdirectlywithinSimulink.

ControllerdesignwithinSimulink
RatherthanperformingthecontrollerdesigninMATLAB,wecanalsolaunch
interactive tools to tune our controller from within Simulink. One manner in
whichthiscanbedoneistodoubleclickonthePIDControllerinthemodel
andselecttheTunebuttontolaunchthePIDTunerGUI.Ratherthandothis,
willlaunchthemoregeneralSimulinkControlDesignGUIbyselectingLinear
Analysis>CompensatorDesignfromundertheToolsmenulocatedatthe
top of the model window. Following these steps will open the Control and
EstimationToolsManagerwindowshownbelow.

Thefirstthingthatneedstobedoneistoidentifythecontrollerblockthatisto

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

11/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

Thefirstthingthatneedstobedoneistoidentifythecontrollerblockthatisto
betuned.ThisisaccomplishedbyfirstclickingontheSelect Blocks button,
and then selecting the PID Controller block from the resulting window as
shown below. Next click the OK button. Note that controllers represented in
othertypesofblocks(TransferFunction,StateSpace,etc.)canalsobetuned.

Beforeweproceedtotuneourcontroller,wemustfirstidentifytheinputsand
outputsoftheclosedloopsystemwewishtoanalyze.Thisisdoneinthesame
mannerwedidwhenextractingamodelintoMATLAB.Specifically,rightclick
on the velocity command signal (output of the Signal Builder block) and
chooseLinearizationPoints>InputPointfromtheresultingmenutoidentify
the input of our closedloop system. Similarly, rightclick on the train engine
velocitysignal("x1_dot")andselectLinearizationPoints>OutputPointfrom
themenutochoosetheoutputofoursystem.Yourmodelshouldnowappear
asfollowswherethesmallarrowsymbolsidentifytheinputandoutputofthe
model.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

12/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

Nowthatwehaveidentifiedtheblocktotuneandourinputandoutputsignals,
we can now commence with tuning the controller. Select the Tune Blocks
buttonintheControlandEstimationToolsManagerwindow.Thiswillopen
the Design Configuration Window shown below which provides some
introductiononhowtoemploytheinteractivedesigntool.Inessence,thisGUI
istheSISODesignToolthatisavailablefromwithinMATLABaswell.

ClickingtheNextbutton,wewillchoosethedesignplotswewishtoemployfor
designingourcontroller.Inthisexample,wewillemployarootlocusdesign
approach and hence will choose a Plot Type of Root Locus for Plot 1 as
shownbelow.Sincetherootlocusapproachtodesignemploysaplotfromthe
openloopsystemforplacingtheclosedlooppoles,wewillleavethechoiceof
Open/ClosedLoopsasOpenLoop1(thisisouronlychoice!).

ClickingtheNextbuttonagainwillallowustochooseouranalysisplots.We
usethestepresponseplottoassesshowwellweareabletomeetourgoalof
bringing the train up to speed smoothly with minimal steadystate error to a
constantspeedcommand.Therefore,wewillchooseaPlotTypeofStepfrom
thedropdownmenuunderPlot1asshownbelow.WewillalsoselectPlot1
under the Plot Contents portion of the window for the only system that is
defined.Thereisonlyonesystemavailablebecausewehavedefinedonlya
singleinputandsingleoutputforoursystem.
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

13/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

SelectingtheNext Button will then open the SISO Design Tool with a root
locusplotandastepresponseplot.Therootlocusplotshownbelowdisplays
the closedloop pole locations of the train system plant under simple
proportionalcontrol.Examiningtheplot,onecanseethatmanyvaluesofloop
gainwillplaceclosedlooppolesintherighthalfplaneleadingtoanunstable
response.

Ifwedecreasetheloopgainsufficiently,wecanmovetheclosedlooppoles
into the lefthalf plane and we can stabilize our system. This can be
accomplished graphically by "grabbing" the pink boxes marking the closed
loop pole locations and dragging them toward the openloop pole locations
(marked by x's). A loop gain of approximately 0.1 will stabilize the system.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

14/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

(marked by x's). A loop gain of approximately 0.1 will stabilize the system.
Examiningthecorrespondingstepresponse,whichwillchangeautomatically
inresponsetothegainchangeiftheRealTimeUpdateboxischeckedinthe
LTIViewerwindow,youcanseethatwhiletheresponseisstableitssteady
stateerrorisquitelarge.

Recallthataddingintegralcontrolisonewaytoreducethesteadystateerror
forasystem.Inthiscase,addinganintegratorviathecontrollerwillmakethe
system type 1, where type 1 systems can track step references with zero
steadystateerror.RecallthefollowingformofaPIcontroller.
(1)

Therefore, a PI controller will add an integrator and a zero to our openloop


system.Theintegratorcanbeaddedtothesystembyrightclickinginthefield
of the root locus plot and selecting Add Pole/Zero > Integrator from the
resultingmenu.Similarly,thezerocanbeaddedbyrightclickingontheroot
locusplotandselectingAddPole/Zero>Realzerofromtheresultingmenu.
Thenclickwherealongtherealaxisyouwishtoplacethezero.Wewillplace
thezerojusttotherightoftheplantpoleontherealaxis.Youcanmovethe
zerobyclickingonitanddraggingittoanewlocation.Onceyouhaveplaced
the zero, then grab the pink boxes representing the closedloop poles and
attempttolinethethreedominantpoles up so that they have the same real
part.Therealsowillbearealclosedlooppoletotheleftthatis"faster"thanthe
rest, and a closedloop pole at the origin that is cancelled by a closedloop
http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

15/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

rest, and a closedloop pole at the origin that is cancelled by a closedloop


zeroattheorigin.Theresultingrootlocusplotisshownbelow.

The compensator can also be edited by directly typing in pole and zero
locations.ThiscanbedonebychoosingEditCompensatorfromtheDesign
menu located at the top of the SISODesignTask window. The window that
opensisshownbelow.Wewillmorepreciselyplacethezeroat0.15andwill
choosealoopgainequalto0.01.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

16/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

The resulting closedloop step response plot is shown below demonstrating


thatthetrainengineisbroughttospeedsmoothlyandwithzerosteadystate
errorforaconstantspeedcommand.

ThecontrolgainsthathavebeenchosencanthenbeappliedtotheSimulink
modelbyclickingtheUpdate Simulink Block Parameters button under the
Compensator Editor tab of the Control and Estimation Tools Manager
window (see above). The simulation can then be run with this newly tuned
controller. Clicking on the Scope block for the train engine's velocity and
selectingautoscalewillproduceaplotliketheoneshownbelow.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

17/18

11/15/2016

ControlTutorialsforMATLABandSimulinkIntroduction:SimulinkControl

Overallthisresponseseemstomeetourgoalsofbringingthetrainuptospeed
and to rest smoothly, while maintaining minimal steadystate error. This
response matches the result generated with the SISO Design Tool above
because that analysis and the Simulink model used the exact same linear
model.

PublishedwithMATLAB7.14

AllcontentslicensedunderaCreativeCommonsAttributionShareAlike4.0
InternationalLicense.

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=SimulinkControl#8

18/18

Вам также может понравиться