Skip to content
LIBRARY
Examples.LinearMPCRegulationExample.md

Examples.LinearMPCRegulationExample ​

Regulation of a double integrator to the origin with LinearMPCOptimizer as a state-feedback MPC: both plant states are sampled and fed to xhat, the control is held with a zero-order hold. Exercises reference_tracking = false, input bounds, a control-increment penalty Q3 and the LQR terminal cost. The plant is continuous, so the sampled loop is exactly the discrete model the controller is built from.

Usage ​

MPCComponents.Examples.LinearMPCRegulationExample()

Parameters: ​

NameDescriptionUnitsDefault value
ctrlMPC object shared by the components of the controller–build_linea..._cost=true)

Variables ​

NameDescriptionUnits
y1Position–
u1Control signal–

Behavior ​

Behavior of this component cannot be rendered because it includes path variables.

Source ​

dyad
"""
Regulation of a double integrator to the origin with `LinearMPCOptimizer` as a state-feedback
MPC: both plant states are sampled and fed to `xhat`, the control is held with a zero-order
hold. Exercises `reference_tracking = false`, input bounds, a control-increment penalty `Q3`
and the LQR terminal cost. The plant is continuous, so the sampled loop is exactly the discrete
model the controller is built from.
"""
example component LinearMPCRegulationExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
  vel = BlockComponents.Continuous.Integrator(x0 = 0.0) {}
  pos = BlockComponents.Continuous.Integrator(x0 = 1.0) {}
  s1 = DiscreteComponents.Sampler() {}
  s2 = DiscreteComponents.Sampler() {}
  zoh = DiscreteComponents.ZeroOrderHold() {}
  mpc = MPCComponents.LinearMPCOptimizer(mpc = ctrl) {}
  "MPC object shared by the components of the controller"
  structural parameter ctrl::MPCComponents.MPCRef = build_linear_mpc(A = [[1.0, 0.1], [0.0, 1.0]], B = [[0.005], [0.1]], Q1 = [1.0, 0.1], Q2 = [0.1], Q3 = [0.05], umin = [-1.0], umax = [1.0], Np = 10, reference_tracking = false, terminal_lqr_cost = true)
  "Position"
  variable y1::Real
  "Control signal"
  variable u1::Real
relations
  y1 = pos.y
  u1 = mpc.u[1]
  connect(zoh.y, vel.u)
  connect(vel.y, pos.u, s2.u)
  connect(pos.y, s1.u)
  connect(s1.y, mpc.xhat[1], periodicclock.y)
  connect(s2.y, mpc.xhat[2])
  connect(mpc.u[1], zoh.u)
metadata {"Dyad": {"tests": {"case1": {"stop": 5}}, "doc": {"behavior": false}}}
end
Flattened Source
dyad
"""
Regulation of a double integrator to the origin with `LinearMPCOptimizer` as a state-feedback
MPC: both plant states are sampled and fed to `xhat`, the control is held with a zero-order
hold. Exercises `reference_tracking = false`, input bounds, a control-increment penalty `Q3`
and the LQR terminal cost. The plant is continuous, so the sampled loop is exactly the discrete
model the controller is built from.
"""
example component LinearMPCRegulationExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
  vel = BlockComponents.Continuous.Integrator(x0 = 0.0) {}
  pos = BlockComponents.Continuous.Integrator(x0 = 1.0) {}
  s1 = DiscreteComponents.Sampler() {}
  s2 = DiscreteComponents.Sampler() {}
  zoh = DiscreteComponents.ZeroOrderHold() {}
  mpc = MPCComponents.LinearMPCOptimizer(mpc = ctrl) {}
  "MPC object shared by the components of the controller"
  structural parameter ctrl::MPCComponents.MPCRef = build_linear_mpc(A = [[1.0, 0.1], [0.0, 1.0]], B = [[0.005], [0.1]], Q1 = [1.0, 0.1], Q2 = [0.1], Q3 = [0.05], umin = [-1.0], umax = [1.0], Np = 10, reference_tracking = false, terminal_lqr_cost = true)
  "Position"
  variable y1::Real
  "Control signal"
  variable u1::Real
relations
  y1 = pos.y
  u1 = mpc.u[1]
  connect(zoh.y, vel.u)
  connect(vel.y, pos.u, s2.u)
  connect(pos.y, s1.u)
  connect(s1.y, mpc.xhat[1], periodicclock.y)
  connect(s2.y, mpc.xhat[2])
  connect(mpc.u[1], zoh.u)
metadata {"Dyad": {"tests": {"case1": {"stop": 5}}, "doc": {"behavior": false}}}
end


Test Cases ​

Test Case case1 ​

  • Examples

  • Experiments

  • Analyses