LIBRARY
Examples.ACADOSMPCTerminalSetExample ​
Upright stabilization of the pendulum with ACADOSMPC pairing a terminal LQR cost with a terminal set: the terminal weight is the infinite-horizon LQR cost linearized at the upright operating_point terminal_constrained = ["theta", "omega"]), softened so the problem stays solvable while the pendulum swings up into the set from test/test_acados_mpc.jl.
Usage ​
MPCComponents.Examples.ACADOSMPCTerminalSetExample()
Variables ​
| Name | Description | Units |
|---|---|---|
theta | Angle | – |
u1 | Torque | – |
flag | acados status | – |
Behavior ​
Behavior of this component cannot be rendered because it includes path variables.
Source ​
dyad
"""
Upright stabilization of the pendulum with `ACADOSMPC` pairing a terminal LQR cost with a terminal
set: the terminal weight is the infinite-horizon LQR cost linearized at the upright `operating_point`
``(\\pi, 0)``, and the terminal state is additionally confined to a small neighborhood of upright
(`terminal_constrained = ["theta", "omega"]`), softened so the problem stays solvable while the
pendulum swings up into the set from ``\\theta_0 = \\pi - 0.4``. The reference is the upright state.
Verified in `test/test_acados_mpc.jl`.
"""
example component ACADOSMPCTerminalSetExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 100, "x2": 400, "y2": 200}}}
}
plant = MPCComponents.Examples.ACADOSPendulumPlant(theta0 = 2.741592653589793) {
"Dyad": {"placement": {"diagram": {"x1": 700, "y1": 300, "x2": 800, "y2": 400}}}
}
s1 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 500, "x2": 600, "y2": 600, "rot": 180}}
}
}
s2 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 650, "x2": 600, "y2": 750, "rot": 180}}
}
}
zoh = DiscreteComponents.ZeroOrderHold() {
"Dyad": {"placement": {"diagram": {"x1": 500, "y1": 300, "x2": 600, "y2": 400}}}
}
rpi = BlockComponents.Sources.Constant(k = 3.141592653589793) {
"Dyad": {"placement": {"diagram": {"x1": -100, "y1": 250, "x2": 0, "y2": 350}}}
}
rzero = BlockComponents.Sources.Constant(k = 0.0) {
"Dyad": {"placement": {"diagram": {"x1": -100, "y1": 550, "x2": 0, "y2": 650}}}
}
mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["tau"], state_variables = ["th", "om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 50, Q1 = diagonal([10.0, 1.0]), Q2 = diagonal([0.5]), umin = [-6.0], umax = [6.0], terminal_lqr_cost = true, operating_point = [3.141592653589793, 0.0], terminal_constrained = ["theta", "omega"], terminal_constrained_min = [2.941592653589793, -0.8], terminal_constrained_max = [3.341592653589793, 0.8], terminal_constraints_soft = true) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 400, "y2": 400}}}
}
"Angle"
variable theta::Real
"Torque"
variable u1::Real
"acados status"
variable flag::Real
relations
theta = plant.theta
u1 = mpc.u[1]
flag = mpc.exitflag
connect(zoh.y, plant.tau)
connect(plant.theta, s1.u)
connect(plant.omega, s2.u)
connect(rpi.y, mpc.r[1])
connect(rzero.y, mpc.r[2])
connect(s1.y, mpc.x[1], periodicclock.y)
connect(s2.y, mpc.x[2])
connect(mpc.u[1], zoh.u)
metadata {"Dyad": {"doc": {"behavior": false}}}
endFlattened Source
dyad
"""
Upright stabilization of the pendulum with `ACADOSMPC` pairing a terminal LQR cost with a terminal
set: the terminal weight is the infinite-horizon LQR cost linearized at the upright `operating_point`
``(\\pi, 0)``, and the terminal state is additionally confined to a small neighborhood of upright
(`terminal_constrained = ["theta", "omega"]`), softened so the problem stays solvable while the
pendulum swings up into the set from ``\\theta_0 = \\pi - 0.4``. The reference is the upright state.
Verified in `test/test_acados_mpc.jl`.
"""
example component ACADOSMPCTerminalSetExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 100, "x2": 400, "y2": 200}}}
}
plant = MPCComponents.Examples.ACADOSPendulumPlant(theta0 = 2.741592653589793) {
"Dyad": {"placement": {"diagram": {"x1": 700, "y1": 300, "x2": 800, "y2": 400}}}
}
s1 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 500, "x2": 600, "y2": 600, "rot": 180}}
}
}
s2 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 650, "x2": 600, "y2": 750, "rot": 180}}
}
}
zoh = DiscreteComponents.ZeroOrderHold() {
"Dyad": {"placement": {"diagram": {"x1": 500, "y1": 300, "x2": 600, "y2": 400}}}
}
rpi = BlockComponents.Sources.Constant(k = 3.141592653589793) {
"Dyad": {"placement": {"diagram": {"x1": -100, "y1": 250, "x2": 0, "y2": 350}}}
}
rzero = BlockComponents.Sources.Constant(k = 0.0) {
"Dyad": {"placement": {"diagram": {"x1": -100, "y1": 550, "x2": 0, "y2": 650}}}
}
mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["tau"], state_variables = ["th", "om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 50, Q1 = diagonal([10.0, 1.0]), Q2 = diagonal([0.5]), umin = [-6.0], umax = [6.0], terminal_lqr_cost = true, operating_point = [3.141592653589793, 0.0], terminal_constrained = ["theta", "omega"], terminal_constrained_min = [2.941592653589793, -0.8], terminal_constrained_max = [3.341592653589793, 0.8], terminal_constraints_soft = true) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 400, "y2": 400}}}
}
"Angle"
variable theta::Real
"Torque"
variable u1::Real
"acados status"
variable flag::Real
relations
theta = plant.theta
u1 = mpc.u[1]
flag = mpc.exitflag
connect(zoh.y, plant.tau)
connect(plant.theta, s1.u)
connect(plant.omega, s2.u)
connect(rpi.y, mpc.r[1])
connect(rzero.y, mpc.r[2])
connect(s1.y, mpc.x[1], periodicclock.y)
connect(s2.y, mpc.x[2])
connect(mpc.u[1], zoh.u)
metadata {"Dyad": {"doc": {"behavior": false}}}
endTest Cases ​
No test cases defined.
Related ​
Examples
Experiments
Analyses