68
Tracking, disturbances and zero offset James B. Rawlings Department of Chemical and Biological Engineering Copyright 2015 by James B. Rawlings Freiburg, Germany March 30-31, 2015 Freiburg 2015 Tracking, disturbances, offset 1 / 57

Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Tracking, disturbances and zero offset

James B. Rawlings

Department of Chemical and Biological Engineering

Copyright © 2015 by James B. Rawlings

Freiburg, GermanyMarch 30-31, 2015

Freiburg 2015 Tracking, disturbances, offset 1 / 57

Page 2: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Outline

1 Setpoint TrackingDeviation variables

2 Steady-state target problem

3 Dynamic regulation problem

4 State estimation, disturbance models and zero offset

5 Review

Freiburg 2015 Tracking, disturbances, offset 2 / 57

Page 3: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Setpoint tracking

In this section we show how to use the MPC regulator and MHEestimator to handle different kinds of control problems, includingsetpoint tracking and rejecting nonzero disturbances.

It is a standard objective in applications to use a feedback controllerto move the measured outputs of a system to a specified andconstant setpoint. This problem is known as setpoint tracking.

In nonlinear MPC theory we can consider the case in which thesystem is nonlinear and constrained, but here we consider linearmodel MPC in which ysp is an arbitrary constant.

Freiburg 2015 Tracking, disturbances, offset 3 / 57

Page 4: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Deviation variables

In the regulation problem we assumed that the goal was to take thestate of the system to the origin. Such a regulator can be used totreat the setpoint tracking problem with a coordinate transformation.

Denote the desired output setpoint as ysp. Denote a steady state ofthe system model as (xs , us). The steady state satisfies

[I − A −B

] [xsus

]= 0

For unconstrained systems, we also impose the requirement that thesteady state satisfies Cxs = ysp for the tracking problem, giving theset of equations [

I − A −BC 0

] [xsus

]=

[0ysp

](1)

Freiburg 2015 Tracking, disturbances, offset 4 / 57

Page 5: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Deviation variables

If this set of equations has a solution, we can then define deviationvariables

x(k) = x(k)− xs

u(k) = u(k)− us

They satisfy the dynamic model

x(k + 1) = x(k + 1)− xs

= Ax(k) + Bu(k)− (Axs + Bus)

x(k + 1) = Ax(k) + Bu(k)

The deviation variables satisfy the same model equation as theoriginal variables! This feature holds only for linear models.

Freiburg 2015 Tracking, disturbances, offset 5 / 57

Page 6: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Deviation variables

The zero regulation problem applied to the system in deviationvariables finds u(k) that takes x(k) to zero, or, equivalently, whichtakes x(k) to xs , so that at steady state, Cx(k) = Cxs = ysp, which isthe goal of the setpoint tracking problem.

After solving the regulation problem in deviation variables, the inputapplied to the system is

u(k) = u(k) + us

We next discuss when we can solve (1). We also note that forconstrained systems, we must impose the constraints on the steadystate (xs , us).

Freiburg 2015 Tracking, disturbances, offset 6 / 57

Page 7: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

More outputs than inputs: controlled variables

The matrix in (1) is a (n + p)× (n + m) matrix. For (1) to have asolution for all ysp, it is sufficient that the rows of the matrix arelinearly independent.

That requires p ≤ m: we require at least as many inputs as outputswith setpoints. But it is not uncommon in applications to have manymore measured outputs than manipulated inputs.

To handle these more general situations, we choose a matrix H anddenote a new variable r = Hy as a selection of linear combinations ofthe measured outputs. The variable r ∈ Rnc is known as thecontrolled variable.

For cases in which p > m, we choose some set of outputs nc ≤ m, ascontrolled variables, and assign setpoints to r , denoted rsp.

Freiburg 2015 Tracking, disturbances, offset 7 / 57

Page 8: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

More inputs than outputs: input targets

We also wish to treat systems with more inputs than outputs, m > p.For these cases, the solution to (1) may exist for some choice of Hand rsp, but cannot be unique.

If we wish to obtain a unique steady state, then we also must providedesired values for the steady inputs, usp.

To handle constrained systems, we simply impose the constraints on(xs , us).

Freiburg 2015 Tracking, disturbances, offset 8 / 57

Page 9: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Steady-state target problem

Our candidate optimization problem is therefore

minxs ,us

1

2

(|us − usp|2Rs

+ |Cxs − ysp|2Qs

)(2a)

subject to: [I − A −BHC 0

] [xsus

]=

[0rsp

](2b)

Eus ≤ e (2c)

FCxs ≤ f (2d)

Freiburg 2015 Tracking, disturbances, offset 9 / 57

Page 10: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

We make the following assumptions:

Assumption 1 (Target feasibility and uniqueness)

1 The target problem is feasible for the controlled variable setpoints ofinterest rsp.

2 The steady-state input penalty Rs is positive definite.

Assumption 1.1 ensures that the solution (xs , us) exists

Assumption 1.2 ensures that the solution is unique.

If one chooses nc = 0, then no controlled variables are required to beat setpoint, and the problem is feasible for any (usp, ysp) because(xs , us) = (0, 0) is a feasible point.

Freiburg 2015 Tracking, disturbances, offset 10 / 57

Page 11: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Some exercises on the target problem

Exercises 1.56 and 1.57 explore the connection between feasibility ofthe equality constraints and the number of controlled variablesrelative to the number of inputs and outputs.

One restriction is that the number of controlled variables chosen to beoffset free must be less than or equal to the number of manipulatedvariables and the number of measurements, nc ≤ m and nc ≤ p.

Freiburg 2015 Tracking, disturbances, offset 11 / 57

Page 12: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Dynamic regulation problem

Given the steady-state solution, we define the following multistageobjective function

V (x(0), u) =1

2

N−1∑k=0

