Documente Academic
Documente Profesional
Documente Cultură
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
AnIntroductiontoControlSystems:Designinga
PIDControllerUsingMATLABsSISOTool
August19,2015byAdolfoMartinez(/author/adolfomartinez)
Introduction
Controlsystemsengineeringrequiresknowledgeofatleasttwobasic
componentsofasystem:theplant,whichdescribesthemathematically
modeledbehaviorofyoursystem,andtheoutputwhichisthegoalyouare
tryingtoreach.Acontrolsystemwhichhasbecomecommonplaceinthe
automotiveindustryisthecruisecontrolsystem:anoutputisprogrammedby
thedriver,andthecontrolsystemhastomanageallofthevehiclereadingsin
ordertomaintainvelocity.
Becausetheroadwedriveonhasimperfections,sometimesthesystemwill
havetoaccelerateordecelerateautomatically.Ifyouveeverusedthisfeature
onacar,youmayhavenoticedthatthecartendstokeepaverysmoothpace
onthevelocityyouvechosenitdoesntabruptlyaccelerateordecelerate.
Thismeansthatthevehiclescontrolsystemisfirstgivenadesiredoutput,
thenmanageserrorsoftheactualoutputbycompensatingfortheinput(for
example,byhowmuchfuelisprovidedtotheengine).
Beforesolvingforasystem,wewillbrieflyanalyzethecomponentsand
behaviorofasystem(uncompensated)andthentheindividualcomponentsofa
PID(proportionalintegralderivative)controller.Thefinalstepwouldbetobring
thesetwotogetheranddesignaPIDcontrollerthatwillcompensatethe
originallyobservedsystem.ItisimportanttoknowthatPIDcontrollersarenot
theonlytypeofcompensationadesignercanapplytosystem,butit'sagreat
placetostartandlearnsomeoftheuniversalcharacteristicsthatwillstaytrue
inothermethods.
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
1/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
inothermethods.
Note:Inthistutorialwewillbeanalyzinganalogsystemsunderidealconditions
(nonoiseordisturbance)andallormostthemathematicalanalysiswilldone
viaMATLAB.
ObservingaSystem
Asystemcanbemadeupofvariouscomponentsarrangedinequallyvarious
waysbutwewillbeginbyanalyzingthecomponentsandfunctionalityofa
classicalclosedloopsytem(Figure1).
Figure1Anexampleblockdiagramofasingleinputsingleoutputsystemclosedloopsystem.
1.Input:rAninputissomesortofreferencevaluethatshouldhavea
directcorrelationwiththesystemsoutput.Thisdoesntnecessary
translatedirectlytoavoltage/powersource,butratherasettingorswitch
thatwillconnectavoltage/powersourcetothesystem.Inthesystem
examplethatwewillanalyzelater,ourinputsignalwillbeaunitarystep.
2.Controller:CInourcase,thisisthePIDcontrollerthatwewilldesign.It
ispositionedbeforetheplantthatwearecompensatedforandjustafter
thejunctionoftheinputsignalandfeedback.
3.Plant:GThisisallofyoursubsystemsmathematicallyexpressedasa
transferfunction.IfwhatyouareattemptingtocontrolisaDCmotor,then
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
2/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
theplantisinfact,yourDCmotor.Youinputwillcausetheplanttoreact
inawaythatwillsupplyanoutputvaluethatisideallyclosetoyourinput.
4.Output:yThisreadingistheactualsystemsresponsetoourdesired
response(theinput)whichhaspassedthroughourassembledsystem
(plant).Theperformanceofthesystemisjudgedbythecomparisonofthe
outputtotheinput,giventhatcertainerrorswilloccurandhavebeen
takenintoaccountasacceptable.
5.Feedback:HInasystemsequivalentblockdiagram(seeFigure1),the
feedbacklineintroducestheoutputofthesystemintotheinput.Whatthis
meansisthatanydiscrepanciesbetweentheoutput(actualresponse)and
input(desiredresponse)canbemeasuredinotherwords,theerror
betweentheinputandoutputiswhatisintroducedtothecontroller.Our
system'serroristhenequalto:inputoutputxHifthesystemhasa
unitaryfeedback(meaningthatH=1),thenourerrorissimplyinputminus
theoutput.Thiswillbeanimportantideatorememberwhenwemove
ontodescribinghoweachfacetofthePIDcontrollerworks.
6.Itisimportanttonotethatthetransferfunctionforthecompleteloopin
Figure1couldbefurthersimplifiedintojustoneblockwithasingleinput
andsingleoutputbytheuseoftheclosedlooptransferfunction:
C (s) G(s)
C losed Loop(s) =
1 + C (s) G(s) H (s)
PIDControlDefinition
APIDcontrollerisactuallyathreepartsystem:
Proportionalcompensation:themainfunctionoftheproportional
compensatoristointroduceagainthatisproportionaltotheerrorreading
whichisproducedbycomparingthesystem'soutputandinput.
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
3/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
Derivativecompensation:inaunitaryfeedbacksystem,thederivative
compensatorwillintroducethederivativeoftheerrorsignalmultipliedbya
gainKD .Inotherwords,theslopeoftheerrorsignal'swaveformiswhat
willintroducedtotheoutput.Itsmainpurposeisthatofimprovingthe
transientresponseoftheoverallclosedloopsystem.
Integralcompensation:inaunitaryfeedbacksystem,theintegral
compensatorwillintroducetheintegraloftheerrorsignalmultipliedbya
gainKI .Thismeansthattheareaundertheerrorsignal'scurvewillbe
affectingtheoutputsignal.Wewillprovethislater,butitisimportantto
notethatthisfacetofthecontrollerwillimprovethesteadystateerrorof
overallclosedloopsystem.
Compensation
TimeDomain
Proportional
KP e(t)
Derivative
KD
e(t)
dt
Integral
KI
e(x)d(x)
0
Therefore,aPIDcontrollercanbemathematicallydescribedas:
Compensation
PIDController
TimeDomain
KP e(t) + KD
d
dt
SDomain
t
e(t) + KI
e(x)d(x) KP + KD s +
0
KI
s
Fornoreasonotherthansimplicity,onecanseewhythesdomainis
exclusivelyusedwhenanalyzingordesigninganalogoussystemsworking
withfractionsisalwayseasierthandoingintegrationand/orderivatives.Ifwe
nowtakewhatwehavedescribedasaPIDcontrollerandapplyittoFigure1,
ourblockdiagramwillnowresemblesomethinglikewhatyouseeinFigure1.1
below.
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
4/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
Figure1.1Our"C"blockisessentiallyeverythingcontainedwithintheredbox:thesummationof
proportional,derivativeandintegralcompensationstothesystem.
OutputCharacteristics
NowthatweknowwhatasystemismadeofandhowwewillapplyingourPID
controller,wecanstarttotalkaboutthecharacteristicsofouroutputsignal
(afterall,thisiswhatwe'remonitoringandattemptingtochange)
ImportantEquations
Outputanalysis:
Characteristic
Equation
Description
Thisgeneralequationwillhelpdes
behaviorofatypicalsecondorder
withnozeros.However,notalltra
functionsareorwillbesecondorde
manywillcontainzeros.Inthesec
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
5/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
GeneralEquation(2nd
order)
manywillcontainzeros.Inthesec
G(s) =
s
+ 2 n s +
2
n
isrequiredtodoapartialfractions
todeterminetheerrorbetweenusin
secondorderequationsonahighe
system.(Note:wewillassumethe
acceptablefortheexampleusedla
thisarticle).
Thisvaluewilldescribethepercen
whichtheoutput'swaveformovers
Overshoot(percent)
pOS
= e
(/ 1 )
100
surpasses)it'sfinal/steadystateva
expressedasapercentofthethef
value.
Itisimportanttotakenotethatthe
forthedampingratioissolelydepe
DampingRatio
ln(pOS /100)
=
2
2
+ ln (pOS /100)
ontheovershoot.Theratiowilldes
systemisisundamped(equalto0)
underdamped(between0and1),c
damped(equalto1),oroverdampe
(greaterthan1).
PeakTime
Tp =
Thisisthetime(inseconds)forthe
2
n 1
waveformtoreachitsmaximum,or
value.
Thetimeittakesforthewaveform
SettlingTime
Ts =
within+/2%ofthefinal/steadysta
4
n
Becauseoscillationsmaycontinue
indefinitely(albeitminor),thisdoes
requirethewaveformtosettleabso
SteadystateerrorAnalysis:
e() = estep () =
1
1 + Kp
where Kp
= lim G(s)
s0
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
6/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
e() = eramp () =
1
Kv
where Kv
= lim s G(s)
s0
e() = eparabola () =
1
Ka
where Ka
= lim s
G(s)
s0
GraphicalRepresentations:
Figure1.2Theplotprovidesavisualizationofhowdifferentdampingratiosaffectasystem'soutput
(inresponsetoastep).Thisalsoshowsathedirectcorrelationbetweenasystem'sdampingratio
andpercentovershoot(thesmallerthedampingratio,thelargertheovershoot).
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
7/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
Figure1.3Anexampleofasystemsresponsetoastepinput.UsingMATLABSISOTool'sanalysis
allowsfortheusertodisplaycharacteristicsoftheresponseinthiscase:peaktime,overshoot,
andsettlingtime.
ControllerDesigninMatlab
Thereareseveralimprovementsweneedtodooncewehaveourtransfer
functionofthecomponent(orplant)whoseresponseneedstobeimproved.
MATLABincludesmanyengineeringtoolboxesthatenableengineersto
create,analyzeandsimulateavarietyofdifferentprojects.Inourcase,
MATLABhasincludedtheControlSystemsToolboxwhichincludesseveral
functionstailoredforcontrolsystemsengineering.Theyvealsoincludedthe
SISO(singleinputsingleoutput)tool,aGUIthatallowsforinteractivesystem
analysisandcontroldesign.TwoofthebestaspectsoftheSISOtoolapproach
are:
1.Howchangesinthetransferfunctionspolesandzerosaltertherootlocus
andbodeplotsinliveresponse.Thechangesingaincanalsobeinstantly
reflectedinthesystemsstepresponse.
2.Specifyingthedesignrequirementswillcreatevisuallimitationsonthe
graphstohelptheusersetandfindappropriategains.Thisisdoneby
rightclickingontheSISOtoolrootlocusplotandselectingDesign
Requirements.Youthenchosethetypeofcharacteristicyouwanttoset
anddefineitslimits.Thiswillprovideyouwithadefinedborderlimitanda
shadedinvalidarea(orangeshade).Itisimportantthatasadesigner,you
keepalistofyourprioritiesandnotethespecificationsthatareofmost
importance.
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
8/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
importance.
ExampleSystemTransferFunction:
K (s + 8)
G(s) =
DesignRequirements:
1.Anovershootofnomorethan20%
2.Peaktime(Tp)thatisnomorethantwothirdsthatofuncompensated
system.(refertoequations)
3.Zerosteadystateerrorforastepinput(refertoequations)
SectionedMATLABScript
%%DefineourPlant
n=poly([8]);%definingournumerator
d=poly([3610]);%definingourdenominator
Ps=tf(n,d)%tfisafunctionthatcallsforapredefinednumeratorand
%denominatorvaluetocreateatransferfunction
Ts=feedback(Ps,1)%thefeedbackfunctionwillautomaticallyprovideyou
%withtheclosedlooptransferfunctionwhiledefining
%yourplantasthefirstvariable,andyourfeedbackas
%yoursecondvariable
%Onceyouclickon"RunSection"youwillnotethatvalueshaveappeared
%inyourWorkspaceandatransferfunctionasbeenprintedinyour
%CommandWindow.
%%RunSISOtooltoanalyzePlanttransferfunction
sisotool(Ps)%NotethatwearerunningsisotoolontheopenloopTF
%%Applygain&analyzesystemresponse
%Atthispointyoucaneitherexportyourgain(K)valueoryoucan
%manuallyenterandsavethevalueinyourworkspace.
K=116.5;%Kasgiventhroughsisoanalysis
Ps1=K*Ps%MuliplyingKwithplant
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
9/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
Ts1=feedback(Ps1,1)%Thiswillprovidetheclosedlooptransferfunction
%wherethefeedbacklinehasavalueofjust1
%(nothingcontainedinfeedbackunitaryfeedback)
stepinfo(Ts1)%stepinfowillprintdetailedstepresponsedata
step(Ts,Ts1);%willprovideagraphofthestepresponseforvisualanalysis
%%CalculateGoalPeakTime
Tp=0.2978;%valueofTpthatIfoundinprevioussectionfromstepinfo
Tp_goal=Tp*(2/3)%printingmygoalpeaktimeincommandwindow
pOS=20;
dr=log(pOS/100)/sqrt(pi^2+(log(pOS/100))^2);%OStoDampingRatioeq.
w=pi/(Tp_goal*sqrt(1(dr^2)))%PeakTimeandDRtofindfreq.
%%ApplyPDcompensation
%Herewerunsisotoolagain,thistimeonPs1insteadofPs.
%Wewillnowaddanadditionaldesigncharacteristicourgoalpeaktime
%Refertopeaktimeequationtofindsettlingtimeequivalent
sisotool(Ps1)
%%ExportthePDcompensatorforanalysis
PD=C%OnlyrunthissectiononcetoensurethatPDisnotoverwrittenwith
%anotherCvaluefromSISOtool
Ps2=Ps1*PD
Ts2=feedback(Ps2,1)
stepinfo(Ts2)
step(Ts,Ts1,Ts2)
%%ApplyPIDcompensation
%Asbefore,wewillrunsisotool,thistimeonPs2andfinalizeourPID
sisotool(Ps2)
%%ExportthePIDcompensatorvalueforanalysis
PID=C%ThiswillcarrythevalueofournewCandattachittoPID
Ps3=Ps2*PID%muliplytheintegratortothePD
Ts3=feedback(Ps3,1)
stepinfo(Ts3)
step(Ts,Ts1,Ts2,Ts3)
%%Finallywewillcalculateoursteadystateerror(refertoequations)
kp=dcgain(Ps3);%dcgainisafunctionthatwillcarryoutourlimits>0
ess=1/(1+kp)%thisistheequationforthesteadystateerrorforastep
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
10/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
DownloadCode(/login/?redirect=http://www.allaboutcircuits.com/technicalarticles/anintr
CommandWindowPrompts
Ps=
s+8
s^3+19s^2+108s+180
Continuoustimetransferfunction.
Ts=
s+8
s^3+19s^2+109s+188
Continuoustimetransferfunction.
Ps1=
116.5s+932
s^3+19s^2+108s+180
Continuoustimetransferfunction.
Ts1=
116.5s+932
s^3+19s^2+224.5s+1112
Continuoustimetransferfunction.
ans=
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
11/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
RiseTime:0.1330
SettlingTime:0.7119
SettlingMin:0.7736
SettlingMax:1.0057
Overshoot:19.9931
Undershoot:0
Peak:1.0057
PeakTime:0.2978
Tp_goal=
0.1985
w=
17.7797
PD=
0.045476(s+56)
Continuoustimezero/pole/gainmodel.
Ps2=
5.298(s+8)(s+56)
(s+10)(s+6)(s+3)
Continuoustimezero/pole/gainmodel.
Ts2=
5.298(s+56)(s+8)
(s+8.08)(s^2+16.22s+316)
Continuoustimezero/pole/gainmodel.
ans=
RiseTime:0.0807
SettlingTime:0.4507
SettlingMin:0.8508
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
12/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
SettlingMin:0.8508
SettlingMax:1.1313
Overshoot:21.7083
Undershoot:0
Peak:1.1313
PeakTime:0.1761
PID=
1.0013(s+0.1)
Continuoustimezero/pole/gainmodel.
Ps3=
5.3048(s+8)(s+56)(s+0.1)
s(s+10)(s+6)(s+3)
Continuoustimezero/pole/gainmodel.
Ts3=
5.3048(s+56)(s+8)(s+0.1)
(s+8.081)(s+0.09324)(s^2+16.13s+315.4)
Continuoustimezero/pole/gainmodel.
ans=
RiseTime:0.0881
SettlingTime:13.0990
SettlingMin:0.8943
SettlingMax:1.1375
Overshoot:13.7503
Undershoot:0
Peak:1.1375
PeakTime:0.1770
ess=
0
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
13/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
DownloadCode(/login/?redirect=http://www.allaboutcircuits.com/technicalarticles/anintr
StepResponsesandRootLocusviaMATLABSISOTool
Figure2Theuncompensatedsystemwillhavetoreachagainofabout116.5
inordertoachievethe20%overshoot(theonlydesigncharacteristicatthis
point)
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
14/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
Figure3Notethatthebordersofthetwodesignrequirementsmeetatcertain
point.Alteringthegainwillcausethatpointwillpositionthepoles..Placingthe
zeroat56willprovidetheplottocrossoverthejunctionpoint,thenadjustits
gain.
Figure4Thegoalistodesignanidealintegratorthatwillbringthesteady
stateerrortozero.Thisisachievedbyplacingapoleattheoriginandazero
closetotheorigin(ruleofthumbisanythinglessthanorequalto0.8)inthis
case,choosetoplacethezeroat0.1.Feelfreetoadjustthesenumbersand
seehowthesystemsreactionchanges.
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
15/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
Figure5Thisshowsthestepresponseofthegivensystemwithzerogain(for
reference),uncompensated(withgain),withPDcontroller,andfinallywithPID
controller
WelcometoAllAboutCircuits!
We'reaglobalcommunityof300,000ElectronicsGeeks
AACiscommunitydriven,withProjects(//www.allaboutcircuits.com/projects/),
ElectronicsTextbooks(//www.allaboutcircuits.com/education/),andaForum
(//forum.allaboutcircuits.com)with930,000posts.Joinusnowandbeenteredin
ournextfreeproductgiveaway!
CreateYourProfile(//forum.allaboutcircuits.com/register/?popup=popup)
Figure6Abetterviewofourpeakresponses
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
16/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
Conclusion
Aspreviouslymentioned,thisarticleattemptedtosubstitutethemathematical
modelingandanalysisbyusingvisualmanipulationsofthesystemsbehavior
andrequirements.Asourendresultshows,wewereabletomeetourdesign
requirementsandimplementthemathematicalmodelofourcompensator.Its
importanttonotethatitwouldrequireanactivecircuittoimplementthedesign
ourPIDcontroller,andthatthereareseveralviablesolutionstoourproblem.
Shouldyoudecidetodesignyourowncontrollerforthesamesystem,itis
recommendedthatyouchoosedifferentvaluesforthepolesandzeroes.
Itislikelythatyoucoulddesignacontrollerthatstillmeetstherequirements
anddoesnothavetheexactvaluesasshownabove.Uponanalysisoffigure
5,itbecomesclearhoweachstepimpactedourendresult.Bysimplydefining
theregionofovershootandadjustingourgain,wewereabletoachievean
outputthatresembledourinput(albeitwithanobviouserror).Bylookingat
figure6,wecanimmediatelytellthatournextattempt(PDcontroller)wasable
WelcometoAllAboutCircuits!
todramaticallyimproveourpeaktimeandsteadystateerror.Finally,ourPID
wasabletotakewhatwealreadyhaddefinedinourPDandimproveour
We'reaglobalcommunityof300,000ElectronicsGeeks
AACiscommunitydriven,withProjects(//www.allaboutcircuits.com/projects/),
steadystateerrortoourgoalofzero.BecomingproficientwiththeSISOtool
ElectronicsTextbooks(//www.allaboutcircuits.com/education/),andaForum
notonlyhelpsimprovethetimeittakestodesignafunctionalcontroller,but
(//forum.allaboutcircuits.com)with930,000posts.Joinusnowandbeenteredin
helpstoingraintherelationshipsofeachaspect/componenttoourendresult.
ournextfreeproductgiveaway!
CreateYourProfile(//forum.allaboutcircuits.com/register/?popup=popup)
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
17/18
12/16/2016
AnIntroductiontoControlSystems:DesigningaPIDControllerUsingMATLABsSISOTool
WelcometoAllAboutCircuits!
We'reaglobalcommunityof300,000ElectronicsGeeks
AACiscommunitydriven,withProjects(//www.allaboutcircuits.com/projects/),
ElectronicsTextbooks(//www.allaboutcircuits.com/education/),andaForum
(//forum.allaboutcircuits.com)with930,000posts.Joinusnowandbeenteredin
ournextfreeproductgiveaway!
CreateYourProfile(//forum.allaboutcircuits.com/register/?popup=popup)
http://www.allaboutcircuits.com/technicalarticles/anintroductiontocontrolsystemsdesigningapidcontrollerusingmatlabs/
18/18