Skip to content

Commit

Permalink
remove hacky W world constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Oct 3, 2024
1 parent eb2114a commit 181ccc5
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 50 deletions.
4 changes: 2 additions & 2 deletions docs/src/examples/prescribed_pose.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using Test
t = Multibody.t
D = Differential(t)
W(args...; kwargs...) = Multibody.world
n = [1, 0, 0]
AB = 146.5 / 1000
Expand Down Expand Up @@ -131,7 +131,7 @@ end
rod_radius = 0.02
end
@components begin
world = W()
world = World()
mass = Body(m=ms, r_cm = 0.5DA*normalize([0, 0.2, 0.2*sin(t5)]))
excited_suspension = ExcitedWheelAssembly(; rod_radius)
prescribed_motion = Pose(; r = [0, 0.1 + 0.1sin(t), 0], R = RotXYZ(0, 0.5sin(t), 0))
Expand Down
3 changes: 1 addition & 2 deletions docs/src/examples/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ using OrdinaryDiffEq
t = Multibody.t
D = Differential(t)
W(;kwargs...) = Multibody.world
@mtkmodel PointGrav begin
@components begin
world = W()
world = World()
body1 = Body(
m=1,
I_11=0.1,
Expand Down
3 changes: 1 addition & 2 deletions docs/src/examples/suspension.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ using Test
t = Multibody.t
D = Differential(t)
W(args...; kwargs...) = Multibody.world
n = [1, 0, 0]
AB = 146.5 / 1000
Expand Down Expand Up @@ -137,7 +136,7 @@ end
dir = mirror ? -1 : 1
end
@components begin
world = W()
world = World()
mass = Body(m=ms, r_cm = 0.5DA*normalize([0, 0.2, 0.2*sin(t5)*dir]))
excited_suspension = SuspensionWithExcitation(; suspension.spring=true, mirror, rod_radius)
body_upright = Prismatic(n = [0, 1, 0], render = false, state_priority=1000)
Expand Down
6 changes: 2 additions & 4 deletions docs/src/examples/swing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ t = Multibody.t
D = Differential(t)
world = Multibody.world
W(args...; kwargs...) = Multibody.world
@mtkmodel SwingRope begin
@components begin
frame_a = Frame()
Expand All @@ -44,7 +42,7 @@ end
w = 0.4
end
@components begin
world = W()
world = World()
upper_trans1 = FixedTranslation(r=[-w/2, 0, 0])
rope1 = SwingRope(rope.r=[-w/2, h, -w/2])
body = Body(m=6, isroot=true, I_11=0.1, I_22=0.1, I_33=0.1)
Expand Down Expand Up @@ -91,7 +89,7 @@ Next, we create the full swing assembly
w = 0.4
end
@components begin
world = W()
world = World()
upper_trans1 = FixedTranslation(r=[-w/2, 0, 0])
upper_trans2 = FixedTranslation(r=[ w/2, 0, 0])
rope1 = SwingRope(rope.r=[-w/2, -h, -w/2])
Expand Down
9 changes: 4 additions & 5 deletions docs/src/examples/wheel.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ using Test
t = Multibody.t
D = Differential(t)
W(args...; kwargs...) = Multibody.world
@mtkmodel WheelInWorld begin
@components begin
world = W()
world = World()
wheel = RollingWheel(
radius = 0.3,
m = 2,
Expand Down Expand Up @@ -104,7 +103,7 @@ The slip velocity is defined such that when the wheel is moving with positive ve
```@example WHEEL
@mtkmodel SlipWheelInWorld begin
@components begin
world = W()
world = World()
wheel = SlippingWheel(
radius = 0.3,
m = 2,
Expand Down Expand Up @@ -164,7 +163,7 @@ A [`RollingWheelSet`](@ref) is comprised out of two wheels mounted on a common a
wheels = RollingWheelSet(radius=0.1, m_wheel=0.5, I_axis=0.01, I_long=0.02, track=0.5, state_priority=100)
bar = FixedTranslation(r = [0.2, 0, 0])
body = Body(m=0.01, state_priority=1)
world = W()
world = World()
end
@equations begin
connect(sine1.output, torque1.tau)
Expand Down Expand Up @@ -216,7 +215,7 @@ tire_black = [0.1, 0.1, 0.1, 1]
g=0
end
@components begin
world = W()
world = World()
sine1 = Blocks.Sine(frequency=1, amplitude=150)
sine2 = Blocks.Sine(frequency=1, amplitude=150, phase=pi/6)
Expand Down
1 change: 0 additions & 1 deletion examples/JuliaSim_logo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ using Multibody, JuliaSimCompiler
using OrdinaryDiffEq # Contains the ODE solver we will use
using Plots
t = Multibody.t
W(args...; kwargs...) = Multibody.world


JULIASIM_PURPLE = [87,87,219,255.0f0]./255 # RGBA
Expand Down
3 changes: 1 addition & 2 deletions ext/URDF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,14 @@ function Multibody.urdf2multibody(filename::AbstractString; extras=false, out=no
"""
using ModelingToolkit, Multibody, JuliaSimCompiler, OrdinaryDiffEq, Plots
import ModelingToolkit: t_nounits as t, D_nounits as D
W(args...; kwargs...) = Multibody.world
"""
else
""
end
s = s * """
@mtkmodel $(modelname) begin
@components begin
world = W()
world = World()
$(join(bodies, "\n"))
$(join(joints, "\n"))
end
Expand Down
20 changes: 10 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ t = Multibody.t
D = Differential(t)
doplot() = false
world = Multibody.world
W(args...; kwargs...) = Multibody.world


@testset "world" begin
@info "Testing world"
Expand Down Expand Up @@ -388,7 +388,7 @@ end

@testset "Spring damper system" begin
systems = @named begin
world = W()
world = World()
body1 = Body(; m = 1, isroot = true, r_cm = [0.0, 0, 0], I_11 = 0.1, I_22 = 0.1,
I_33 = 0.1, r_0 = [0.3, -0.2, 0], quat=false) # This is root since there is no joint parallel to the spring leading to this body
body2 = Body(; m = 1, isroot = false, r_cm = [0.0, -0.2, 0]) # This is not root since there is a joint parallel to the spring leading to this body
Expand Down Expand Up @@ -565,7 +565,7 @@ end
using LinearAlgebra
@mtkmodel PlanarTest begin
@components begin
world = W()
world = World()
planar = Planar(n=[0,0,1], n_x=[1,0,0])
force = Force()
body = Body(m=1)
Expand Down Expand Up @@ -1054,7 +1054,7 @@ using LinearAlgebra
world = Multibody.world
@mtkmodel CylinderPend begin
@components begin
world = W()
world = World()
body = BodyCylinder(r=[1,2,3], diameter=0.1)
joint = Revolute()
end
Expand Down Expand Up @@ -1102,7 +1102,7 @@ using LinearAlgebra
@info "Testing BodyBox"
@mtkmodel BoxPend begin
@components begin
world = W()
world = World()
body = Multibody.BodyBox(r=[0.1, 1, 0.2], r_shape=[0, 0, 0], width=0.1, height=0.3, inner_width=0.05)
joint = Revolute()
end
Expand Down Expand Up @@ -1217,7 +1217,7 @@ sol3 = solve(prob, FBDF(), abstol=1e-8, reltol=1e-8)

@mtkmodel TestSphericalSpherical begin
@components begin
world = W()
world = World()
ss = SphericalSpherical(r_0 = [1, 0, 0], m = 1, kinematic_constraint=false)
ss2 = BodyShape(r = [0, 0, 1], m = 1, isroot=true)
s = Spherical()
Expand Down Expand Up @@ -1248,7 +1248,7 @@ sol = solve(prob, Rodas4())

@mtkmodel TestSphericalSpherical begin
@components begin
world = W()
world = World()
ss = UniversalSpherical(rRod_ia = [1, 0, 0], kinematic_constraint=false, sphere_diameter=0.3)
ss2 = BodyShape(r = [0, 0, 1], m = 1, isroot=true)
s = Spherical()
Expand Down Expand Up @@ -1291,7 +1291,7 @@ end
# Test cylindrical joint
@mtkmodel CylinderTest begin
@components begin
world = W()
world = World()
cyl = Cylindrical(n = [0, 1, 0])
# spring = Spring(c = 1)
body = Body(state_priority=0)
Expand Down Expand Up @@ -1352,7 +1352,7 @@ import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica as Transl
jr = 0.03, [description = "Radius of revolute joint"]
end
@components begin
world = W()
world = World()

r1 = Revolute(; n, radius=jr, color=jc)
r2 = Revolute(; n, radius=jr, color=jc)
Expand Down Expand Up @@ -1482,7 +1482,7 @@ import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica as Transl
rRod2_ib = BC*normalize([0, 0.2, 0])
end
@components begin
world = W()
world = World()

r123 = JointRRR(n_a = n, n_b = n, rRod1_ia, rRod2_ib, rod_radius=0.02, rod_color=jc)
r2 = Revolute(; n, radius=jr, color=jc)
Expand Down
6 changes: 3 additions & 3 deletions test/test_JointUSR_RRR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using LinearAlgebra
using JuliaSimCompiler

world = Multibody.world
W(args...; kwargs...) = Multibody.world

t = Multibody.t
D = Differential(t)

Expand All @@ -17,7 +17,7 @@ D = Differential(t)
# ==============================================================================
@mtkmodel TestUSR begin
@components begin
world = W()
world = World()
j1 = JointUSR(positive_branch=true, use_arrays=false)
fixed = FixedTranslation(r=[1,0,0])
b1 = Body(m=1)
Expand Down Expand Up @@ -48,7 +48,7 @@ sol = solve(prob, FBDF(autodiff=true))
# ==============================================================================
@mtkmodel TestRRR begin
@components begin
world = W()
world = World()
j1 = JointRRR(positive_branch=true)
fixed = FixedTranslation(r=[1,0,0])
b1 = Body(m=1)
Expand Down
2 changes: 1 addition & 1 deletion test/test_orientation_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Test
import ModelingToolkitStandardLibrary.Mechanical.Rotational
@mtkmodel FurutaPendulum begin
@components begin
world = W()
world = World()
shoulder_joint = Revolute(n = [0, 1, 0], isroot = true, axisflange = true)
elbow_joint = Revolute(n = [0, 0, 1], isroot = true, axisflange = true, phi0=0.1)
upper_arm = BodyShape(; m = 1, isroot = false, r = [0, 0, 0.6], radius=0.04)
Expand Down
2 changes: 1 addition & 1 deletion test/test_urdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include("doublependulum.jl")

using ModelingToolkit, Multibody, JuliaSimCompiler, OrdinaryDiffEq#, Plots
import ModelingToolkit: t_nounits as t, D_nounits as D
W(args...; kwargs...) = Multibody.world

@named model = DoublePendulum()
model = complete(model)
ssys = structural_simplify(IRSystem(model))
Expand Down
8 changes: 4 additions & 4 deletions test/test_wheels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using LinearAlgebra
@mtkmodel WheelInWorld begin
@components begin
# world = World(n=[0,0,-1])
world = W()
world = World()
wheel = RollingWheel(radius = 0.3, m = 2, I_axis = 0.06,
I_long = 0.12,
x0 = 0.2,
Expand Down Expand Up @@ -59,7 +59,7 @@ using LinearAlgebra
end
@components begin
# world = World(n=[0,0,-1])
world = W()
world = World()
wheel = RollingWheel(; radius = 0.3, m = 2, I_axis = 0.06,
I_long = 0.12,
x0 = 0.2,
Expand Down Expand Up @@ -123,7 +123,7 @@ dd = diff(sol(tv, idxs=worldwheel.wheel.wheeljoint.der_angles[2]).u) # angular a
import ModelingToolkitStandardLibrary.Blocks
@mtkmodel WheelWithAxis begin
@components begin
world = W()
world = World()
prismatic = Prismatic(n = [0,1,0])
world_axis = Revolute(n = [0,1,0], iscut=false, state_priority=100, w0=10)
# world_axis = RevolutePlanarLoopConstraint(n = [0,1,0])
Expand Down Expand Up @@ -168,7 +168,7 @@ end
wheels = RollingWheelSet(radius=0.1, m_wheel=0.5, I_axis=0.01, I_long=0.02, track=0.5, state_priority=100)
bar = FixedTranslation(r = [0.2, 0, 0])
body = Body(m=0.01, state_priority=1)
world = W()
world = World()
end
@equations begin
connect(sine1.output, torque1.tau)
Expand Down
Loading

0 comments on commit 181ccc5

Please sign in to comment.