|x(k)|2Q + |u(k)|2R s.t. x+ = Ax + Bu

The initial state isx(0) = x(k)− xs

i.e., the initial condition for the regulation problem comes from thestate estimate shifted by the steady-state xs .

Freiburg 2015 Tracking, disturbances, offset 12 / 57

Page 13: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Dynamic regulation problem

The regulator solves the following dynamic, zero-state regulation problem

minu

V (x(0), u)

subject to

Eu ≤ e − Eus

FCx ≤ f − FCxs

in which the constraints also are shifted by the steady state (xs , us).

Freiburg 2015 Tracking, disturbances, offset 13 / 57

Page 14: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Dynamic regulation problem — control law

The optimal cost and solution are V 0(x(0)) and u0(x(0)).

The moving horizon control law uses the first move of this optimalsequence, u0(x(0)) = u0(0; x(0)), so the controller output is

u(k) = u0(x(0)) + us

The control law is more complex than the PID control law, but thecontrol is a function of the estimated state, and the estimated statedepends on the measurements. That’s the feedback in MPC!

Designing the state estimator is crucial to good closed-loop controlperformance.

Freiburg 2015 Tracking, disturbances, offset 14 / 57

Page 15: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

The assembly so far

xs

us

x

estimator

target

selector

x+ = Ax + Bu

(Q,R)

u y

ysp, usp, rsp

(Qs ,Rs)

regulator plant

x

Freiburg 2015 Tracking, disturbances, offset 15 / 57

Page 16: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Disturbances and zero offset

Another common objective in applications is to use a feedbackcontroller to compensate for an unmeasured disturbance to thesystem with the input so the disturbance’s effect on the controlledvariable is mitigated.

This problem is known as disturbance rejection. We may wish todesign a feedback controller that compensates for nonzerodisturbances such that the selected controlled variables asymptoticallyapproach their setpoints without offset.

This property is known as zero offset. In this section we show a simplemethod for constructing an MPC controller to achieve zero offset.

Freiburg 2015 Tracking, disturbances, offset 16 / 57

Page 17: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Disturbances and zero offset

We will ensure that if the system is stabilized in the presence of thedisturbance, then there is zero offset.

This more limited objective is similar to what one achieves when usingthe integral mode in proportional-integral-derivative (PID) control ofan unconstrained system: either there is zero steady offset, or thesystem trajectory is unbounded.

In a constrained system, the statement is amended to: either there iszero steady offset, or the system trajectory is unbounded, or thesystem constraints are active at steady state.

In both constrained and unconstrained systems, the zero-offsetproperty precludes one undesirable possibility: the system settles atan unconstrained steady state, and the steady state displays offset inthe controlled variables.

Freiburg 2015 Tracking, disturbances, offset 17 / 57

Page 18: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

So why does the PI controller have zero offset?

Here’s the control law

u(t) = kc

(e(t) +

1

τI

∫ t

0e(t ′)dt ′

), e = ysp − y

If the tracking error goes to a (nonzero) constant, e(t)→ es , thenu(t)→∞ as t →∞ because of the integral term.

If we turn off the integrator

us = kces

and we expect offset with a proportional controller.

In PI, we obtain zero offset by integrating the tracking error. In MPCwe will not integrate the tracking error. But we will integrate insteadthe model error.

We can show that is also sufficient to remove offset. And we won’thave windup when inputs saturate.

Freiburg 2015 Tracking, disturbances, offset 18 / 57

Page 19: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Disturbance model

A simple method to compensate for an unmeasured disturbance is to1 model the disturbance2 use the measurements and model to estimate the disturbance3 find the inputs that minimize the effect of the disturbance on the

controlled variables.

The choice of disturbance model is motivated by the zero-offset goal.To achieve offset-free performance we augment the system state withan integrating disturbance d driven by the process noise w

d(k + 1) = d(k) + w(k) (3)

d integrates the driving noise w

d(k) = w(0) + w(1) + · · ·+ w(k − 1)

Freiburg 2015 Tracking, disturbances, offset 19 / 57

Page 20: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

A little history on disturbance models

This choice is motivated by the works of Davison and Smith (1971,1974); Qiu and Davison (1993) and the Internal Model Principle ofFrancis and Wonham (1976).

To remove offset, one designs a control system that can removeasymptotically constant, nonzero disturbances (Davison and Smith,1971), (Kwakernaak and Sivan, 1972, p.278).

To accomplish this end, the original system is augmented with areplicate of the constant, nonzero disturbance model, (3). Thus thestates of the original system are moved to cancel the effect of thedisturbance on the controlled variables.

Freiburg 2015 Tracking, disturbances, offset 20 / 57

Page 21: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

System plus disturbance model

The augmented system model used for the state estimator is given by[xd

]+

=

[A Bd

0 I

] [xd

]+

[B0

]u + w (4a)

y =[C Cd

] [xd

]+ v (4b)

We are free to choose how the integrating disturbance affects thestates and measured outputs through the choice of Bd and Cd .

The only restriction is that the augmented system is detectable. Thatrestriction can be easily checked using the following result.

Freiburg 2015 Tracking, disturbances, offset 21 / 57

Page 22: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Restrictions on the disturbance model

Lemma 2 (Detectability of the augmented system)

The augmented system (4) is detectable if and only if the nonaugmentedsystem (A,C ) is detectable, and the following condition holds:

rank

[I − A −Bd

C Cd

]= n + nd (5)

Corollary 3 (Dimension of the disturbance)

The maximal dimension of the disturbance d in (4) such that theaugmented system is detectable is equal to the number of measurements,that is

nd ≤ p

A pair of matrices (Bd ,Cd) such that (5) is satisfied always exists.

Freiburg 2015 Tracking, disturbances, offset 22 / 57

Page 23: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Estimate state plus disturbance

