How to use Multibody.jl?

Hello all,
I am new to Julia, now on version 1.12.2 on Linux/Debian version 13.2.
Played around with it and with Dyad.
Now trying to use the Pendulum example from Multibody.jl
I can do add and then using ModelingToolkit, but adding Multibody fails. Same with JuliaSimCompiler.
The error is:

Updating registry at `~/.julia/registries/DyadRegistry.toml`
ERROR: The following package names could not be resolved:
 * Multibody (not found in project, manifest or registry)

What am I doing wrong?

Regards, Sietse

PS.
In Dyad, in Julia-Based Component Libraries there is mentioning of using Multibody.jl.
It says it could be used using " the external components definition".
But how?

Hello and welcome to the community :waving_hand:

Multibody.jl used to use an alternative model compiler, JuliaSimCompiler, but this compiler has been deprecated and is no longer functional. The work to make the standard ModelingToolkit compiler handle multibody systems is not yet complete and Multibody.jl is currently not installable or usable. I expect it to take a few months before it’s usable again.

2 Likes

Thanks for the quick reply! Then I’ll wait.

As an aside, in my use case I need contact modeling and friction.
For example to bounce a ball or drag a box on the ground.

For example opensim/simbody has this.
Looking at the code of Multibody I see that this isn’t there.
My hope is to implement something like this, hopefully this is feasible (for me).

Thanks again, Sietse

Perhaps you’ve seen it already, but a bouncing ball is an example in the MTK docs.

Event Handling and Callback Functions · ModelingToolkit.jl

As pointed out above, simple events like a ball bouncing off the ground is handled using the standard MTK event machinery. Dragging a box on the ground is slightly more involved, at least if you want to include modeling of static friction, see Modelica.Mechanics.Rotational.UsersGuide.ModelingOfFriction for an overview.

1 Like

By the way, besides the event-detection based methods for simulation of nonsmooth dynamical systems (which is what the sliding mass exposed to dry friction is), there is a framework of methods based on complementarity constraints (these methods are called, imho rather confusingly, time-stepping methods). As a teaser, here comes my code. Note that it needs a solver for Linear Complemenrarity Problem (LCP) and Mixed Complementarity Problem (MCP) – I am using the PATH solver.

using JuMP
using PATHSolver
using Plots

m = 100.0
g = 9.81
μ = 10.0

x0 = 0.0
v0 = 100.0

x = [x0]
v = [v0]

h = 1e-1
tfinal = 5.0
N = tfinal/h

for i = 1:N
    model = Model(PATHSolver.Optimizer)
    set_optimizer_attribute(model, "output", "no")
    set_silent(model)
    @variable(model, ν >= 0)
    @variable(model, F⁺ >= 0)
    @variable(model, F⁻ >= 0)
    @constraint(model, (v[end] + h/m*(F⁺-F⁻) + ν) ⟂ F⁺)
    @constraint(model, (-(v[end] + h/m*(F⁺-F⁻)) + ν) ⟂ F⁻)
    @constraint(model, (μ*m*g - (F⁺+F⁻)) ⟂ ν)
    optimize!(model) 
    push!(v, v[end] + h/m*(value(F⁺)-value(F⁻)))
    push!(x, x[end] + h*v[end])         # At this point, after the update on the prevous line, v[end] already equals v_k+1.
end

t = range(0.0, step=h, stop=tfinal)
Plots.plot(t, v, label="v", lw=3, markershape=:circle, markersize=2)
Plots.plot!(t, x, label="x", lw=3, markershape=:circle, markersize=2, xlabel="t")

You can find a bit more in my introductory material Simulations of complementarity systems using time-stepping – B(E)3M35HYS – Hybrid systems. This is example 3 toward the bottom of the page. But it is admittedly very introductory (but links to other literature are included). This type of methods are implemented in simulators such as SICONOS and PINOCCHIO.

2 Likes