LIBRARY
Examples.CartPoleIncrementMPCExample ​
The cart-pole example of the DyadControlSystems generic-MPC documentation ("Getting started"): all four state variables start at 1 and are regulated to the origin with Q1 = I, Q2 = 0.1, a penalty Q3 = 0.1 on the force increments, the force bounded to ±3 and the pendulum angular velocity to ±4 (soft here, where the tutorial's stage constraint is hard). The tutorial's LQR-based terminal cost is replaced by the default Qf = Q1. Verified in test/test_acados_tutorials.jl.
Usage ​
MPCComponents.Examples.CartPoleIncrementMPCExample()
Variables ​
| Name | Description | Units |
|---|---|---|
pos | Cart position | – |
theta | Pendulum angle | – |
omega | Pendulum angular velocity | – |
u1 | Force | – |
flag | acados status | – |
Behavior ​
Source ​
dyad
"""
The cart-pole example of the DyadControlSystems generic-MPC documentation ("Getting started"): all four
state variables start at 1 and are regulated to the origin with `Q1 = I`, `Q2 = 0.1`, a penalty
`Q3 = 0.1` on the force increments, the force bounded to ±3 and the pendulum angular velocity to ±4
(soft here, where the tutorial's stage constraint is hard). The tutorial's LQR-based terminal cost is
replaced by the default `Qf = Q1`. Verified in `test/test_acados_tutorials.jl`.
"""
example component CartPoleIncrementMPCExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
plant = MPCComponents.Examples.CartPolePlant(p0 = 1.0, th0 = 1.0, v0 = 1.0, w0 = 1.0) {}
"Samplers of the four state variables"
s = [DiscreteComponents.Sampler() for i in 1:4] {}
zoh = DiscreteComponents.ZeroOrderHold() {}
mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["F"], state_variables = ["p", "th", "v", "w"], outputs = ["p", "th", "v", "w"], Ts = 0.1, Np = 10, Q1 = diagonal([1.0, 1.0, 1.0, 1.0]), Q2 = diagonal([0.1]), penalize_increments = true, Q3 = diagonal([0.1]), umin = [-3.0], umax = [3.0], constrained = ["w"], constrained_min = [-4.0], constrained_max = [4.0], reference_tracking = false, integrator = ACADOSIntegrator.IRK(), integrator_stages = 3) {}
"Cart position"
variable pos::Real
"Pendulum angle"
variable theta::Real
"Pendulum angular velocity"
variable omega::Real
"Force"
variable u1::Real
"acados status"
variable flag::Real
relations
pos = plant.pos
theta = plant.theta
omega = plant.omega
u1 = mpc.u[1]
flag = mpc.exitflag
connect(plant.pos, s[1].u)
connect(plant.theta, s[2].u)
connect(plant.vel, s[3].u)
connect(plant.omega, s[4].u)
connect(s[1].y, mpc.x[1], periodicclock.y)
for i in 2:4
connect(s[i].y, mpc.x[i])
end
connect(mpc.u[1], zoh.u) {}
connect(zoh.y, plant.F) {}
endFlattened Source
dyad
"""
The cart-pole example of the DyadControlSystems generic-MPC documentation ("Getting started"): all four
state variables start at 1 and are regulated to the origin with `Q1 = I`, `Q2 = 0.1`, a penalty
`Q3 = 0.1` on the force increments, the force bounded to ±3 and the pendulum angular velocity to ±4
(soft here, where the tutorial's stage constraint is hard). The tutorial's LQR-based terminal cost is
replaced by the default `Qf = Q1`. Verified in `test/test_acados_tutorials.jl`.
"""
example component CartPoleIncrementMPCExample
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
plant = MPCComponents.Examples.CartPolePlant(p0 = 1.0, th0 = 1.0, v0 = 1.0, w0 = 1.0) {}
"Samplers of the four state variables"
s = [DiscreteComponents.Sampler() for i in 1:4] {}
zoh = DiscreteComponents.ZeroOrderHold() {}
mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["F"], state_variables = ["p", "th", "v", "w"], outputs = ["p", "th", "v", "w"], Ts = 0.1, Np = 10, Q1 = diagonal([1.0, 1.0, 1.0, 1.0]), Q2 = diagonal([0.1]), penalize_increments = true, Q3 = diagonal([0.1]), umin = [-3.0], umax = [3.0], constrained = ["w"], constrained_min = [-4.0], constrained_max = [4.0], reference_tracking = false, integrator = ACADOSIntegrator.IRK(), integrator_stages = 3) {}
"Cart position"
variable pos::Real
"Pendulum angle"
variable theta::Real
"Pendulum angular velocity"
variable omega::Real
"Force"
variable u1::Real
"acados status"
variable flag::Real
relations
pos = plant.pos
theta = plant.theta
omega = plant.omega
u1 = mpc.u[1]
flag = mpc.exitflag
connect(plant.pos, s[1].u)
connect(plant.theta, s[2].u)
connect(plant.vel, s[3].u)
connect(plant.omega, s[4].u)
connect(s[1].y, mpc.x[1], periodicclock.y)
for i in 2:4
connect(s[i].y, mpc.x[i])
end
connect(mpc.u[1], zoh.u) {}
connect(zoh.y, plant.F) {}
metadata {}
endTest Cases ​
No test cases defined.
Related ​
Examples
Experiments
Analyses