The state and the additional integrating disturbance are estimatedfrom the plant measurement using a Kalman filter designed for theaugmented system.

The variances of the stochastic disturbances w and v may be treatedas adjustable parameters or found from input-outputmeasurements (Odelson, Rajamani, and Rawlings, 2006).

Freiburg 2015 Tracking, disturbances, offset 23 / 57

Page 24: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Overview of the final assembly

[x

d

]+

=

[ABd

0 I

] [x

d

]+

[B0

]u+[

LxLd

](y −

[C Cd

] [xd

])x

d

xs

us

x

estimator

target

selector

x+ = Ax + Bu

(Q,R)

u y

ysp, usp, rsp

(Qs ,Rs)

regulator plant

Freiburg 2015 Tracking, disturbances, offset 24 / 57

Page 25: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Forecast of the disturbance

The estimator provides x(k) and d(k) at each time k .

The best forecast of the steady-state disturbance using (3) is simply

ds = d(k)

Freiburg 2015 Tracking, disturbances, offset 25 / 57

Page 26: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

The nonzero disturbance affects the steady-state target

The steady-state target problem is therefore modified to account for thenonzero disturbance ds

minxs ,us

1

2

(|us − usp|2Rs

+∣∣∣Cxs + Cd ds − ysp

∣∣∣2Qs

)(6a)

subject to: [I − A −BHC 0

] [xsus

]=

[Bd ds

rsp − HCd ds

](6b)

Eus ≤ e (6c)

FCxs ≤ f − FCd ds (6d)

Freiburg 2015 Tracking, disturbances, offset 26 / 57

Page 27: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Effect of the disturbance

Comparing (2) to (6), we see the disturbance model affects thesteady-state target determination in four places.

1 The output target is modified in (6a) to account for the effect of thedisturbance on the measured output (ysp → ysp − Cd ds).

2 The output constraint in (6d) is similarly modified (f → f − FCd ds).

3 The system steady-state relation in (6b) is modified to account forthe effect of the disturbance on the state evolution (0→ Bd ds).

4 The controlled variable target in (6b) is modified to account for theeffect of the disturbance on the controlled variable(rsp → rsp − HCd ds).

Freiburg 2015 Tracking, disturbances, offset 27 / 57

Page 28: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

No change to the regulation problem, only the target!

Given the steady-state target, the same dynamic regulation problemas presented in the tracking section is used for the regulator.

In other words, the regulator is based on the deterministic system(A,B) in which the current state is x(k)− xs and the goal is to takethe system to the origin.

Freiburg 2015 Tracking, disturbances, offset 28 / 57

Page 29: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Offset-free control property of the control system

Lemma 4 (Offset-free control)

Consider a system controlled by the MPC algorithm as shown in thefigure. The target problem (6) is assumed feasible. Augment the systemmodel with a number of integrating disturbances equal to the number ofmeasurements (nd = p); choose any Bd ∈ Rn×p, Cd ∈ Rp×p such that

rank

[I − A −Bd

C Cd

]= n + p

If the plant output y(k) goes to steady state ys , the closed-loop system isstable, and constraints are not active at steady state, then there is zerooffset in the controlled variables, that is

Hys = rsp

Freiburg 2015 Tracking, disturbances, offset 29 / 57

Page 30: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Remarks on offset

The proof of this lemma is given in Pannocchia and Rawlings (2003).

It may seem surprising that the number of integrating disturbancesmust be equal to the number of measurements used for feedbackrather than the number of controlled variables to guaranteeoffset-free control.

To gain insight into the reason, consider the disturbance part (bottomhalf) of the Kalman filter equations shown in the figure

d+ = d + Ld

(y −

[C Cd

] [xd

])Because of the integrator, the disturbance estimate cannot convergeuntil

Ld

(y −

[C Cd

] [xd

])= 0

Freiburg 2015 Tracking, disturbances, offset 30 / 57

Page 31: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Number of disturbances equals number of measurements

Let the output prediction error be

Lde = 0 e = y −[C Cd

] [xd

]nd

p[Ld]

If we choose nd = nc < p, then the number of columns of Ld isgreater than the number of rows and Lde = 0 does not force e = 0.

In general, we require the output prediction error to be zero toachieve zero offset independently of the regulator tuning.

For Lde = 0 to force e = 0, we require nd ≥ p.

Since we also know nd ≤ p from Corollary 3, we conclude nd = p.

Freiburg 2015 Tracking, disturbances, offset 31 / 57

Page 32: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Also removes offset due to model error!

Notice also that Lemma 4 does not require that the plant output begenerated by the model. The theorem applies regardless of whatgenerates the plant output. If the plant is identical to the systemplus disturbance model assumed in the estimator, then the conclusioncan be strengthened.

In the nominal case without measurement or process noise (w = 0,v = 0), for a set of plant initial states, the closed-loop systemconverges to a steady state and the feasible steady-state target isachieved leading to zero offset in the controlled variables.

Characterizing the set of initial states in the region of convergence,and stabilizing the system when the plant and the model differ, aretreated in Chapters 3 and 5 of (Rawlings and Mayne, 2009).

We conclude this section with a nonlinear example that demonstratesthe use of Lemma 4.

Freiburg 2015 Tracking, disturbances, offset 32 / 57

Page 33: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Exothermic chemical reaction

Example 5

We consider a well-stirred chemical reactor as in Pannocchia and Rawlings(2003). An irreversible, first-order reaction A−→ B occurs in the liquid

phase and the reactor temperature is regulated with external cooling.

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

F0,T0, c0

Tc

rF

h

T , c

Freiburg 2015 Tracking, disturbances, offset 33 / 57

Page 34: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Mass and energy balances

Mass and energy balances lead to the following nonlinear state spacemodel:

dc

dt=

F0(c0 − c)

