Skip to content
LIBRARY
Examples.ACADOSMPCNestedParameterExample.md

Examples.ACADOSMPCNestedParameterExample ​

Regulation of the geared pendulum to its hanging position, with the parameters of the prediction model named hierarchically. The plant ACADOSGearedPendulum carries the pendulum as a subcomponent, so its mass is link.m; tunable_parameters = ["link.m", "n"] keeps that and the gear ratio of the assembly itself symbolic in the compiled solver, and mpc.p_values holds the two values in that order, by default the ones the plant carries. Building the problem with [ssys.mpc.p_values => [1.0, 2.0]] hands the controller a link three times too light without rebuilding it, and with [3.0, 1.0] one whose gearbox is believed to transmit half the torque it does. The state variables of the subcomponent are named the same way, state_variables = ["link.th", "link.om"]. Verified in test/test_acados_mpc.jl.

Usage ​

MPCComponents.Examples.ACADOSMPCNestedParameterExample()

Variables ​

NameDescriptionUnits
thetaAngle–
u1Motor torque–
flagacados status–

Behavior ​

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

Source ​

dyad
"""
Regulation of the geared pendulum to its hanging position, with the parameters of the prediction
model named hierarchically. The plant `ACADOSGearedPendulum` carries the pendulum as a subcomponent,
so its mass is `link.m`; `tunable_parameters = ["link.m", "n"]` keeps that and the gear ratio of the
assembly itself symbolic in the compiled solver, and `mpc.p_values` holds the two values in that
order, by default the ones the plant carries. Building the problem with
`[ssys.mpc.p_values => [1.0, 2.0]]` hands the controller a link three times too light without
rebuilding it, and with `[3.0, 1.0]` one whose gearbox is believed to transmit half the torque it
does. The state variables of the subcomponent are named the same way,
`state_variables = ["link.th", "link.om"]`. Verified in `test/test_acados_mpc.jl`.
"""
example component ACADOSMPCNestedParameterExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
    "Dyad": {"placement": {"diagram": {"x1": 150, "y1": 200, "x2": 50, "y2": 300}}}
  }
  plant = MPCComponents.Examples.ACADOSGearedPendulum(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 = ["link.m", "n"], state_variables = ["link.th", "link.om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 40, Q1 = diagonal([10.0, 1.0]), Q2 = diagonal([0.1]), umin = [-12.5], umax = [12.5], reference_tracking = false) {
    "Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 400, "y2": 400}}}
  }
  "Angle"
  variable theta::Real
  "Motor 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}}}
end
Flattened Source
dyad
"""
Regulation of the geared pendulum to its hanging position, with the parameters of the prediction
model named hierarchically. The plant `ACADOSGearedPendulum` carries the pendulum as a subcomponent,
so its mass is `link.m`; `tunable_parameters = ["link.m", "n"]` keeps that and the gear ratio of the
assembly itself symbolic in the compiled solver, and `mpc.p_values` holds the two values in that
order, by default the ones the plant carries. Building the problem with
`[ssys.mpc.p_values => [1.0, 2.0]]` hands the controller a link three times too light without
rebuilding it, and with `[3.0, 1.0]` one whose gearbox is believed to transmit half the torque it
does. The state variables of the subcomponent are named the same way,
`state_variables = ["link.th", "link.om"]`. Verified in `test/test_acados_mpc.jl`.
"""
example component ACADOSMPCNestedParameterExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.05) {
    "Dyad": {"placement": {"diagram": {"x1": 150, "y1": 200, "x2": 50, "y2": 300}}}
  }
  plant = MPCComponents.Examples.ACADOSGearedPendulum(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 = ["link.m", "n"], state_variables = ["link.th", "link.om"], outputs = ["theta", "omega"], Ts = 0.05, Np = 40, Q1 = diagonal([10.0, 1.0]), Q2 = diagonal([0.1]), umin = [-12.5], umax = [12.5], reference_tracking = false) {
    "Dyad": {"placement": {"diagram": {"x1": 300, "y1": 300, "x2": 400, "y2": 400}}}
  }
  "Angle"
  variable theta::Real
  "Motor 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}}}
end


Test Cases ​

No test cases defined.

  • Examples

  • Experiments

  • Analyses