University College of Southeast Norway http://home.hit.no/~hansha Model Predictive Control in LabVIEW Hans-Petter Halvorsen, 2016.10.31
UniversityCollegeofSoutheastNorway
http://home.hit.no/~hansha
ModelPredictiveControlinLabVIEWHans-PetterHalvorsen,2016.10.31
i
PrefaceModelPredictiveControl,orMPC,isanadvancedmethodofprocesscontrolthathasbeeninuseintheprocessindustriessuchaschemicalplantsandoilrefineriessincethe1980s.Modelpredictivecontrollersrelyondynamicmodelsoftheprocess,mostoftenlinearempiricalmodelsobtainedbysystemidentification.
Modelpredictivecontrol(MPC)referstoaclassofcomputercontrolalgorithmsthatutilizeanexplicitprocessmodeltopredictthefutureresponseofaplant.AteachcontrolintervalanMPCalgorithmattemptstooptimizefutureplantbehaviorbycomputingasequenceoffuturemanipulatedvariableadjustments.Thefirstinputintheoptimalsequenceisthensentintotheplant,andtheentirecalculationisrepeatedatsubsequentcontrolintervals.Originallydevelopedtomeetthespecializedcontrolneedsofpowerplantsandpetroleumrefineries,MPCtechnologycannowbefoundinawidevarietyofapplicationareasincludingchemicals,foodprocessing,automotive,andaerospaceapplications.
Programmingtoolslike,e.g.,MATLAB(ModelPredictiveControlToolbox)andLabVIEW(ControlDesignandSimulationModule)hasMPCfunctionality.
DeltaV,whichisaDCS(DistributedControlSystem)systemhasMPCfunctionality(DeltaVPredict/DeltaVPredictPro).
Thesearejustafewexamples,butmentionedherebecausethesetoolsandsystemsareavailbleattheuniversity.
InthisTutorialwewillusethePredictiveControlfunctionalitywhichispartoftheLabVIEWControlDesignandSimulationModule.
ThescopewiththisTutorialisnottogoindepthofthetheorybehindMPC,buttouseandgiveanoverviewoftheMPCimplementationinLabVIEW.
ii Preface
Tutorial:ModelPredictiveControlinLabVIEW
[Figureontitlepage:NationalInstruments,LabVIEWControlDesignUserManual,2008]
iii
TableofContentsPreface..................................................................................................................i
TableofContents................................................................................................iii
1 IntroductiontoModelPredictiveControl.....................................................4
1.1 Introduction............................................................................................4
1.2 PredictionandControlHorizons.............................................................5
1.3 Model.....................................................................................................7
1.4 CostFunction..........................................................................................8
1.5 Constraints..............................................................................................9
1.6 MPCvs.TraditionalControl(PID).........................................................10
2 LabVIEWControlandSimulationModule...................................................12
3 MPCinLabVIEW..........................................................................................14
3.1 Example1:Simple1.orderModel.......................................................14
3.2 Example2:ModelwithTimeDelay......................................................17
3.3 Example:MultipleInputs......................................................................20
4
1 IntroductiontoModelPredictiveControl
1.1 IntroductionTraditionalfeedbackcontrollersoperatebyadjustingcontrolactioninresponsetoachangeintheoutputsetpointofasystem.Modelpredictivecontrol(MPC)isatechniquethatfocusesonconstructingcontrollersthatcanadjustthecontrolactionbeforeachangeintheoutputsetpointactuallyoccurs.Thispredictiveability,whencombinedwithtraditionalfeedbackoperation,enablesacontrollertomakeadjustmentsthataresmootherandclosertotheoptimalcontrolactionvalues.
BelowweseethebasicstructureofMPC:
[Wikipedia]
5 IntroductiontoModelPredictiveControl
Tutorial:ModelPredictiveControlinLabVIEW
ModelPredictiveControl(MPC)isacontrolstrategywhichisaspecialcaseoftheoptimalcontroltheorydevelopedinthe1960andlather.MPCconsistsofanoptimizationproblemateachtimeinstants,k.
Themainpointofthisoptimizationproblemistocomputeanewcontrolinputvector, 𝑢",tobefeedtothesystem,andatthesametimetakeprocessconstraintsintoconsideration(e.g.,constraintsonprocessvariables).
AnMPCalgorithmconsistsof:
• ACostfunction• Constraints• AModeloftheprocess
Thesethingswillbeexplainedindetailbelow.
1.2 PredictionandControlHorizonsPredictionhorizon(𝑵𝒑)-ThenumberofsamplesinthefuturetheMPCcontrollerpredictstheplantoutput.
Controlhorizon(𝑵𝒄)–ThenumberofsampleswithinthepredictionhorizonwheretheMPCcontrollercanaffectthecontrolaction.
Note!
𝑁' ≤ 𝑁)
BelowweseethePredictionandControlHorizons:
6 IntroductiontoModelPredictiveControl
Tutorial:ModelPredictiveControlinLabVIEW
[Figure:NationalInstruments,LabVIEWControlDesignUserManual,2008]
Fortime 𝑘 theMPCcontrollerpredictstheplantoutputfortime 𝑘 + 𝑁).Weseefromthefigurethatthecontrolactiondoesnotchangeafterthecontrolhorizonends.
Thefirstinputintheoptimalsequenceisthensentintotheplant,andtheentirecalculationisrepeatedatsubsequentcontrolintervals.ForeachiterationthepredictionhorizonismovingforwardintimeandtheMPCcontrolleragainpredictstheplantoutput.
7 IntroductiontoModelPredictiveControl
Tutorial:ModelPredictiveControlinLabVIEW
[Figure:NationalInstruments,LabVIEWControlDesignUserManual,2008]
Predictionhorizon:
AshortpredictionhorizonreducesthelengthoftimeduringwhichtheMPCcontrollerpredictstheplantoutputs.WhenthepredictionhorizonisshorttheMPCcontrollerworksmorelikeatraditionalfeedbackcontroller.
AlongpredictionhorizonincreasesthepredictiveabilityoftheMPCcontroller,buttheperformancepoorerduetoextracalculations.
Controlhorizon:
Ashortcontrolhorizonmeansmorecarefullychangesinthecontrolaction.
Alongcontrolhorizonmeansmoreaggressivechangesinthecontrolaction.
1.3 ModelThemaindrawbackwithMPCisthatamodelfortheprocess,i.e.,amodelwhichdescribestheinputtooutputbehavioroftheprocess,isneeded.Mechanisticmodelsderivedfromconservationlawscanbeused.Usually,howeverinpracticesimplydata-drivenlinearmodelsareused.
InMPCitisassumedthatthemodelisadiscretestate-spacemodeloftheform:
8 IntroductiontoModelPredictiveControl
Tutorial:ModelPredictiveControlinLabVIEW
𝑥"-. = 𝐴𝑥" + 𝐵𝑢"
𝑦" = 𝐶𝑥" + 𝐷𝑢"
1.4 CostFunctionThemainideawithMPCisthattheMPCcontrollercalculatesasequenceoffuturecontrolactionssuchthatacostfunctionisminimized.
ThecostfunctionoftenusedinMPCislikethis(alinearquadraticfunction)[NationalInstruments,LabVIEWControlDesignUserManual,2008]:
𝐽 = 𝑦 − 𝑟 8𝑄
:;
"<=
𝑦 − 𝑟 + ∆𝑢8𝑅
:;
"<=
∆𝑢
Where:
𝑁) –Predictionhorizon
𝑟 –Setpoint
𝑦 –Predictedprocessoutput
∆𝑢 –Predictedchangeincontrolvalue, ∆𝑢" = 𝑢" − 𝑢"@.
𝑄 –Outputerrorweightmatrix
𝑅 –Controlweightmatrix
ThisworksforMIMOsystems(MultipleInputandMultipleOutputs)sowearedealingwithvectorsandmatrices.
Forascalarsystemwehave:
𝐽 = 𝑞 𝑦 − 𝑟 B
:;
"<=
+ 𝑟∆𝑢B:;
"<=
Sothebasicproblemistosolve:
9 IntroductiontoModelPredictiveControl
Tutorial:ModelPredictiveControlinLabVIEW
𝜕𝐽𝜕𝑢 = 0
Bysolvingthiswegetthefutureoptimalcontrol.
Solving EFEG= 0 isquitecomplexandwillnotbepartofthistutorial,butinthe
figurebelowweseeanillustrationoftheproblem.
1.5 ConstraintsAllphysicalsystemshaveconstraints.Wehavephysicalconstraintslikeactuatorlimits,etc.andwehavesafetyconstraintsliketemperatureandpressurelimits.Finallywehaveperformanceconstraintslikeovershoot,etc.
InMPCyounormallydefinetheseconstraints:
Constraintsintheoutputs:
𝑦HIJ ≤ 𝑦 ≤ 𝑦HKL
10 IntroductiontoModelPredictiveControl
Tutorial:ModelPredictiveControlinLabVIEW
Constraintsintheinputs:
∆𝑢HIJ ≤ ∆𝑢 ≤ ∆𝑢HKL
𝑢HIJ ≤ 𝑢 ≤ 𝑢HKL
Note! ∆𝑢" = 𝑢" − 𝑢"@.
TheMPCcontrollertakesalltheseconstraintsintoconsiderationwhencalculatingthefuturecontrols.
1.6 MPCvs.TraditionalControl(PID)MPCisoftenusedinadditiontotraditionalcontrollikePID.InlargeplantsMPCisnotareplacementfortraditionalPID,butusedinadditiontoPIDcontrollers.PIDcontrollersareusedassingle-loopcontrollers,whileMPCisusedasanoverallsystem.PIDhandlesonlyasingleinputandasingleoutput(SISOsystems),whileMPCisamoreadvancedmethodofprocesscontrolusedforMIMOsystems(MultipleInputs,multipleOutputs).
TraditionalControl(PID) MPC
• Noknowledgeaboutconstraints
• Setpointfarfromconstraints• Notoptimalprocess
operation• SISOsystems
• Constraintsincludedinthedesign
• Setpointcanbeclosertoconstraints
• Improvedprocessoperation• MIMOsystems• Amathematicalmodelisneeded
11 IntroductiontoModelPredictiveControl
Tutorial:ModelPredictiveControlinLabVIEW
• Amathematicalmodelisnotneeded
ThemodelsusedinMPCaregenerallyintendedtorepresentthebehaviorofcomplexdynamicalsystems.TheadditionalcomplexityoftheMPCcontrolalgorithmisnotgenerallyneededtoprovideadequatecontrolofsimplesystems,whichareoftencontrolledwellbyPIDcontrollers.CommondynamiccharacteristicsthataredifficultforPIDcontrollersincludelargetimedelaysandhigh-orderdynamics.
AnotheradvantageofMPCisthatcrosscouplinginmultipleinputandmultipleoutput(MIMO)systemsaretakenintoconsiderationinanoptimalway.MPCisasimplemethodforcontrollingMIMOsystems.
12
2 LabVIEWControlandSimulationModule
TheMPCfunctionalityinLabVIEWispartofthe“ControlDesignandSimulationModule”.
The“ControlDesignandSimulation”paletteinLabVIEW:
The“ControlDesign”paletteinLabVIEW:
The“PredictiveControl”paletteinLabVIEW:
13 LabVIEWControlandSimulationModule
Tutorial:ModelPredictiveControlinLabVIEW
HereisashortdescriptionofthedifferentVIs:
Youusethe“CDCreateMPCController”VItocreateanMPCcontroller.ThisVIbasestheMPCcontrolleronastate-spacemodeloftheplantthatyouprovide.
The“CDImplementMPCController”isusedtocalculatethecontrolvaluesforeachsamplingtimeandisnormallyimplementedinaloop,e.g.,aWhileLoop.
14
3 MPCinLabVIEWInthischapterwewillusetheVisinthe“PredictiveControl”paletteininsomeexample.
3.1 Example1:Simple1.orderModelGiventhefollowingsystem:
𝑥 = −1𝑇 𝑥 + 𝐾𝑢
Where
𝑇 isthetimeconstantforthesystem
𝐾 is,e.g.,thepumpgain
Weset 𝑇 = 5𝑠 and 𝐾 = 2
FrontPanel:
15 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
Results:
SetpointProfile:
ConstraintsandWeighting:
16 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
BlockDiagram:
Wecandividethesolutioninto2differentparts:
InitializationtheMPCController:
Thisissomethingwedoonlyoncewhenwestarttheprogram.Weusethe“CDCreateMPCController.vi”.
17 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
RuntheController:
Thisoperationisperformedeachsample,andthisisnormallyexecutedinsidealoop,e.g.aWhileLoop.Weusethe“CDImplementMPCController.vi”.
[EndofExample]
3.2 Example2:ModelwithTimeDelayGiventhefollowingsystem:
𝑥 = −1𝑇 𝑥 + 𝐾𝑢(𝑡 − 𝜏)
Where
𝑇 isthetimeconstantforthesystem
𝐾 is,e.g.,thepumpgain
18 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
𝜏 isthetimedelay
Weset 𝑇 = 5𝑠, 𝐾 = 2 and 𝜏 = 3𝑠
TheMPCalgorithmrequiresthatthemodelisalinearstate-spacemodel,butthetimedelaycausesproblems.
Asolutioncouldbetotransformthedifferentialequationwehavetoatransferfunction.Thenwecanusebuilt-infunctionsinLabVIEWtoconvertittoalinearstate-spacemodel.
WeuseLaplaceonthedifferentialequationabove:
𝑠𝑥(𝑠) = −1𝑇 𝑥(𝑠) + 𝐾𝑢(𝑠)𝑒
@YZ
Note!WeusethefollowingLaplacetransformation:
𝐹 𝑠 𝑒@YZ ⟺ 𝑓(𝑡 − 𝜏)
𝑠𝐹(𝑠) ⟺ 𝑓(𝑡)
Thisgives:
𝑠𝑥 𝑠 +1𝑇 𝑥 𝑠 = 𝐾𝑢(𝑠)𝑒@YZ
Next:
𝑥 𝑠 𝑠 +1𝑇 = 𝐾𝑢(𝑠)𝑒@YZ
Next:
𝑥 𝑠𝑢(𝑠) =
𝐾
𝑠 + 1𝑇𝑒@YZ
Finally:
𝐻 𝑠 =𝑥 𝑠𝑢(𝑠) =
𝐾𝑇𝑇𝑠 + 1 𝑒
@YZ =𝐾`a`𝑇𝑠 + 1 𝑒
@YZ
Withvalues(𝑇 = 5, 𝐾 = 2, 𝜏 = 3):
19 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
𝐻 𝑠 =𝑥 𝑠𝑢(𝑠) =
105𝑠 + 1 𝑒
@bZ
LabVIEWapplication:
Wecanusethe“CDConstructSpecialTFModel.vi”inordertocreatethetransferfunction.Thenweusemiscellaneousfunctionsinordertoendupwithadiscretestate-spacemodelthathandlesthetimedelay(additionalstatesareadded).
Where
Restofthecodeissimilartopreviousexample,exceptthatwehavebeenusingastatemachineinordertoimplementthecode.
Belowweseethefrontpanel:
20 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
[EndofExample]
3.3 Example:MultipleInputsInthisexamplewewilluseMPConaMISOsystemwith2inputsand1output.
21 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
Wedefinethesetpointprofilethesystemshouldfollowinadvance(thefuturesetpointisknown)andseehowtheMPCcontrollerworksinordertofollowthesetpoint.
Weseethatthecontrollerstartstoreactbeforethereferenceactuallychanges,whichisatypicallyfeaturefortheMPCcontroller.
HereweseethemaindifferencebetweenaMPCcontrollerandamoretraditionalPIDcontroller.AnothermaindifferencebetweenMPCandPIDisthatMPCcanhandleMIMO(MultipleInputs,MultipleOutputs)systems,whilePIDisusedforSISOsystems(SingleInput,SingleOutput).
BlockDiagram:
Belowweseetheblockdiagramfortheprogram:
22 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
Wecandividethesolutioninto2differentparts:
InitializationtheMPCController:
Thisissomethingwedoonlyoncewhenwestarttheprogram.Weusethe“CDCreateMPCController.vi”.
RuntheController:
Thisoperationisperformedeachsample,andthisisnormallyexecutedinsidealoop,e.g.aWhileLoop.Weusethe“CDImplementMPCController.vi”.
23 MPCinLabVIEW
Tutorial:ModelPredictiveControlinLabVIEW
[EndofExample]
Hans-PetterHalvorsen,M.Sc.
E-mail:[email protected]
Blog:http://home.hit.no/~hansha/
UniversityCollegeofSoutheastNorway
www.usn.no