πr2h− k0 exp

(− E

RT

)c

dT

dt=

F0(T0 − T )

πr2h+−∆H

ρCpk0 exp

(− E

RT

)c +

2U

rρCp(Tc − T )

dh

dt=

F0 − F

πr2

Freiburg 2015 Tracking, disturbances, offset 34 / 57

Page 35: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Steady-state operating point

The controlled variables are h, the level of the tank, and c , the molarconcentration of species A. The additional state variable is T , thereactor temperature

The manipulated variables are Tc , the coolant liquid temperature,and F , the outlet flowrate.

Moreover, it is assumed that the inlet flowrate acts as an unmeasureddisturbance.

The open-loop stable steady-state operating conditions are thefollowing:

cs = 0.878 kmol/m3 T s = 324.5K hs = 0.659m

T sc = 300K F s = 0.1m3/min

The model parameters in nominal conditions are reported in thefollowing table.

Freiburg 2015 Tracking, disturbances, offset 35 / 57

Page 36: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Plant parameter values

Parameter Nominal value Units

F0 0.1 m3/minT0 350 Kc0 1 kmol/m3

r 0.219 mk0 7.2× 1010 min−1

E/R 8750 KU 54.94 kJ/min·m2·Kρ 1000 kg/m3

Cp 0.239 kJ/kg·K∆H −5× 104 kJ/kmol

Freiburg 2015 Tracking, disturbances, offset 36 / 57

Page 37: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Using a sampling time of 1 min, a linearized discrete state space model is obtainedand, assuming that all the states are measured, the state space variables are:

x =

c − cs

T − T s

h − hs

u =

[Tc − T s

c

F − F s

]y =

c − cs

T − T s

h − hs

p = F0 − F s0

The corresponding linear model is:

x(k + 1) = Ax(k) + Bu(k) + Bpp

y(k) = Cx(k)

in which

A =

0.2681 −0.00338 −0.007289.703 0.3279 −25.44

0 0 1

C =

1 0 00 1 00 0 1

B =

−0.00537 0.16551.297 97.91

0 −6.637

Bp =

−0.117569.746.637

Freiburg 2015 Tracking, disturbances, offset 37 / 57

Page 38: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

a Since we have two inputs, Tc and F , we try to remove offset in twocontrolled variables, c and h. Model the disturbance with twointegrating output disturbances on the two controlled variables.Assume that the covariances of the state noises are zero except forthe two integrating states. Assume that the covariances of the threemeasurements’ noises are also zero.Notice that although there are only two controlled variables, thischoice of two integrating disturbances does not follow the prescriptionof Lemma 4 for zero offset.Simulate the response of the controlled system after a 10% increasein the inlet flowrate F0 at time t = 10min. Use the nonlineardifferential equations for the plant model. Do you have steady offsetin any of the outputs? Which ones?

Freiburg 2015 Tracking, disturbances, offset 38 / 57

Page 39: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

b Follow the prescription of Lemma 4 and choose a disturbance modelwith three integrating modes. Can you choose three integratingoutput disturbances for this plant? If so, prove it. If not, state whynot.

c Again choose a disturbance model with three integrating modes;choose two integrating output disturbances on the two controlledvariables. Choose one integrating input disturbance on the outletflowrate F . Is the augmented system detectable?Simulate again the response of the controlled system after a 10%increase in the inlet flowrate F0 at time t = 10min. Again use thenonlinear differential equations for the plant model. Do you havesteady offset in any of the outputs? Which ones?Compare and contrast the closed-loop performance for the design withtwo integrating disturbances and the design with three integratingdisturbances. Which control system do you recommend and why?

Freiburg 2015 Tracking, disturbances, offset 39 / 57

Page 40: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Solution—two integrating disturbances

Solutiona I Integrating disturbances are added to the two controlled variables (first

and third outputs) by choosing

Cd =

1 00 00 1

Bd = 0

I The results with two integrating disturbances are shown in the nextfigures.

I Notice that despite adding integrating disturbances to the twocontrolled variables, c and h, both of these controlled variables as wellas the third output, T , all display nonzero offset at steady state.

Freiburg 2015 Tracking, disturbances, offset 40 / 57

Page 41: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Controlled variables

Solution

0.87

0.9

0.93

0 5 10 15 20 25 30 35 40 45 50

c(k

mol

/m3)

315

320

325

330

0 5 10 15 20 25 30 35 40 45 50

T(K

)

0.6

0.66

0.72

0.78

0 5 10 15 20 25 30 35 40 45 50

h(m

)

time (min)

Figure 1: Three measured outputs versus time after a step change in inlet flowrate at10 minutes; nd = 2. Notice the steady-state offset in all three output variables.

Freiburg 2015 Tracking, disturbances, offset 41 / 57

Page 42: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Manipulated variables

Solution

294

296

298

300

302

0 5 10 15 20 25 30 35 40 45 50

Tc

(K)

0.096

0.1

0.104

0.108

0.112

0 5 10 15 20 25 30 35 40 45 50

F(m

3/m

in)

time (min)

Figure 2: Two manipulated inputs versus time after a step change in inlet flowrate at10 minutes; nd = 2.

Freiburg 2015 Tracking, disturbances, offset 42 / 57

Page 43: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Solution—third integrator at an output

Solutionb I A third integrating disturbance is added to the second output giving

Cd =

1 0 00 0 10 1 0

Bd = 0

I The augmented system is not detectable with this disturbance model!

The rank of[I−A −Bd

C Cd

]is only 5 instead of 6.

I The problem here is that the system level is itself an integrator, and wecannot distinguish h from the integrating disturbance added to h.

Freiburg 2015 Tracking, disturbances, offset 43 / 57

Page 44: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Solution—third integrator at an input

Solutionc I Next we try three integrating disturbances: two added to the two

