Examples.ACADOSMPCTrimTorqueExample ​
Regulation of the pendulum with the torque penalty centered on a trim torque. The linear control cost eu = -q2 u_trim of ACADOSMPC turns the penalty ½ q2 u² into ½ q2 (u - u_trim)² up to a constant, so the controller trades the angle against the deviation of the torque from u_trim and holds the pendulum at a deflection where both are nonzero. The control weight and the linear cost are bound to the parameters q2 and u_trim of this component, so they reach the solver as parameters of the compiled problem: they can be changed without rebuilding the controller, and u_trim = 0 recovers regulation to the hanging position. Verified in test/test_acados_mpc.jl.
Usage ​
MPCComponents.Examples.ACADOSMPCTrimTorqueExample(q2=0.1, u_trim=2.0)
Parameters: ​
| Name | Description | Units | Default value |
|---|---|---|---|
q2 | Weight of the torque penalty | – | 0.1 |
u_trim | Torque the penalty is centered on | – | 2.0 |
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 the pendulum with the torque penalty centered on a trim torque. The linear control cost
`eu = -q2 u_trim` of `ACADOSMPC` turns the penalty `½ q2 u²` into `½ q2 (u - u_trim)²` up to a
constant, so the controller trades the angle against the deviation of the torque from `u_trim` and
holds the pendulum at a deflection where both are nonzero. The control weight and the linear cost are
bound to the parameters `q2` and `u_trim` of this component, so they reach the solver as parameters of
the compiled problem: they can be changed without rebuilding the controller, and `u_trim = 0` recovers
regulation to the hanging position. Verified in `test/test_acados_mpc.jl`.
"""
example component ACADOSMPCTrimTorqueExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
"Dyad": {"placement": {"diagram": {"x1": 150, "y1": 200, "x2": 50, "y2": 300}}}
}
plant = MPCComponents.Examples.ACADOSPendulumPlant() {
"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"], state_variables = ["th", "om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 20, Q1 = diagonal([10.0, 1.0]), final Q2 = diagonal([q2]), final eu = [-q2 * u_trim], umin = [-5.0], umax = [5.0], reference_tracking = false) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 400, "y2": 400}}}
}
"Weight of the torque penalty"
parameter q2::Real = 0.1
"Torque the penalty is centered on"
parameter u_trim::Real = 2.0
"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 the pendulum with the torque penalty centered on a trim torque. The linear control cost
`eu = -q2 u_trim` of `ACADOSMPC` turns the penalty `½ q2 u²` into `½ q2 (u - u_trim)²` up to a
constant, so the controller trades the angle against the deviation of the torque from `u_trim` and
holds the pendulum at a deflection where both are nonzero. The control weight and the linear cost are
bound to the parameters `q2` and `u_trim` of this component, so they reach the solver as parameters of
the compiled problem: they can be changed without rebuilding the controller, and `u_trim = 0` recovers
regulation to the hanging position. Verified in `test/test_acados_mpc.jl`.
"""
example component ACADOSMPCTrimTorqueExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
"Dyad": {"placement": {"diagram": {"x1": 150, "y1": 200, "x2": 50, "y2": 300}}}
}
plant = MPCComponents.Examples.ACADOSPendulumPlant() {
"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"], state_variables = ["th", "om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 20, Q1 = diagonal([10.0, 1.0]), final Q2 = diagonal([q2]), final eu = [-q2 * u_trim], umin = [-5.0], umax = [5.0], reference_tracking = false) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 400, "y2": 400}}}
}
"Weight of the torque penalty"
parameter q2::Real = 0.1
"Torque the penalty is centered on"
parameter u_trim::Real = 2.0
"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