Skip to content
LIBRARY
Examples.CartPolePlant.md

Examples.CartPolePlant ​

Cart-pole: a cart of mass mc driven by the force F, carrying a pendulum of mass mp and length l. The angle theta is zero when the pendulum hangs down. Translated from the DyadControlSystems quadratic-MPC tutorial.

Usage ​

MPCComponents.Examples.CartPolePlant(mc=1.0, mp=0.2, l=0.5, g=9.81, p0=0.0, th0=0.0, v0=0.0, w0=0.0)

Parameters: ​

NameDescriptionUnitsDefault value
mc–1.0
mp–0.2
l–0.5
g–9.81
p0–0.0
th0–0.0
v0–0.0
w0–0.0

Connectors ​

  • F - This connector represents a real signal as an input to a component (RealInput)

  • pos - This connector represents a real signal as an output from a component (RealOutput)

  • theta - This connector represents a real signal as an output from a component (RealOutput)

  • vel - This connector represents a real signal as an output from a component (RealOutput)

  • omega - This connector represents a real signal as an output from a component (RealOutput)

Variables ​

NameDescriptionUnits
p–
th–
v–
w–

Behavior ​

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

Source ​

dyad
"""
Cart-pole: a cart of mass `mc` driven by the force `F`, carrying a pendulum of mass `mp` and length `l`.
The angle `theta` is zero when the pendulum hangs down. Translated from the DyadControlSystems
quadratic-MPC tutorial.
"""
component CartPolePlant
  "Force on the cart"
  F = RealInput() {
    "Dyad": {"placement": {"diagram": {"x1": -100, "x2": 0, "y1": 450, "y2": 550}}}
  }
  "Cart position"
  pos = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 100, "y2": 200}}}
  }
  "Pendulum angle"
  theta = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 330, "y2": 430}}}
  }
  "Cart velocity"
  vel = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 610, "y2": 710}}}
  }
  "Pendulum angular velocity"
  omega = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 830, "y2": 930}}}
  }
  parameter mc::Real = 1.0
  parameter mp::Real = 0.2
  parameter l::Real = 0.5
  parameter g::Real = 9.81
  parameter p0::Real = 0.0
  parameter th0::Real = 0.0
  parameter v0::Real = 0.0
  parameter w0::Real = 0.0
  variable p::Real
  variable th::Real
  variable v::Real
  variable w::Real
relations
  initial p = p0
  initial th = th0
  initial v = v0
  initial w = w0
  der(p) = v
  der(th) = w
  der(v) = (F + mp * l * sin(th) * w ^ 2 + mp * g * sin(th) * cos(th)) / (mc + mp * sin(th) ^ 2)
  der(w) = -(cos(th) * (F + mp * l * sin(th) * w ^ 2) + (mc + mp) * g * sin(th)) / (l * (mc + mp * sin(th) ^ 2))
  pos = p
  theta = th
  vel = v
  omega = w
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MPCComponents/CartPolePlant.svg"},
    "doc": {"behavior": false}
  }
}
end
Flattened Source
dyad
"""
Cart-pole: a cart of mass `mc` driven by the force `F`, carrying a pendulum of mass `mp` and length `l`.
The angle `theta` is zero when the pendulum hangs down. Translated from the DyadControlSystems
quadratic-MPC tutorial.
"""
component CartPolePlant
  "Force on the cart"
  F = RealInput() {
    "Dyad": {"placement": {"diagram": {"x1": -100, "x2": 0, "y1": 450, "y2": 550}}}
  }
  "Cart position"
  pos = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 100, "y2": 200}}}
  }
  "Pendulum angle"
  theta = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 330, "y2": 430}}}
  }
  "Cart velocity"
  vel = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 610, "y2": 710}}}
  }
  "Pendulum angular velocity"
  omega = RealOutput() {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "x2": 1100, "y1": 830, "y2": 930}}}
  }
  parameter mc::Real = 1.0
  parameter mp::Real = 0.2
  parameter l::Real = 0.5
  parameter g::Real = 9.81
  parameter p0::Real = 0.0
  parameter th0::Real = 0.0
  parameter v0::Real = 0.0
  parameter w0::Real = 0.0
  variable p::Real
  variable th::Real
  variable v::Real
  variable w::Real
relations
  initial p = p0
  initial th = th0
  initial v = v0
  initial w = w0
  der(p) = v
  der(th) = w
  der(v) = (F + mp * l * sin(th) * w ^ 2 + mp * g * sin(th) * cos(th)) / (mc + mp * sin(th) ^ 2)
  der(w) = -(cos(th) * (F + mp * l * sin(th) * w ^ 2) + (mc + mp) * g * sin(th)) / (l * (mc + mp * sin(th) ^ 2))
  pos = p
  theta = th
  vel = v
  omega = w
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MPCComponents/CartPolePlant.svg"},
    "doc": {"behavior": false}
  }
}
end


Test Cases ​

No test cases defined.

  • Examples

  • Experiments

  • Analyses