controlled variables, and one added to the second manipulated variable

Cd =

1 0 00 0 00 1 0

Bd =

0 0 0.16550 0 97.910 0 −6.637

I The augmented system is detectable for this disturbance model.I The results for this choice of three integrating disturbances are shown

in the next figures. Notice that we have zero offset in the twocontrolled variables, c and h, and have successfully forced thesteady-state effect of the inlet flowrate disturbance entirely into thesecond output, T .

Freiburg 2015 Tracking, disturbances, offset 44 / 57

Page 45: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Controlled variables

Solution

0.865

0.87

0.875

0.88

0 5 10 15 20 25 30 35 40 45 50

c(k

mol

/m3)

324

326

328

0 5 10 15 20 25 30 35 40 45 50

T(K

)

0.64

0.68

0.72

0.76

0 5 10 15 20 25 30 35 40 45 50

h(m

)

time (min)

Figure 3: Three measured outputs versus time after a step change in inlet flowrate at10 minutes; nd = 3.

Freiburg 2015 Tracking, disturbances, offset 45 / 57

Page 46: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Manipulated variables

Solution

299

300

301

0 5 10 15 20 25 30 35 40 45 50

Tc

(K)

0.09

0.1

0.11

0.12

0 5 10 15 20 25 30 35 40 45 50

F(m

3/m

in)

time (min)

Figure 4: Two manipulated inputs versus time after a step change in inlet flowrate at10 minutes; nd = 3.

Freiburg 2015 Tracking, disturbances, offset 46 / 57

Page 47: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Solution

Notice also that the dynamic behavior of all three outputs is superiorto that achieved with the model using two integrating disturbances.

The true disturbance, which is a step at the inlet flowrate, is betterrepresented by including the integrator in the outlet flowrate. With amore accurate disturbance model, better overall control is achieved.

The controller uses smaller manipulated variable action and alsoachieves better output variable behavior.

An added bonus is that steady offset is removed in the maximumpossible number of outputs. �

Freiburg 2015 Tracking, disturbances, offset 47 / 57

Page 48: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Further reading I

E. J. Davison and H. W. Smith. Pole assignment in linear time-invariant multivariablesystems with constant disturbances. Automatica, 7:489–498, 1971.

E. J. Davison and H. W. Smith. A note on the design of industrial regulators: Integralfeedback and feedforward controllers. Automatica, 10:329–332, 1974.

B. A. Francis and W. M. Wonham. The internal model principle of control theory.Automatica, 12:457–465, 1976.

H. Kwakernaak and R. Sivan. Linear Optimal Control Systems. John Wiley and Sons,New York, 1972. ISBN 0-471-51110-2.

B. J. Odelson, M. R. Rajamani, and J. B. Rawlings. A new autocovariance least-squaresmethod for estimating noise covariances. Automatica, 42(2):303–308, February 2006.

G. Pannocchia and J. B. Rawlings. Disturbance models for offset-free MPC control.AIChE J., 49(2):426–437, 2003.

L. Qiu and E. J. Davison. Performance limitations of non-minimum phase systems in theservomechanism problem. Automatica, 29(2):337–349, 1993.

M. R. Rajamani, J. B. Rawlings, and S. J. Qin. Achieving state estimation equivalencefor misassigned disturbances in offset-free model predictive control. AIChE J., 55(2):396–407, February 2009.

J. B. Rawlings and D. Q. Mayne. Model Predictive Control: Theory and Design. NobHill Publishing, Madison, WI, 2009. 576 pages, ISBN 978-0-9759377-0-9.

Freiburg 2015 Tracking, disturbances, offset 48 / 57

Page 49: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Tracking, disturbances, and zero offset

Review

Freiburg 2015 Tracking, disturbances, offset 49 / 57

Page 50: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Lab Exercises

Exercise 1.56

Exercise 1.57

Exercise 1.58

Exercise 1.60

Reproduce Figure 4 of Rajamani, Rawlings, and Qin (2009)

Reproduce Figure 6 of Rajamani et al. (2009)

Freiburg 2015 Tracking, disturbances, offset 50 / 57

Page 51: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Computational Exercise

Reproduce the CSTR example in CasADi/Python.

0 10 20 30 40 500.8710.8720.8730.8740.8750.8760.8770.8780.879

c (m

ol/L

)

0 10 20 30 40 50324.5

325.0

325.5

326.0

T (K

)

0 10 20 30 40 50Time (min)

0.650.660.670.680.690.700.710.720.73

h (m

)

0 10 20 30 40 50299.0

299.5

300.0

300.5

301.0

Tc (K

)

0 10 20 30 40 50Time (min)

0.095

0.100

0.105

0.110

0.115

0.120

F (k

L/m

in)

Figure 5: CSTR example in CasADi/Python.

Freiburg 2015 Tracking, disturbances, offset 51 / 57

Page 52: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

mpc-tools-casadi

mpc-tools-casadi provides a collection of functions for solving MPCproblems using CasADi/Python.

Why?

Reduce coding effort for users solving MPC problems

Usage

import mpc_tools_casadi as mpc

# Turn model into CasADi function.

fcasadi = mpc.getCasadiFunc(f, Nx, Nu, Nd, name)

# Turn model into CasADi simulator.

fsim = mpc.OneStepSimulator(f, Delta, Nx, Nu, Nd)

Freiburg 2015 Tracking, disturbances, offset 52 / 57

Page 53: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

mpc-tools-casadi

mpc-tools-casadi provides a collection of functions for solving MPCproblems using CasADi/Python.

Why?

Reduce coding effort for users solving MPC problems

Usage

import mpc_tools_casadi as mpc

# Turn model into CasADi function.

fcasadi = mpc.getCasadiFunc(f, Nx, Nu, Nd, name)

# Turn model into CasADi simulator.

