Double Pendulum Model

An undamped double pendulum can be constructed using the DoublePendulum function, as shown below. Models are provided for the fully-actuated version, the undriven version, and both of the underactuated versions (also accessible via the convenience functions Acrobot and Pendubot). Additionally, when also using the Plots.jl package, the convenience plotting function plot_double_pendulum is provided.

Double pendulum animation

NeuralLyapunovProblemLibrary.DoublePendulumFunction
DoublePendulum(; actuation=:fully_actuated, name, defaults)

Create an ODESystem representing an undamped double pendulum.

The posture of the double pendulum is determined by θ1 and θ2, the angle of the first and second pendula, respectively. θ1 is measured counter-clockwise relative to the downward equilibrium and θ2 is measured counter-clockwise relative to θ1 (i.e., when θ2 is fixed at 0, the double pendulum appears as a single pendulum).

The ODESystem uses the explicit manipulator form of the equations:

\[q̈ = M^{-1}(q) (-C(q,q̇)q̇ + τ_g(q) + Bu).\]

The name of the ODESystem is name.

Actuation modes

The four actuation modes are described in the table below and selected via actuation.

Actuation mode (actuation)Torque around θ1Torque around θ2
:fully_actuated (default)τ1τ2
:acrobotNot actuatedτ
:pendubotτNot actuated
:undrivenNot actuatedNot actuated

ODESystem Parameters

  • I1: moment of inertia of the first pendulum around its pivot (not its center of mass).
  • I2: moment of inertia of the second pendulum around its pivot (not its center of mass).
  • l1: length of the first pendulum.
  • l2: length of the second pendulum.
  • lc1: distance from pivot to the center of mass of the first pendulum.
  • lc2: distance from the link to the center of mass of the second pendulum.
  • m1: mass of the first pendulum.
  • m2: mass of the second pendulum.
  • g: gravitational acceleration (defaults to 9.81).

Users may optionally provide default values of the parameters through defaults: a vector of the default values for [I1, I2, l1, l2, lc1, lc2, m1, m2, g].

source

Copy-Pastable Code

using ModelingToolkit, NeuralLyapunovProblemLibrary, Plots, OrdinaryDiffEq

@named double_pendulum_undriven = DoublePendulum(; actuation = :undriven)

t, = independent_variables(double_pendulum_undriven)
Dt = Differential(t)
θ1, θ2 = unknowns(double_pendulum_undriven)
x0 = Dict([θ1, θ2, Dt(θ1), Dt(θ2)] .=> vcat(2π * rand(2) .- π, zeros(2)))

# Assume uniform rods of random mass and length
m1, m2 = ones(2)
l1, l2 = ones(2)
lc1, lc2 = l1 /2, l2 / 2
I1 = m1 * l1^2 / 3
I2 = m2 * l2^2 / 3
g = 1.0
p = Dict(parameters(double_pendulum_undriven) .=> [I1, I2, l1, l2, lc1, lc2, m1, m2, g])

prob = ODEProblem(structural_simplify(double_pendulum_undriven), x0, 100, p)
sol = solve(prob, Tsit5(), abstol = 1e-10, reltol = 1e-10)

p = [I1, I2, l1, l2, lc1, lc2, m1, m2, g]
gif(plot_double_pendulum(sol, p); fps=50)
Example block output

Plotting the Double Pendulum

NeuralLyapunovProblemLibrary.plot_double_pendulumFunction
plot_double_pendulum(θ1, θ2, p, t; title)
plot_double_pendulum(sol, p; title, N, angle_symbol)

Plot the pendulum's trajectory.

Arguments

  • θ1: The angle of the first pendulum link at each time step.
  • θ2: The angle of the second pendulum link at each time step.
  • t: The time steps.
  • sol: The solution to the ODE problem.
  • p: The parameters of the double pendulum.

Keyword arguments

  • title: The title of the plot; defaults to no title (i.e., title="").
  • N: The number of points to plot; when using θ and t, uses length(t); defaults to 500 when using sol.
  • angle1_symbol: The symbol of the angle of the first link in sol; defaults to :θ1.
  • angle2_symbol: The symbol of the angle of the second link in sol; defaults to :θ2.
source