JuliaComputing / Multibody.jl

Other
7 stars 0 forks source link

Experiment with a scalar formulation #118

Open YingboMa opened 1 month ago

YingboMa commented 1 month ago
using Test
using Multibody
using ModelingToolkit
import ModelingToolkitStandardLibrary.Mechanical.Rotational
using OrdinaryDiffEq
using LinearAlgebra
using JuliaSimCompiler

t = Multibody.t
D = Differential(t)
world = Multibody.world
W(args...; kwargs...) = Multibody.world

@mtkmodel TestUSR begin
    @components begin
        world = W()
        j1 = JointUSR(positive_branch=true, use_arrays=false)
        fixed = FixedTranslation(r=[1,0,0])
        b1 = Body(isroot=false, neg_w=true)
        p1 = Prismatic(state_priority=100)
    end
    @equations begin
        connect(world.frame_b, j1.frame_a, fixed.frame_a)
        connect(fixed.frame_b, p1.frame_a)
        connect(p1.frame_b, j1.frame_b)
        connect(j1.frame_im, b1.frame_a)
    end
end

@named model = TestUSR()
model = complete(model)
ss = structural_simplify(IRSystem(model))
prob = ODEProblem(ss, [model.b1.a_0[1]=>0.0, D(D(model.p1.s))=>0.0], (0.0, 1.0))
sol = solve(prob, FBDF(autodiff=true))

works

baggepinnen commented 1 month ago

it solves but the solution is all zeros, while in OpenModelica the mechanism slides along the prismatic joint as expected