fsim = mpc.OneStepSimulator(f, Delta, Nx, Nu, Nd)

Freiburg 2015 Tracking, disturbances, offset 52 / 57

Page 54: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

mpc-tools-casadi

mpc-tools-casadi provides a collection of functions for solving MPCproblems using CasADi/Python.

Why?

Reduce coding effort for users solving MPC problems

Usage

import mpc_tools_casadi as mpc

# Turn model into CasADi function.

fcasadi = mpc.getCasadiFunc(f, Nx, Nu, Nd, name)

# Turn model into CasADi simulator.

fsim = mpc.OneStepSimulator(f, Delta, Nx, Nu, Nd)

Freiburg 2015 Tracking, disturbances, offset 52 / 57

Page 55: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Creating an Integrator

CasADi/Python

# Define symbolic variables.

x = casadi.MX.sym("x",Nx)

u = casadi.MX.sym("u",Nu)

# Make integrator object.

ode_integrator = casadi.MXFunction(

casadi.daeIn(x=x,p=u),

casadi.daeOut(ode=casadi.vertcat(

ode(x,u))))

vdp = casadi.Integrator("cvodes",

ode_integrator)

vdp.setOption("abstol",1e-8)

vdp.setOption("reltol",1e-8)

vdp.setOption("tf",Delta)

vdp.init()

mpc-tools-casadi

# Create a simulator.

vdp = mpc.OneStepSimulator(ode, Delta,

Nx, Nu)

Freiburg 2015 Tracking, disturbances, offset 53 / 57

Page 56: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Runge-Kutta Discretization

CasADi/Python

# Get nonlinear casadi functions

# and rk4 discretization.

ode_casadi = casadi.MXFunction(

[x,u],[casadi.vertcat(ode(x,u))])

ode_casadi.init()

[k1] = ode_casadi([x,u])

[k2] = ode_casadi([x + Delta/2*k1,u])

[k3] = ode_casadi([x + Delta/2*k2,u])

[k4] = ode_casadi([x + Delta*k3,u])

xrk4 = x + Delta/6*(k1+2*k2+2*k3+k4)

ode_rk4_casadi = casadi.MXFunction([x,u

],[xrk4])

ode_rk4_casadi.init()

mpc-tools-casadi

# Get nonlinear casadi functions

# and rk4 discretization.

ode_casadi = mpc.getCasadiFunc(ode,Nx,

Nu, name="f")

ode_rk4_casadi = mpc.getRungeKutta4(

ode_casadi, Delta)

Freiburg 2015 Tracking, disturbances, offset 54 / 57

Page 57: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Creating Optimizers

CasADi/Python

x0 = np.array([0,1])Nt = 20# Create variables struct.var = ctools.struct_symMX([(

ctools.entry("x",shape=(Nx,),repeat=Nt+1),ctools.entry("u",shape=(Nu,),repeat=Nt),)])

varlb = var(-np.inf)varub = var(np.inf)varguess = var(0)for t in range(Nt):

varlb["u",t,:] = ulbvarub["u",t,:] = uub

# Now build up constraints and objective.obj = casadi.MX(0)con = []for t in range(Nt):

con.append(ode_rk4_casadi([var["x",t],var["u",t]])[0] - var["x",t+1])

obj += l([var["x",t],var["u",t]])[0]obj += Pf([var["x",Nt]])[0]# Build solver object.con = casadi.vertcat(con)conlb = np.zeros((Nx*Nt,))conub = np.zeros((Nx*Nt,))nlp = casadi.MXFunction(casadi.nlpIn(x=var),

casadi.nlpOut(f=obj,g=con))solver = casadi.NlpSolver("ipopt",nlp)solver.setOption("print_level",0)solver.setOption("print_time",False)solver.setOption("max_cpu_time",60)solver.init()solver.setInput(conlb,"lbg")solver.setInput(conub,"ubg")

mpc-tools-casadi

# Make optimizers.x0 = np.array([0,1])Nt = 20solver = mpc.nmpc(F=[ode_rk4_casadi],N=Nt,

verbosity=0,l=[l],x0=x0,Pf=Pf,bounds=bounds,returnTimeInvariantSolver=True)

Freiburg 2015 Tracking, disturbances, offset 55 / 57

Page 58: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Fixing Initial States and Calling Solver

CasADi/Python

# Fix initial state.

varlb["x",0,:] = x[t,:]

varub["x",0,:] = x[t,:]

varguess["x",0,:] = x[t,:]

solver.setInput(varguess,"x0")

solver.setInput(varlb,"lbx")

solver.setInput(varub,"ubx")

# Solve nlp.

solver.evaluate()

status = solver.getStat("return_status"

)

optvar = var(solver.getOutput("x"))

mpc-tools-casadi

# Fix initial state.

solver.fixvar("x",0,x[t,:])

# Solve nlp.

sol = solver.solve()

Freiburg 2015 Tracking, disturbances, offset 56 / 57

Page 59: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

System Simulation

CasADi/Python

# Simulate.

vdp.setInput(x[t,:],"x0")

vdp.setInput(u[t,:],"p")

vdp.evaluate()

x[t+1,:] = np.array(vdp.getOutput("xf")

).flatten()

vdp.reset()

mpc-tools-casadi

# Simulate.

x[t+1,:] = vdp.sim(x[t,:],u[t,:])

Freiburg 2015 Tracking, disturbances, offset 57 / 57

Page 60: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Plotting Results

CasADi/Python

# Plots.fig = plt.figure()numrows = max(Nx,Nu)numcols = 2

# u plots.u = np.concatenate((u,u[-1:,:]))for i in range(Nu):

ax = fig.add_subplot(numrows,numcols,numcols*(i+1))

ax.step(times,u[:,i],"-k")ax.set_xlabel("Time")ax.set_ylabel("Control %d" % (i + 1))

