Spherical pendulum

This example models a spherical pendulum. The pivot point is modeled using a Spherical joint, the pendulum rod is modeled using a FixedTranslation and the mass is modeled using a Body. In this example, we choose the joint to be the root (joints are often better root objects than bodies).

using Multibody
using ModelingToolkit
using Plots
using SymbolicIR
using OrdinaryDiffEq

t = Multibody.t
D = Differential(t)
world = Multibody.world

systems = @named begin
    joint = Spherical(enforceStates=true, isroot=true, phi = 1)
    bar = FixedTranslation(r = [0, -1, 0])
    body = Body(; m = 1, isroot = false)

connections = [connect(world.frame_b, joint.frame_a)
            connect(joint.frame_b, bar.frame_a)
            connect(bar.frame_b, body.frame_a)]

@named model = ODESystem(connections, t, systems = [world; systems])
ssys = structural_simplify(IRSystem(model))

prob = ODEProblem(ssys, [], (0, 10))

sol = solve(prob, Rodas4())
@assert SciMLBase.successful_retcode(sol)

plot(sol, idxs = [body.r_0...])