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

20/01/2016

Tips
TIPS

Effects

BASICS

SearchControlTutorials

HARDWARE

INDEX

NEXT

INTRODUCTION CRUISECONTROL MOTORSPEED MOTORPOSITION SUSPENSION

1/26

20/01/2016

SYSTEM
MODELING

ANALYSIS

RelatedTutorial

CONTROL
PID

Temperature
ControlActivity

ROOTLOCUS

Motor

FREQUENCY

Speed

ControlActivity
STATESPACE

Interaction

DIGITAL

with

MATLAB

RelatedExternal

MODELING

Modeling
CONTROL

ChallengesVideo

Contents
Theopenloopplantmodel
Runningtheclosedloopmodel
ExtractingamodelintoMATLAB

2/26

20/01/2016

Theopenloopplantmodel
IntheIntroduction:SimulinkModeling page we demonstrated how Simulink can be employed to simulate a
the approximate solutions of mathematical models that may be prohibitively difficult to solve "by hand." For
example,considerthatyouhaveanonlinearplant.Acommonapproachistogeneratealinearapproximationof
the plant and then use the linearized model to design a controller using analytical techniques. Simulink can
then be employed to simulate the performance of your controller when applied to the full nonlinear model.
controllerasdescribedintheotherIntroductionpages.VariouscontroldesignfacilitiesofMATLABcanalsobe
Recall the Simulink model of the toy train system derived in the Introduction: Simulink Modeling page and
picturedbelow.

3/26

20/01/2016

onlytravelsinonedimension(alongthetrack),wewanttoapplycontroltothetrainenginesothatitstartsand

LetusfirstcreatethestructureforsimulatingthetrainsysteminunityfeedbackwithaPIDcontroller.Inorderto
Toaccomplishthis,deletethethreescopeblocksandreplaceeachonebyanOut1blockfromtheSinkslibrary.
LabeleachOut1blockwiththecorrespondingvariablename,"x1_dot","x1",and"x2".ThendeletetheSignal
Generator block and replace it with an In1 block from the Sources library. Label this input "F" for the force

4/26

20/01/2016

ofthemodelwindow.Withalittlerearrangingandrelabeling,yourmodelwillappearasshownbelow.

5/26

20/01/2016

PID Controller block from the Continuous library. Placing this block in series with 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
designandanalysis.

6/26

20/01/2016

DoubleclickingonthePIDControllerblock,wewillinitiallysettheIntegral(I)gainfieldequalto0andwillleave
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

7/26

20/01/2016

we wish to design a controller to bring the train smoothly up to speed and smoothly to rest, we will test the
systemwithavelocitycommandthatstepsupto1m/sfollowedbyastepbackdownto0m/s(recallthatour
systemisatoytrain).Togeneratethistypeofcommandsignal,doubleclickontheSignalBuilderblock.Then
to"300"seconds.Next,setthestepuptooccurat10secondsandthestepdowntooccurat150seconds.This
isaccomplishedbyclickingonthecorrespondingportionsofthesignalgraph(leftandrightverticallines)and
eitherdraggingthelinetothedesiredposition,orenteringthedesiredtimeintheTfieldatthebottomofthe
window.Whendone,yoursignalshouldappearasfollows.

8/26

20/01/2016

Also add a Scope block from the Sinks library and use it to replace the Out1 block for the train's velocity.
Relabelingtheblocks,yourmodelwillappearasfollows.

9/26

20/01/2016

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 your mfile in the MATLAB command window to define these values. Simulink will recognize these
MATLABvariablesforuseinthemodel.Nextweneedtosetthetimeforwhichoursimulationwillruntomatch
thetimerangeofthecommandfromtheSignalBuilderblock.ThisisaccomplishedbyselectingParameters
thesimulationandopenthe"x1_dot"scopetoexaminethevelocityoutput(hitautoscale).Theresultasshown

10/26

20/01/2016

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

ExtractingamodelintoMATLAB
workspace. This is especially useful for complicated, or nonlinear simulation models. 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 the output of the train system by rightclicking on the "x1_dot" signal and choosing Linearization

11/26

20/01/2016

symbolsasshowninthefollowingfigure.Sincewewishtoextractamodelofthetrainbyitself,withoutcontrol,
weneedtofurtherdeletethefeedbacksignal,otherwisewewillextracttheclosedloopmodelfrom

to

Yourmodelshouldnowappearasfollows.

WecannowextractthemodelbyopeningtheLinearAnalysisTool.ThisisaccomplishedbyselectingControl
openthewindowshownbelow.

12/26

20/01/2016

pointwillhavenoeffectandwecanleaveitasthedefaultModelInitialCondition.Inordertogeneratethe
linearizedmodel,selecttheLinearizebuttonintheabovefigure,whichisindicatedbythegreentriangle.The
LinearAnalysisToolwindowshouldnowappearasshownbelow.

13/26

20/01/2016

