Skip to content

Commit

Permalink
Fix depwarn
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa authored and baggepinnen committed Oct 7, 2024
1 parent 714fc3d commit 3c4f652
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 10 additions & 7 deletions ext/Render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Multibody.PlanarMechanics as P
using Rotations
using LinearAlgebra
using ModelingToolkit
using ModelingToolkit: get_metadata
export render, loop_render
using MeshIO, FileIO
using StaticArrays
Expand Down Expand Up @@ -301,10 +302,11 @@ function render(model, sol,
if traces !== nothing
tvec = range(sol.t[1], stop=sol.t[end], length=500)
for frame in traces
(frame.metadata !== nothing) || error("Only frames can be traced in animations.")
if get(frame.metadata, :frame, false)
md = get_metadata(frame)
(md !== nothing) || error("Only frames can be traced in animations.")
if get(md, :frame, false)
points = get_trans(sol, frame, tvec) |> Matrix
elseif get(frame.metadata, :frame_2d, false)
elseif get(md, :frame_2d, false)
points = get_trans_2d(sol, frame, tvec) |> Matrix
else
error("Got fishy frame metadata")
Expand Down Expand Up @@ -374,10 +376,11 @@ function render(model, sol, time::Real;
if traces !== nothing
tvec = range(sol.t[1], stop=sol.t[end], length=500)
for frame in traces
(frame.metadata !== nothing) || error("Only frames can be traced in animations.")
if get(frame.metadata, :frame, false)
md = get_metadata(frame)
(md !== nothing) || error("Only frames can be traced in animations.")
if get(md, :frame, false)
points = get_trans(sol, frame, tvec) |> Matrix
elseif get(frame.metadata, :frame_2d, false)
elseif get(md, :frame_2d, false)
points = get_trans_2d(sol, frame, tvec) |> Matrix
else
error("Got fishy frame metadata")
Expand Down Expand Up @@ -1165,4 +1168,4 @@ function render!(scene, ::typeof(Multibody.CylinderVisualizer), sys, sol, t)
true
end

end
end
11 changes: 7 additions & 4 deletions src/components.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using LinearAlgebra
using ModelingToolkit: get_metadata
import ModelingToolkitStandardLibrary

function isroot(sys)
sys.metadata isa Dict || return false
get(sys.metadata, :isroot, false)
md = get_metadata(sys)
md isa Dict || return false
get(md, :isroot, false)
end

purple = [0.5019608f0,0.0f0,0.5019608f0,1.0f0]
Expand All @@ -13,12 +15,13 @@ purple = [0.5019608f0,0.0f0,0.5019608f0,1.0f0]
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.
For frames, the orientation is stored in the metadata field of the system as `sys.metadata[:orientation]`.
For frames, the orientation is stored in the metadata field of the system as `get_metadata(sys)[:orientation]`.
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.
"""
function ori(sys, varw = false)
if sys.metadata isa Dict && (O = get(sys.metadata, :orientation, nothing)) !== nothing
md = get_metadata(sys)
if md isa Dict && (O = get(md, :orientation, nothing)) !== nothing
R = collect(O.R)
# Since we are using this function instead of sys.ori, we need to handle namespacing properly as well
ns = nameof(sys)
Expand Down

0 comments on commit 3c4f652

Please sign in to comment.