# x plots.for i in range(Nx):

ax = fig.add_subplot(numrows,numcols,numcols*(i+1) - 1)

ax.plot(times,x[:,i],"-k",label="System")ax.set_xlabel("Time")ax.set_ylabel("State %d" % (i + 1))

fig.tight_layout(pad=.5)

mpc-tools-casadi

# Plots.mpc.mpcplot(x.T,u.T,times)

Freiburg 2015 Tracking, disturbances, offset 58 / 57

Page 61: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

General Tips for Computational Exercise

Remember that indexing is 0-based.

Use NumPy’s array instead of matrix.I Despite what Octave/Matlab says, everything is not a matrix of

doublesI Have to use A.dot(x) instead of A*xI However, indexing is MUCH easier with arrays

Use bmat([[A,B],[C,D]]).A to assemble matrices from blocks.I Equivalent to [A, B; C, D] in Octave/MatlabI Trailing .A casts back to array type from matrix

Use scipy.linalg.solve(A,b) to compute A−1b.

Freiburg 2015 Tracking, disturbances, offset 59 / 57

Page 62: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

System Model

Start by defining the system model as a Python function.

def ode(x,u,d):

# Grab the states, controls, and disturbance.

[c, T, h] = x[:Nx]

[Tc, F] = u[:Nu]

[F0] = d[:Nd]

# Now create the right-hand side function of the ODE.

rate = k0*c*np.exp(-E/T)

dxdt = [

F0*(c0 - c)/(np.pi*r**2*h) - rate,

F0*(T0 - T)/(np.pi*r**2*h)

- dH/(rho*Cp)*rate

+ 2*U/(r*rho*Cp)*(Tc - T),

(F0 - F)/(np.pi*r**2)

]

return dxdt

Freiburg 2015 Tracking, disturbances, offset 60 / 57

Page 63: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

System Simulation

The nonlinear system can be simulated using CasADi integrator objectswith a convenient wrapper.

# Turn model into CasADi function and simulator.

ode_casadi = mpc.getCasadiFunc(ode,Nx,Nu,Nd,name="ode")

cstr = mpc.OneStepSimulator(ode, Delta, Nx, Nu, Nd)

# Simulate with nonlinear model.

x[n+1,:] = cstr.sim(x[n,:] + xs, u[n,:] + us, d[n,:] + ds) - xs

Freiburg 2015 Tracking, disturbances, offset 61 / 57

Page 64: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Calls to LQR and LQE

The functions dlqr and dlqe are also provided in mpc-tools-casadi.

Octave/Matlab

% Get LQR.

[K, P, Epoles] = dlqr(A, B, Q, R);

% Get Kalman filter.

[L, M, P, Epoles] = dlqe(Aaug, eye(naug

), Caug, Qw, Rv);

Lx = L(1:n,:);

Ld = L(n+1:end,:);

CasADi/Python

# Get LQR.

[K, Pi] = mpc.dlqr(A,B,Q,R)

# Get Kalman filter.

[L, P] = mpc.dlqe(Aaug, Caug, Qw, Rv)

Lx = L[:Nx,:]

Ld = L[Nx:,:]

Freiburg 2015 Tracking, disturbances, offset 62 / 57

Page 65: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

Controller Simulation

Octave/Matlab

for i = 1: ntimes

% Take plant measurement.

y(:,i) = C*x(:,i) + v(:,i);

% Update state estimate with measurement.

ey = y(:,i) - C*xhat_(:,i) -Cd*dhat_(:,i);

xhat(:,i) = xhat_(:,i) + Lx*ey;

dhat(:,i) = dhat_(:,i) + Ld*ey;

% Steady-state target.

H = [1 0 0; 0 0 1];

G = [eye(n)-A, -B; H*C, zeros(size(H,1), m)];

qs = G\[Bd*dhat(:,i); H*(target.yset-Cd*dhat(:,i))];

xss = qs(1:n);

uss = qs(n+1:end);

% Regulator.

u(:,i) = K*(xhat(:,i) - xss) + uss;

if (i == ntimes) break; end

% Simulate with nonlinear model.

t = [time(i); mean(time(i:i+1)); time(i+1)];

z0 = x(:,i) + zs; F0 = p(:,i) + Fs;

Tc = u(1,i) + Tcs; F = u(2,i) + Fs;

[tout, z] = ode15s (@massenbal, t, z0, options);

x(:,i+1) = z(end,:)' - zs;

% Advance state estimate.

xhat_(:,i+1) = A*xhat(:,i) + Bd*dhat(:,i) + B*u(:,i);

dhat_(:,i+1) = dhat(:,i);

end

CasADi/Python

for n in range(Nsim + 1):

# Take plant measurement.

y[n,:] = C.dot(x[n,:]) + v[n,:]

# Update state estimate with measurement.

err[n,:] = y[n,:] - C.dot(xhatm[n,:]) - Cd.dot(dhatm[n,:])

xhat[n,:] = xhatm[n,:] + Lx.dot(err[n,:])

dhat[n,:] = dhatm[n,:] + Ld.dot(err[n,:])

# Make sure we aren't at the last timestep.

if n == Nsim: break

# Steady-state target.

rhs = np.concatenate((Bd.dot(dhat[n,:]), H.dot(ysp[n,:] -

Cd.dot(dhat[n,:]))))

qsp = linalg.solve(G,rhs) # Similar to "G\rhs" in Matlab.

xsp = qsp[:Nx]

usp = qsp[Nx:]

# Regulator.

u[n,:] = K.dot(xhat[n,:] - xsp) + usp

# Simulate with nonlinear model.

x[n+1,:] = cstr.sim(x[n,:] + xs, u[n,:] + us, d[n,:] + ds)

- xs

# Advance state estimate.

