Examples.ACADOSMPCTunableMassExample ​
Regulation of a heavy pendulum to its hanging position, with the mass of the prediction model left tunable. tunable_parameters = ["m"] keeps the plant parameter m symbolic in the compiled solver, so that it becomes the online parameter of the acados model and its value is the ordinary parameter mpc.p_values, by default the mass the plant carries. Building the problem with [ssys.mpc.p_values => [1.0]] therefore hands the controller a model three times too light without rebuilding it: it predicts the torque to be three times as effective as it is, commands a visibly different torque, and realizes a higher closed-loop cost than the matched default. Verified in test/test_acados_mpc.jl.
Usage ​
MPCComponents.Examples.ACADOSMPCTunableMassExample()
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 ​
"""
Regulation of a heavy pendulum to its hanging position, with the mass of the prediction model left
tunable. `tunable_parameters = ["m"]` keeps the plant parameter `m` symbolic in the compiled solver,
so that it becomes the online parameter of the acados model and its value is the ordinary parameter
`mpc.p_values`, by default the mass the plant carries. Building the problem with
`[ssys.mpc.p_values => [1.0]]` therefore hands the controller a model three times too light without
rebuilding it: it predicts the torque to be three times as effective as it is, commands a visibly
different torque, and realizes a higher closed-loop cost than the matched default. Verified in
`test/test_acados_mpc.jl`.
"""
example component ACADOSMPCTunableMassExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
"Dyad": {"placement": {"diagram": {"x1": 150, "y1": 200, "x2": 50, "y2": 300}}}
}
plant = MPCComponents.Examples.ACADOSPendulumPlant(m = 3.0, theta0 = 0.7853981633974483) {
"Dyad": {"placement": {"diagram": {"x1": 700, "y1": 300, "x2": 800, "y2": 400}}}
}
s1 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 570, "x2": 600, "y2": 670, "rot": 180}}
}
}
s2 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 450, "x2": 600, "y2": 550, "rot": 180}}
}
}
zoh = DiscreteComponents.ZeroOrderHold() {
"Dyad": {"placement": {"diagram": {"x1": 500, "y1": 300, "x2": 600, "y2": 400}}}
}
mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["tau"], tunable_parameters = ["m"], state_variables = ["th", "om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 40, Q1 = diagonal([10.0, 1.0]), Q2 = diagonal([0.1]), umin = [-25.0], umax = [25.0], reference_tracking = false) {
"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) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 880, "y": 335}, {"x": 880, "y": 620}], "E": 2}],
"path": {}
}
}
connect(plant.omega, s2.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 830, "y": 365}, {"x": 830, "y": 500}], "E": 2}],
"path": {}
}
}
connect(s1.y, mpc.x[1], periodicclock.y) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 260, "y": 620}, {"x": 260, "y": 350}], "E": 2},
{"S": 2, "M": [{"x": 260, "y": 350}, {"x": 260, "y": 250}], "E": 3}
],
"path": {}
}
}
connect(s2.y, mpc.x[2]) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 280, "y": 500}, {"x": 280, "y": 350}], "E": 2}],
"path": {}
}
}
connect(mpc.u[1], zoh.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 450, "y": 373}, {"x": 450, "y": 350}], "E": 2}],
"path": {}
}
}
metadata {"Dyad": {"doc": {"behavior": false}}}
endFlattened Source
"""
Regulation of a heavy pendulum to its hanging position, with the mass of the prediction model left
tunable. `tunable_parameters = ["m"]` keeps the plant parameter `m` symbolic in the compiled solver,
so that it becomes the online parameter of the acados model and its value is the ordinary parameter
`mpc.p_values`, by default the mass the plant carries. Building the problem with
`[ssys.mpc.p_values => [1.0]]` therefore hands the controller a model three times too light without
rebuilding it: it predicts the torque to be three times as effective as it is, commands a visibly
different torque, and realizes a higher closed-loop cost than the matched default. Verified in
`test/test_acados_mpc.jl`.
"""
example component ACADOSMPCTunableMassExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
"Dyad": {"placement": {"diagram": {"x1": 150, "y1": 200, "x2": 50, "y2": 300}}}
}
plant = MPCComponents.Examples.ACADOSPendulumPlant(m = 3.0, theta0 = 0.7853981633974483) {
"Dyad": {"placement": {"diagram": {"x1": 700, "y1": 300, "x2": 800, "y2": 400}}}
}
s1 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 570, "x2": 600, "y2": 670, "rot": 180}}
}
}
s2 = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {"diagram": {"x1": 500, "y1": 450, "x2": 600, "y2": 550, "rot": 180}}
}
}
zoh = DiscreteComponents.ZeroOrderHold() {
"Dyad": {"placement": {"diagram": {"x1": 500, "y1": 300, "x2": 600, "y2": 400}}}
}
mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["tau"], tunable_parameters = ["m"], state_variables = ["th", "om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 40, Q1 = diagonal([10.0, 1.0]), Q2 = diagonal([0.1]), umin = [-25.0], umax = [25.0], reference_tracking = false) {
"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) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 880, "y": 335}, {"x": 880, "y": 620}], "E": 2}],
"path": {}
}
}
connect(plant.omega, s2.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 830, "y": 365}, {"x": 830, "y": 500}], "E": 2}],
"path": {}
}
}
connect(s1.y, mpc.x[1], periodicclock.y) {
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 260, "y": 620}, {"x": 260, "y": 350}], "E": 2},
{"S": 2, "M": [{"x": 260, "y": 350}, {"x": 260, "y": 250}], "E": 3}
],
"path": {}
}
}
connect(s2.y, mpc.x[2]) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 280, "y": 500}, {"x": 280, "y": 350}], "E": 2}],
"path": {}
}
}
connect(mpc.u[1], zoh.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 450, "y": 373}, {"x": 450, "y": 350}], "E": 2}],
"path": {}
}
}
metadata {"Dyad": {"doc": {"behavior": false}}}
endTest Cases ​
No test cases defined.
Related ​
Examples
Experiments
Analyses