Skip to content

Commit 083796e

Browse files
Fix depwarn (#171)
* Fix depwarn * tol changes --------- Co-authored-by: Fredrik Bagge Carlson <[email protected]>
1 parent 714fc3d commit 083796e

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

ext/Render.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Multibody.PlanarMechanics as P
66
using Rotations
77
using LinearAlgebra
88
using ModelingToolkit
9+
using ModelingToolkit: get_metadata
910
export render, loop_render
1011
using MeshIO, FileIO
1112
using StaticArrays
@@ -301,10 +302,11 @@ function render(model, sol,
301302
if traces !== nothing
302303
tvec = range(sol.t[1], stop=sol.t[end], length=500)
303304
for frame in traces
304-
(frame.metadata !== nothing) || error("Only frames can be traced in animations.")
305-
if get(frame.metadata, :frame, false)
305+
md = get_metadata(frame)
306+
(md !== nothing) || error("Only frames can be traced in animations.")
307+
if get(md, :frame, false)
306308
points = get_trans(sol, frame, tvec) |> Matrix
307-
elseif get(frame.metadata, :frame_2d, false)
309+
elseif get(md, :frame_2d, false)
308310
points = get_trans_2d(sol, frame, tvec) |> Matrix
309311
else
310312
error("Got fishy frame metadata")
@@ -374,10 +376,11 @@ function render(model, sol, time::Real;
374376
if traces !== nothing
375377
tvec = range(sol.t[1], stop=sol.t[end], length=500)
376378
for frame in traces
377-
(frame.metadata !== nothing) || error("Only frames can be traced in animations.")
378-
if get(frame.metadata, :frame, false)
379+
md = get_metadata(frame)
380+
(md !== nothing) || error("Only frames can be traced in animations.")
381+
if get(md, :frame, false)
379382
points = get_trans(sol, frame, tvec) |> Matrix
380-
elseif get(frame.metadata, :frame_2d, false)
383+
elseif get(md, :frame_2d, false)
381384
points = get_trans_2d(sol, frame, tvec) |> Matrix
382385
else
383386
error("Got fishy frame metadata")
@@ -1165,4 +1168,4 @@ function render!(scene, ::typeof(Multibody.CylinderVisualizer), sys, sol, t)
11651168
true
11661169
end
11671170

1168-
end
1171+
end

src/components.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using LinearAlgebra
2+
using ModelingToolkit: get_metadata
23
import ModelingToolkitStandardLibrary
34

45
function isroot(sys)
5-
sys.metadata isa Dict || return false
6-
get(sys.metadata, :isroot, false)
6+
md = get_metadata(sys)
7+
md isa Dict || return false
8+
get(md, :isroot, false)
79
end
810

911
purple = [0.5019608f0,0.0f0,0.5019608f0,1.0f0]
@@ -13,12 +15,13 @@ purple = [0.5019608f0,0.0f0,0.5019608f0,1.0f0]
1315
1416
Get the orientation of `sys` as a `RotationMatrix` object. See also [`get_rot`](@ref). `ori(frame).R` is the rotation matrix that rotates a vector from the world coordinate system to the local frame.
1517
16-
For frames, the orientation is stored in the metadata field of the system as `sys.metadata[:orientation]`.
18+
For frames, the orientation is stored in the metadata field of the system as `get_metadata(sys)[:orientation]`.
1719
1820
If `varw = true`, the angular velocity variables `w` of the frame is also included in the `RotationMatrix` object, otherwise `w` is derived as the time derivative of `R`. `varw = true` is primarily used when selecting a component as root.
1921
"""
2022
function ori(sys, varw = false)
21-
if sys.metadata isa Dict && (O = get(sys.metadata, :orientation, nothing)) !== nothing
23+
md = get_metadata(sys)
24+
if md isa Dict && (O = get(md, :orientation, nothing)) !== nothing
2225
R = collect(O.R)
2326
# Since we are using this function instead of sys.ori, we need to handle namespacing properly as well
2427
ns = nameof(sys)

test/test_quaternions.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,22 @@ for (i, ti) in enumerate(ts)
118118
end
119119

120120
# Test that rotational velocity of 1 results in one full rotation in 2π seconds. Test rotation around all three major axes
121-
@test get_R(sol, body.frame_a, 0pi) I
121+
@test get_R(sol, body.frame_a, 0pi) I atol=1e-3
122122
@test get_R(sol, body.frame_a, pi/2) [1 0 0; 0 0 -1; 0 1 0]' atol=1e-3
123123
@test get_rot(sol, body.frame_a, pi/2)*[0,1,0] [0,0,1] atol=1e-3 # Same test as above, but in one other way for sanity. They y-axis basis vector is rotated around x axis which aligns it with the z-axis basis vector. get_rot is used for this, which is the transpose of get_R
124124
@test get_R(sol, body.frame_a, 1pi) diagm([1, -1, -1]) atol=1e-3
125125
@test get_R(sol, body.frame_a, 2pi) I atol=1e-3
126126

127127
prob = ODEProblem(ssys, [collect(body.w_a) .=> [0,1,0];], (0, 2pi))
128128
sol = solve(prob, Rodas4())#,
129-
@test get_R(sol, body.frame_a, 0pi) I
129+
@test get_R(sol, body.frame_a, 0pi) I atol=1e-3
130130
@test get_R(sol, body.frame_a, 1pi) diagm([-1, 1, -1]) atol=1e-3
131131
@test get_R(sol, body.frame_a, 2pi) I atol=1e-3
132132

133133

134134
prob = ODEProblem(ssys, [collect(body.w_a) .=> [0,0,1];], (0, 2pi))
135135
sol = solve(prob, Rodas4())#,
136-
@test get_R(sol, body.frame_a, 0pi) I
136+
@test get_R(sol, body.frame_a, 0pi) I atol=1e-3
137137
@test get_R(sol, body.frame_a, 1pi) diagm([-1, -1, 1]) atol=1e-3
138138
@test get_R(sol, body.frame_a, 2pi) I atol=1e-3
139139

@@ -184,7 +184,7 @@ end
184184
@test Q Qh ./ sqrt.(n) atol=1e-2
185185
@test norm(mapslices(norm, Q, dims=1) .- 1) < 1e-2
186186

187-
@test get_R(sol, joint.frame_b, 0pi) I
187+
@test get_R(sol, joint.frame_b, 0pi) I atol=1e-3
188188
@test_broken get_R(sol, joint.frame_b, pi/2)*[0,1,0] [0,0,1] atol=1e-3
189189
@test get_R(sol, joint.frame_b, 1pi) diagm([1, -1, -1]) atol=1e-3
190190
@test get_R(sol, joint.frame_b, 2pi) I atol=1e-3
@@ -245,7 +245,7 @@ end
245245

246246
Matrix(sol(ts, idxs = [body.w_a...]))
247247

248-
@test get_R(sol, joint.frame_b, 0pi) I
248+
@test get_R(sol, joint.frame_b, 0pi) I atol = 1e-3
249249

250250

251251
# Matrix(sol(ts, idxs = [joint.w_rel_b...]))

0 commit comments

Comments
 (0)