Skip to content
LIBRARY
Examples.LinearMPCIntroExample.md

Examples.LinearMPCIntroExample ​

Reference tracking with LinearMPCController on the double integrator DoubleIntegratorPlant. Only the position is measured; the velocity is estimated by the Kalman filter of the controller. The prediction model is obtained by linearizing the plant (dynamics = plant). The cost penalizes the tracking error of the position and the increments of the force, the force is limited to    and the velocity to    through a general linear constraint on the state. The position reference steps from 0 to 1 at t = 1.

Verified in test/test_mpc.jl.

Usage ​

MPCComponents.Examples.LinearMPCIntroExample()

Variables ​

NameDescriptionUnits
positionPosition–
velocityVelocity–
forceForce–
velocity_estimateVelocity estimated by the controller–
flagExit flag of the QP solver–

Behavior ​

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

Source ​

dyad
"""
Reference tracking with `LinearMPCController` on the double integrator `DoubleIntegratorPlant`. Only
the position is measured; the velocity is estimated by the Kalman filter of the controller. The
prediction model is obtained by linearizing the plant (`dynamics = plant`). The cost penalizes the
tracking error of the position and the increments of the force, the force is limited to
``|u| \\le 1`` and the velocity to ``|v| \\le 0.5`` through a general linear constraint on the state.
The position reference steps from 0 to 1 at t = 1.

Verified in `test/test_mpc.jl`.
"""
example component LinearMPCIntroExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
  plant = MPCComponents.Examples.DoubleIntegratorPlant() {}
  ref = BlockComponents.Sources.Step(height = 1.0, start_time = 1.0) {}
  sy = DiscreteComponents.Sampler() {}
  sr = DiscreteComponents.Sampler() {}
  zoh = DiscreteComponents.ZeroOrderHold() {}
  mpc = MPCComponents.LinearMPCController(dynamics = plant, inputs = ["u"], outputs = ["position"], state_variables = ["x", "v"], Ts = 0.1, Np = 30, Q1 = [1.0], Q3 = [0.1], umin = [-1.0], umax = [1.0], Ax = [[0.0, 1.0]], lb = [-0.5], ub = [0.5], R1 = [1e-4, 1e-2], R2 = [1e-4]) {}
  "Position"
  variable position::Real
  "Velocity"
  variable velocity::Real
  "Force"
  variable force::Real
  "Velocity estimated by the controller"
  variable velocity_estimate::Real
  "Exit flag of the QP solver"
  variable flag::Real
relations
  position = plant.position
  velocity = plant.velocity
  force = zoh.y
  velocity_estimate = mpc.xhat[2]
  flag = mpc.exitflag
  connect(plant.position, sy.u)
  connect(sy.y, mpc.y[1], periodicclock.y)
  connect(ref.y, sr.u)
  connect(sr.y, mpc.r[1])
  connect(mpc.u[1], zoh.u)
  connect(zoh.y, plant.u)
metadata {"Dyad": {"tests": {"case1": {"stop": 10}}, "doc": {"behavior": false}}}
end
Flattened Source
dyad
"""
Reference tracking with `LinearMPCController` on the double integrator `DoubleIntegratorPlant`. Only
the position is measured; the velocity is estimated by the Kalman filter of the controller. The
prediction model is obtained by linearizing the plant (`dynamics = plant`). The cost penalizes the
tracking error of the position and the increments of the force, the force is limited to
``|u| \\le 1`` and the velocity to ``|v| \\le 0.5`` through a general linear constraint on the state.
The position reference steps from 0 to 1 at t = 1.

Verified in `test/test_mpc.jl`.
"""
example component LinearMPCIntroExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
  plant = MPCComponents.Examples.DoubleIntegratorPlant() {}
  ref = BlockComponents.Sources.Step(height = 1.0, start_time = 1.0) {}
  sy = DiscreteComponents.Sampler() {}
  sr = DiscreteComponents.Sampler() {}
  zoh = DiscreteComponents.ZeroOrderHold() {}
  mpc = MPCComponents.LinearMPCController(dynamics = plant, inputs = ["u"], outputs = ["position"], state_variables = ["x", "v"], Ts = 0.1, Np = 30, Q1 = [1.0], Q3 = [0.1], umin = [-1.0], umax = [1.0], Ax = [[0.0, 1.0]], lb = [-0.5], ub = [0.5], R1 = [1e-4, 1e-2], R2 = [1e-4]) {}
  "Position"
  variable position::Real
  "Velocity"
  variable velocity::Real
  "Force"
  variable force::Real
  "Velocity estimated by the controller"
  variable velocity_estimate::Real
  "Exit flag of the QP solver"
  variable flag::Real
relations
  position = plant.position
  velocity = plant.velocity
  force = zoh.y
  velocity_estimate = mpc.xhat[2]
  flag = mpc.exitflag
  connect(plant.position, sy.u)
  connect(sy.y, mpc.y[1], periodicclock.y)
  connect(ref.y, sr.u)
  connect(sr.y, mpc.r[1])
  connect(mpc.u[1], zoh.u)
  connect(zoh.y, plant.u)
metadata {"Dyad": {"tests": {"case1": {"stop": 10}}, "doc": {"behavior": false}}}
end


Test Cases ​

Test Case case1 ​

  • Examples

  • Experiments

  • Analyses