Skip to content
LIBRARY
examples.Cartpole.md

examples.Cartpole

Inverted pendulum on a cart.

The cart moves along the world x-axis by means of a prismatic joint and is driven by a force actuator. The pendulum is a cylinder attached to the cart through a revolute joint, with an additional point mass at the tip. The pendulum angle phi is zero when the pendulum points straight up.

The force input u drives the cart, and the variables x, v, phi, w expose the cart position and velocity as well as the pendulum angle and angular velocity.

Usage

MultibodyComponents.examples.Cartpole()

Connectors

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

Variables

NameDescriptionUnits
xCart positionm
vCart velocitym/s
phiPendulum angle, zero when the pendulum points uprad
wPendulum angular velocityrad/s

Behavior

Source

dyad
"""
Inverted pendulum on a cart.

The cart moves along the world x-axis by means of a prismatic joint and is
driven by a force actuator. The pendulum is a cylinder attached to the cart
through a revolute joint, with an additional point mass at the tip. The
pendulum angle `phi` is zero when the pendulum points straight up.

The force input `u` drives the cart, and the variables `x`, `v`, `phi`, `w`
expose the cart position and velocity as well as the pendulum angle and
angular velocity.
"""
component Cartpole
  "Force driving the cart along the prismatic axis"
  u = RealInput()
  fixed = MultibodyComponents.Fixed()
  cart = MultibodyComponents.BodyShape(m = 1, r = [0.2, 0, 0], shape = "box", width = 0.1, height = 0.1, color = [0.2, 0.2, 0.2, 1])
  mounting_point = MultibodyComponents.FixedTranslation(r = [0.1, 0, 0])
  prismatic = MultibodyComponents.Prismatic(n = [1, 0, 0], statePriority = 100, color = [0.5, 0.5, 0.5, 1])
  revolute = MultibodyComponents.Revolute(n = [0, 0, 1], statePriority = 100)
  pendulum = MultibodyComponents.BodyCylinder(r = [0, 0.5, 0], diameter = 0.015, color = [0.5, 0.5, 0.5, 1])
  motor = TranslationalComponents.Sources.Force()
  tip = MultibodyComponents.Body(m = 0.05)
  "Cart position"
  variable x::Length
  "Cart velocity"
  variable v::Velocity
  "Pendulum angle, zero when the pendulum points up"
  variable phi::Angle
  "Pendulum angular velocity"
  variable w::AngularVelocity
relations
  connect(fixed.frame_b, prismatic.frame_a)
  connect(prismatic.frame_b, cart.frame_a, mounting_point.frame_a)
  connect(mounting_point.frame_b, revolute.frame_a)
  connect(revolute.frame_b, pendulum.frame_a)
  connect(pendulum.frame_b, tip.frame_a)
  connect(motor.flange_a, prismatic.support)
  connect(motor.flange_b, prismatic.axis)
  connect(u, motor.f)
  x = prismatic.s
  v = prismatic.v
  phi = revolute.phi
  w = revolute.w
metadata {"Dyad": {"labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}]}}
end
Flattened Source
dyad
"""
Inverted pendulum on a cart.

The cart moves along the world x-axis by means of a prismatic joint and is
driven by a force actuator. The pendulum is a cylinder attached to the cart
through a revolute joint, with an additional point mass at the tip. The
pendulum angle `phi` is zero when the pendulum points straight up.

The force input `u` drives the cart, and the variables `x`, `v`, `phi`, `w`
expose the cart position and velocity as well as the pendulum angle and
angular velocity.
"""
component Cartpole
  "Force driving the cart along the prismatic axis"
  u = RealInput()
  fixed = MultibodyComponents.Fixed()
  cart = MultibodyComponents.BodyShape(m = 1, r = [0.2, 0, 0], shape = "box", width = 0.1, height = 0.1, color = [0.2, 0.2, 0.2, 1])
  mounting_point = MultibodyComponents.FixedTranslation(r = [0.1, 0, 0])
  prismatic = MultibodyComponents.Prismatic(n = [1, 0, 0], statePriority = 100, color = [0.5, 0.5, 0.5, 1])
  revolute = MultibodyComponents.Revolute(n = [0, 0, 1], statePriority = 100)
  pendulum = MultibodyComponents.BodyCylinder(r = [0, 0.5, 0], diameter = 0.015, color = [0.5, 0.5, 0.5, 1])
  motor = TranslationalComponents.Sources.Force()
  tip = MultibodyComponents.Body(m = 0.05)
  "Cart position"
  variable x::Length
  "Cart velocity"
  variable v::Velocity
  "Pendulum angle, zero when the pendulum points up"
  variable phi::Angle
  "Pendulum angular velocity"
  variable w::AngularVelocity
relations
  connect(fixed.frame_b, prismatic.frame_a)
  connect(prismatic.frame_b, cart.frame_a, mounting_point.frame_a)
  connect(mounting_point.frame_b, revolute.frame_a)
  connect(revolute.frame_b, pendulum.frame_a)
  connect(pendulum.frame_b, tip.frame_a)
  connect(motor.flange_a, prismatic.support)
  connect(motor.flange_b, prismatic.axis)
  connect(u, motor.f)
  x = prismatic.s
  v = prismatic.v
  phi = revolute.phi
  w = revolute.w
metadata {"Dyad": {"labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}]}}
end


Test Cases

No test cases defined.

  • Examples

  • Experiments

  • Analyses