xhatm[n+1,:] = A.dot(xhat[n,:]) + Bd.dot(dhat[n,:]) + B.dot

(u[n,:])

dhatm[n+1,:] = dhat[n,:]

Freiburg 2015 Tracking, disturbances, offset 63 / 57

Page 66: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

82 Getting Started with Model Predictive Control

Exercise 1.54: Where is the steady state?

Consider the two-input, two-output system

A =

0.5 0 0 00 0.6 0 00 0 0.5 00 0 0 0.6

B =

0.5 00 0.4

0.25 00 0.6

C =[

1 1 0 00 0 1 1

]

(a) The output setpoint is ysp =[1 −1

]′and the input setpoint is usp =

[0 0

]′.

Calculate the target triple (xs , us , ys). Is the output setpoint feasible, i.e., doesys = ysp?

(b) Assume only input oneu1 is available for control. Is the output setpoint feasible?What is the target in this case using Qs = I?

(c) Assume both inputs are available for control but only the first output has asetpoint, y1t = 1. What is the solution to the target problem for Rs = I?

Exercise 1.55: Detectability of integrating disturbance models

(a) Prove Lemma 1.8; the augmented system is detectable if and only if the system(A,C) is detectable and

rank

[I −A −BdC Cd

]= n+nd

(b) Prove Corollary 1.9; the augmented system is detectable only if nd ≤ p.

Exercise 1.56: Unconstrained tracking problem

(a) For an unconstrained system, show that the following condition is sufficient forfeasibility of the target problem for any rsp.

rank

[I −A −BHC 0

]= n+nc (1.69)

(b) Show that (1.69) implies that the number of controlled variables without offsetis less than or equal to the number of manipulated variables and the number ofmeasurements, nc ≤m and nc ≤ p.

(c) Show that (1.69) implies the rows of H are independent.

(d) Does (1.69) imply that the rows of C are independent? If so, prove it; if not,provide a counterexample.

(e) By choosingH, how can one satisfy (1.69) if one has installed redundant sensorsso several rows of C are identical?

Exercise 1.57: Unconstrained tracking problem for stabilizable systems

If we restrict attention to stabilizable systems, the sufficient condition of Exercise 1.56becomes a necessary and sufficient condition. Prove the following lemma.

Page 67: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

1.6 Exercises 83

Lemma 1.14 (Stabilizable systems and feasible targets). Consider an unconstrained,stabilizable system (A, B). The target is feasible for any rsp if and only if

rank

[I −A −BHC 0

]= n+nc

Exercise 1.58: Existence and uniqueness of the unconstrained target

Assume a system having p controlled variables z = Hx, with setpoints rsp, and mmanipulated variables u, with setpoints usp. Consider the steady-state target problem

minx,u(1/2)(u−usp)′R(u−usp) R > 0

subject to [I −A −BH 0

][xu

]=[

0rsp

]Show that the steady-state solution (x,u) exists for any (rsp, usp) and is unique if

rank

[I −A −BH 0

]= n+ p rank

[I −AH

]= n

Exercise 1.59: Choose a sample time

Consider the unstable continuous time system

dxdt= Ax + Bu y = Cx

in which

A =

−0.281 0.935 0.035 0.0080.047 −0.116 0.053 0.3830.679 0.519 0.030 0.0670.679 0.831 0.671 −0.083

B =

0.6870.5890.9300.846

C = I

Consider regulator tuning parameters and constraints

Q = diag(1,2,1,2) R = 1 N = 10 |x| ≤

1213

(a) Compute the eigenvalues of A. Choose a sample time of ∆ = 0.04 and simulate

the MPC regulator response given x(0) =[−0.9 −1.8 0.7 2

]′until t = 20.

Use an ODE solver to simulate the continuous time plant response. Plot all statesand the input versus time.

Now add an input disturbance to the regulator so the control applied to the plantis ud instead of u in which

ud(k) = (1+ 0.1w1)u(k)+ 0.1w2

and w1 and w2 are zero mean, normally distributed random variables with unitvariance. Simulate the regulator’s performance given this disturbance. Plot allstates and ud(k) versus time.

Page 68: Tracking, disturbances and zero o setstatic.syscop.de/mpc-short-course-website/together_all.pdfOutline 1 Setpoint Tracking Deviation variables 2 Steady-state target problem 3 Dynamic

84 Getting Started with Model Predictive Control

u

d

ysp ygc g

Figure 1.13: Feedback control system with output disturbance d,and setpoint ysp.

(b) Repeat the simulations with and without disturbance for ∆ = 0.4 and ∆ = 2.

(c) Compare the simulations for the different sample times. What happens if thesample time is too large? Choose an appropriate sample time for this systemand justify your choice.

Exercise 1.60: Disturbance models and offset

Consider the following two-input, three-output plant discussed in Example 1.11

x+ = Ax + Bu+ Bppy = Cx

in which

A =

0.2681 −0.00338 −0.007289.703 0.3279 −25.44

0 0 1

C =

1 0 00 1 00 0 1

B =

−0.00537 0.16551.297 97.91

0 −6.637

Bp =

−0.117569.746.637

The input disturbance p results from a reactor inlet flowrate disturbance.

(a) Since there are two inputs, choose two outputs in which to remove steady-stateoffset. Build an output disturbance model with two integrators. Is your aug-mented model detectable?

(b) Implement your controller using p = 0.01 as a step disturbance at k = 0. Do youremove offset in your chosen outputs? Do you remove offset in any outputs?

(c) Can you find any two-integrator disturbance model that removes offset in twooutputs? If so, which disturbance model do you use? If not, why not?

Exercise 1.61: MPC, PID and time delay

Consider the following first-order system with time delay shown in Figure 1.13

g(s) = kτs + 1

e−θs , k = 1, τ = 1, θ = 5

Consider a unit step change in setpoint ysp, at t = 0.