Inspectingtheabove,thestepresponseofthelinearizedmodelwasautomaticallygenerated.Comparingthis
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

14/26

20/01/2016

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 then employ MATLAB to design a new controller. Instead, we will demonstrate how to access some of

Rather than performing the controller design in MATLAB, we can also launch interactive tools to tune our
themodelandselecttheTunebuttontolaunchthePIDTunerGUI.Ratherthandothis,willlaunchthemore
general Simulink Control Design GUI by selecting Linear Analysis > Compensator Design from under the
ToolsManagerwindowshownbelow.

15/26

20/01/2016

Thefirstthingthatneedstobedoneistoidentifythecontrollerblockthatistobetuned.Thisisaccomplishedby
firstclickingontheSelectBlocksbutton,andthenselectingthePIDControllerblockfromtheresultingwindow
asshownbelow.NextclicktheOKbutton.Notethatcontrollersrepresentedinothertypesofblocks(Transfer
Function,StateSpace,etc.)canalsobetuned.

16/26

20/01/2016

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
Linearization Points > Input Point from the resulting menu to identify the input of our closedloop system.
Similarly,rightclickonthetrainenginevelocitysignal("x1_dot")andselectLinearizationPoints>OutputPoint
arrowsymbolsidentifytheinputandoutputofthemodel.

17/26

20/01/2016

Nowthatwehaveidentifiedtheblocktotuneandourinputandoutputsignals,wecannowcommencewith
tuning the controller. SelecttheTuneBlocks button in the Control and Estimation Tools Manager window.
ThiswillopentheDesignConfigurationWindow shown below which provides some introduction on how to
employtheinteractivedesigntool.Inessence,thisGUIistheSISODesignTool that is available from within
MATLABaswell.

ClickingtheNextbutton,wewillchoosethedesignplotswewishtoemployfordesigningourcontroller.Inthis

18/26

20/01/2016

example,wewillemployarootlocusdesignapproachandhencewillchooseaPlotTypeofRootLocus for
Plot1asshownbelow.Sincetherootlocusapproachtodesignemploysaplotfromtheopenloopsystemfor
placingtheclosedlooppoles,wewillleavethechoiceofOpen/ClosedLoopsasOpenLoop1(thisisouronly
choice!).

ClickingtheNext button again will allow us to choose our analysis plots. We use the step response plot to
stateerrortoaconstantspeedcommand.Therefore,wewillchooseaPlotTypeofStepfromthedropdown
theonlysystemthatisdefined.Thereisonlyonesystemavailablebecausewehavedefinedonlyasingleinput
andsingleoutputforoursystem.

19/26

20/01/2016

SelectingtheNextButtonwillthenopentheSISODesignToolwitharootlocusplotandastepresponseplot.
Therootlocusplotshownbelowdisplaystheclosedlooppolelocationsofthetrainsystemplantundersimple
proportionalcontrol.Examiningtheplot,onecanseethatmanyvaluesofloopgainwillplaceclosedlooppoles

20/26

20/01/2016

Ifwedecreasetheloopgainsufficiently,wecanmovetheclosedlooppolesintothelefthalfplaneandwecan
stabilizeoursystem.Thiscanbeaccomplishedgraphicallyby"grabbing"thepinkboxesmarkingtheclosed
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. Examining the corresponding step response, which will change
automaticallyinresponsetothegainchangeiftheRealTimeUpdateboxischeckedintheLTIViewerwindow,

21/26

20/01/2016

anintegratorviathecontrollerwillmakethesystemtype1,wheretype1systemscantrackstepreferenceswith
(1)

Therefore, a PI controller will add an integrator and a zero to our openloop system. The integrator can be
zero.Wewillplacethezerojusttotherightoftheplantpoleontherealaxis.Youcanmovethezerobyclicking
onitanddraggingittoanewlocation.Onceyouhaveplacedthezero,thengrabthepinkboxesrepresenting
the closedloop poles and attempt to line the three dominant poles up so that they have the same real part.
Therealsowillbearealclosedlooppoletotheleftthatis"faster"thantherest,andaclosedlooppoleatthe
originthatiscancelledbyaclosedloopzeroattheorigin.Theresultingrootlocusplotisshownbelow.

22/26

20/01/2016

Thecompensatorcanalsobeeditedbydirectlytypinginpoleandzerolocations.Thiscanbedonebychoosing
opensisshownbelow.Wewillmorepreciselyplacethezeroat0.15andwillchoosealoopgainequalto0.01.

23/26

20/01/2016

Theresultingclosedloopstepresponseplotisshownbelowdemonstratingthatthetrainengineisbroughtto

24/26

20/01/2016

The control gains that have been chosen can then be applied to the Simulink model by clicking the Update
Managerwindow(seeabove).Thesimulationcanthenberunwiththisnewlytunedcontroller.Clickingonthe
Scopeblockforthetrainengine'svelocityandselectingautoscalewillproduceaplotliketheoneshownbelow.

25/26

20/01/2016