Top Banner
University College of Southeast Norway http://home.hit.no/~hansha Model Predictive Control in LabVIEW Hans-Petter Halvorsen, 2016.10.31
25

University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

Mar 15, 2018

Download

Documents

lamthien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

UniversityCollegeofSoutheastNorway

http://home.hit.no/~hansha

ModelPredictiveControlinLabVIEWHans-PetterHalvorsen,2016.10.31

Page 2: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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.

Page 3: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

ii Preface

Tutorial:ModelPredictiveControlinLabVIEW

[Figureontitlepage:NationalInstruments,LabVIEWControlDesignUserManual,2008]

Page 4: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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

Page 5: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

4

1 IntroductiontoModelPredictiveControl

1.1 IntroductionTraditionalfeedbackcontrollersoperatebyadjustingcontrolactioninresponsetoachangeintheoutputsetpointofasystem.Modelpredictivecontrol(MPC)isatechniquethatfocusesonconstructingcontrollersthatcanadjustthecontrolactionbeforeachangeintheoutputsetpointactuallyoccurs.Thispredictiveability,whencombinedwithtraditionalfeedbackoperation,enablesacontrollertomakeadjustmentsthataresmootherandclosertotheoptimalcontrolactionvalues.

BelowweseethebasicstructureofMPC:

[Wikipedia]

Page 6: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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:

Page 7: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

6 IntroductiontoModelPredictiveControl

Tutorial:ModelPredictiveControlinLabVIEW

[Figure:NationalInstruments,LabVIEWControlDesignUserManual,2008]

Fortime 𝑘 theMPCcontrollerpredictstheplantoutputfortime 𝑘 + 𝑁).Weseefromthefigurethatthecontrolactiondoesnotchangeafterthecontrolhorizonends.

Thefirstinputintheoptimalsequenceisthensentintotheplant,andtheentirecalculationisrepeatedatsubsequentcontrolintervals.ForeachiterationthepredictionhorizonismovingforwardintimeandtheMPCcontrolleragainpredictstheplantoutput.

Page 8: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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:

Page 9: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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:

Page 10: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

9 IntroductiontoModelPredictiveControl

Tutorial:ModelPredictiveControlinLabVIEW

𝜕𝐽𝜕𝑢 = 0

Bysolvingthiswegetthefutureoptimalcontrol.

Solving EFEG= 0 isquitecomplexandwillnotbepartofthistutorial,butinthe

figurebelowweseeanillustrationoftheproblem.

1.5 ConstraintsAllphysicalsystemshaveconstraints.Wehavephysicalconstraintslikeactuatorlimits,etc.andwehavesafetyconstraintsliketemperatureandpressurelimits.Finallywehaveperformanceconstraintslikeovershoot,etc.

InMPCyounormallydefinetheseconstraints:

Constraintsintheoutputs:

𝑦HIJ ≤ 𝑦 ≤ 𝑦HKL

Page 11: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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

Page 12: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

11 IntroductiontoModelPredictiveControl

Tutorial:ModelPredictiveControlinLabVIEW

• Amathematicalmodelisnotneeded

ThemodelsusedinMPCaregenerallyintendedtorepresentthebehaviorofcomplexdynamicalsystems.TheadditionalcomplexityoftheMPCcontrolalgorithmisnotgenerallyneededtoprovideadequatecontrolofsimplesystems,whichareoftencontrolledwellbyPIDcontrollers.CommondynamiccharacteristicsthataredifficultforPIDcontrollersincludelargetimedelaysandhigh-orderdynamics.

AnotheradvantageofMPCisthatcrosscouplinginmultipleinputandmultipleoutput(MIMO)systemsaretakenintoconsiderationinanoptimalway.MPCisasimplemethodforcontrollingMIMOsystems.

Page 13: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

12

2 LabVIEWControlandSimulationModule

TheMPCfunctionalityinLabVIEWispartofthe“ControlDesignandSimulationModule”.

The“ControlDesignandSimulation”paletteinLabVIEW:

The“ControlDesign”paletteinLabVIEW:

The“PredictiveControl”paletteinLabVIEW:

Page 14: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

13 LabVIEWControlandSimulationModule

Tutorial:ModelPredictiveControlinLabVIEW

