JuliaRobotics / MeshCatMechanisms.jl

3D Visualization of mechanisms and URDFs using MeshCat.jl and RigidBodyDynamics.jl
Other
40 stars 9 forks source link

Animation constructor #34

Closed tkoolen closed 4 years ago

tkoolen commented 5 years ago

On top of #33.

Extract out Animation constructor. In the medium term, I think we should deprecate the setanimation! overload. But that's for later.

ferrolho commented 5 years ago

Calling setanimation!, e.g., setanimation!(mvis, t, qs), yields this on #master:

MethodError: no method matching Tuple{AbstractArray{T,1} where T}(::Array{RigidBody{Float64},1}, ::Int64, ::Int64)
Closest candidates are:
  Tuple{AbstractArray{T,1} where T}(::Any) where T<:Tuple at tuple.jl:246

Stacktrace:
 [1] reverse at /home/henrique/.julia/packages/Cassette/N8DMt/src/context.jl:447 [inlined]
 [2] overdub(::Cassette.Context{nametype(AnimationCtx),Tuple{MeshCat.Animation,Int64},Nothing,getfield(Cassette, Symbol("##PassType#365")),Nothing,Nothing}, ::typeof(invoke), ::typeof(reverse), ::Type{Tuple{AbstractArray{T,1} where T}}, ::Array{RigidBody{Float64},1}) at /home/henrique/.julia/packages/Cassette/N8DMt/src/overdub.jl:0
 [3] reverse at ./array.jl:1466 [inlined]
 [4] overdub(::Cassette.Context{nametype(AnimationCtx),Tuple{MeshCat.Animation,Int64},Nothing,getfield(Cassette, Symbol("##PassType#365")),Nothing,Nothing}, ::typeof(reverse), ::Array{RigidBody{Float64},1}) at /home/henrique/.julia/packages/Cassette/N8DMt/src/overdub.jl:0
 [5] _path at /home/henrique/.julia/packages/MeshCatMechanisms/L2mYm/src/visualizer.jl:120 [inlined]
 [6] overdub(::Cassette.Context{nametype(AnimationCtx),Tuple{MeshCat.Animation,Int64},Nothing,getfield(Cassette, Symbol("##PassType#365")),Nothing,Nothing}, ::typeof(MeshCatMechanisms._path), ::Mechanism{Float64}, ::RigidBody{Float64}) at /home/henrique/.julia/packages/Cassette/N8DMt/src/overdub.jl:0
 [7] getindex at /home/henrique/.julia/packages/MeshCatMechanisms/L2mYm/src/visualizer.jl:48 [inlined]
 [8] overdub(::Cassette.Context{nametype(AnimationCtx),Tuple{MeshCat.Animation,Int64},Nothing,getfield(Cassette, Symbol("##PassType#365")),Nothing,Nothing}, ::typeof(getindex), ::MechanismVisualizer{MechanismState{Float64,Float64,Float64,TypeSortedCollections.TypeSortedCollection{Tuple{Array{Joint{Float64,Revolute{Float64}},1}},1}},Visualizer}, ::RigidBody{Float64}) at /home/henrique/.julia/packages/Cassette/N8DMt/src/overdub.jl:0
 [9] _render_state! at /home/henrique/.julia/packages/MeshCatMechanisms/L2mYm/src/visualizer.jl:137 [inlined]
 [10] overdub(::Cassette.Context{nametype(AnimationCtx),Tuple{MeshCat.Animation,Int64},Nothing,getfield(Cassette, Symbol("##PassType#365")),Nothing,Nothing}, ::typeof(MeshCatMechanisms._render_state!), ::MechanismVisualizer{MechanismState{Float64,Float64,Float64,TypeSortedCollections.TypeSortedCollection{Tuple{Array{Joint{Float64,Revolute{Float64}},1}},1}},Visualizer}, ::MechanismState{Float64,Float64,Float64,TypeSortedCollections.TypeSortedCollection{Tuple{Array{Joint{Float64,Revolute{Float64}},1}},1}}) at /home/henrique/.julia/packages/Cassette/N8DMt/src/overdub.jl:0
 [11] _render_state! at /home/henrique/.julia/packages/MeshCatMechanisms/L2mYm/src/visualizer.jl:125 [inlined]
 [12] #5 at /home/henrique/.julia/packages/MeshCatMechanisms/L2mYm/src/animate.jl:48 [inlined]
 [13] #51 at /home/henrique/.julia/packages/MeshCat/rIG2y/src/atframe.jl:80 [inlined]
 [14] atframe at /home/henrique/.julia/packages/MeshCat/rIG2y/src/atframe.jl:62 [inlined]
 [15] atframe at /home/henrique/.julia/packages/MeshCat/rIG2y/src/atframe.jl:80 [inlined]
 [16] #setanimation!#4(::Int64, ::Bool, ::Int64, ::Function, ::MechanismVisualizer{MechanismState{Float64,Float64,Float64,TypeSortedCollections.TypeSortedCollection{Tuple{Array{Joint{Float64,Revolute{Float64}},1}},1}},Visualizer}, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Array{SegmentedVector{JointID,Float64,Base.OneTo{JointID},Array{Float64,1}},1}) at /home/henrique/.julia/packages/MeshCatMechanisms/L2mYm/src/animate.jl:47
 [17] setanimation!(::MechanismVisualizer{MechanismState{Float64,Float64,Float64,TypeSortedCollections.TypeSortedCollection{Tuple{Array{Joint{Float64,Revolute{Float64}},1}},1}},Visualizer}, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Array{SegmentedVector{JointID,Float64,Base.OneTo{JointID},Array{Float64,1}},1}) at /home/henrique/.julia/packages/MeshCatMechanisms/L2mYm/src/animate.jl:39
 [18] top-level scope at In[104]:1
tkoolen commented 5 years ago

Oh, darn. This should be worked around in https://github.com/JuliaRobotics/MeshCatMechanisms.jl/pull/33 (which I thought was already merged and tagged), and fixed in https://github.com/jrevels/Cassette.jl/pull/137.

tkoolen commented 5 years ago

Ah, but that's only with MeshCat master, not any released version (MeshCat 0.7 doesn't have the Cassette animation yet). Also it should be worked around if you're actually using this PR branch rather than MeshCatMechanisms master, since it contains #33.

ferrolho commented 5 years ago

Yes, this is not with the released version. As a temporary workaround, and to be on MeshCat master, I ended up forking this and merging /tk/meshfileobject-hack on top of /tk/develop to get the .dae and the animation working. Works for now :stuck_out_tongue:

tkoolen commented 5 years ago

Actually, you should just be able to do a ] up to get the latest version of Cassette (released this morning), which contains my fix to the issue you reported.

codecov-io commented 4 years ago

Codecov Report

Merging #34 into master will increase coverage by 0.05%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #34      +/-   ##
==========================================
+ Coverage   96.69%   96.74%   +0.05%     
==========================================
  Files           5        5              
  Lines         121      123       +2     
==========================================
+ Hits          117      119       +2     
  Misses          4        4
Impacted Files Coverage Δ
src/animate.jl 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4183805...a665f20. Read the comment docs.