HereisashortdescriptionofthedifferentVIs:

Youusethe“CDCreateMPCController”VItocreateanMPCcontroller.ThisVIbasestheMPCcontrolleronastate-spacemodeloftheplantthatyouprovide.

The“CDImplementMPCController”isusedtocalculatethecontrolvaluesforeachsamplingtimeandisnormallyimplementedinaloop,e.g.,aWhileLoop.

Page 15: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

14

3 MPCinLabVIEWInthischapterwewillusetheVisinthe“PredictiveControl”paletteininsomeexample.

3.1 Example1:Simple1.orderModelGiventhefollowingsystem:

𝑥 = −1𝑇 𝑥 + 𝐾𝑢

Where

𝑇 isthetimeconstantforthesystem

𝐾 is,e.g.,thepumpgain

Weset 𝑇 = 5𝑠 and 𝐾 = 2

FrontPanel:

Page 16: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

15 MPCinLabVIEW

Tutorial:ModelPredictiveControlinLabVIEW

Results:

SetpointProfile:

ConstraintsandWeighting:

Page 17: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

16 MPCinLabVIEW

Tutorial:ModelPredictiveControlinLabVIEW

BlockDiagram:

Wecandividethesolutioninto2differentparts:

InitializationtheMPCController:

Thisissomethingwedoonlyoncewhenwestarttheprogram.Weusethe“CDCreateMPCController.vi”.

Page 18: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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

Page 19: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

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):

Page 20: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

19 MPCinLabVIEW

Tutorial:ModelPredictiveControlinLabVIEW

𝐻 𝑠 =𝑥 𝑠𝑢(𝑠) =

105𝑠 + 1 𝑒

@bZ

LabVIEWapplication:

Wecanusethe“CDConstructSpecialTFModel.vi”inordertocreatethetransferfunction.Thenweusemiscellaneousfunctionsinordertoendupwithadiscretestate-spacemodelthathandlesthetimedelay(additionalstatesareadded).

Where

Restofthecodeissimilartopreviousexample,exceptthatwehavebeenusingastatemachineinordertoimplementthecode.

Belowweseethefrontpanel:

Page 21: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

20 MPCinLabVIEW

Tutorial:ModelPredictiveControlinLabVIEW

[EndofExample]

3.3 Example:MultipleInputsInthisexamplewewilluseMPConaMISOsystemwith2inputsand1output.

Page 22: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

21 MPCinLabVIEW

Tutorial:ModelPredictiveControlinLabVIEW

Wedefinethesetpointprofilethesystemshouldfollowinadvance(thefuturesetpointisknown)andseehowtheMPCcontrollerworksinordertofollowthesetpoint.

Weseethatthecontrollerstartstoreactbeforethereferenceactuallychanges,whichisatypicallyfeaturefortheMPCcontroller.

HereweseethemaindifferencebetweenaMPCcontrollerandamoretraditionalPIDcontroller.AnothermaindifferencebetweenMPCandPIDisthatMPCcanhandleMIMO(MultipleInputs,MultipleOutputs)systems,whilePIDisusedforSISOsystems(SingleInput,SingleOutput).

BlockDiagram:

Belowweseetheblockdiagramfortheprogram:

Page 23: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

22 MPCinLabVIEW

Tutorial:ModelPredictiveControlinLabVIEW

Wecandividethesolutioninto2differentparts:

InitializationtheMPCController:

Thisissomethingwedoonlyoncewhenwestarttheprogram.Weusethe“CDCreateMPCController.vi”.

RuntheController:

Thisoperationisperformedeachsample,andthisisnormallyexecutedinsidealoop,e.g.aWhileLoop.Weusethe“CDImplementMPCController.vi”.

Page 24: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

23 MPCinLabVIEW

Tutorial:ModelPredictiveControlinLabVIEW

[EndofExample]

Page 25: University College of Southeast Norwayhome.hit.no/~hansha/documents/labview/training/Model Predictive... · that utilize an explicit process model to predict the future response of

Hans-PetterHalvorsen,M.Sc.

E-mail:[email protected]

Blog:http://home.hit.no/~hansha/

UniversityCollegeofSoutheastNorway

www.usn.no