Skip to content

Update Animation given the changes upstream in MeshCat.jl #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 5, 2024
Merged
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- master
pull_request:

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand All @@ -13,13 +14,18 @@ jobs:
matrix:
version:
- '1.6'
- '1.10'
- '1'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
include:
- os: macOS-latest
arch: arm64
version: 1
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
Expand Down
13 changes: 8 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "MeshCatMechanisms"
uuid = "6ad125db-dd91-5488-b820-c1df6aab299d"
version = "0.9.0"
version = "0.9.1"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand All @@ -14,19 +14,22 @@ MeshCat = "283c5d60-a78f-5afe-a0af-af636b173e11"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
RigidBodyDynamics = "366cf18f-59d5-5db9-a4de-86a9f6786172"

[sources]
ValkyrieRobot = {rev = "hf/dev", url = "https://github.com/ferrolho/ValkyrieRobot.jl.git"}

[compat]
ColorTypes = "0.7, 0.8, 0.9, 0.10, 0.11"
ColorTypes = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12"
CoordinateTransformations = "0.5, 0.6"
GeometryBasics = "0.4"
InteractBase = "0.8, 0.9, 0.10"
Interpolations = "0.9, 0.10, 0.11, 0.12, 0.13, 0.14"
Interpolations = "0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15"
LoopThrottle = "0.1"
MechanismGeometries = "0.7"
MeshCat = "0.13, 0.14, 0.15, 0.16"
MeshCat = "1"
NBInclude = "1, 2"
OrderedCollections = "1"
RigidBodyDynamics = "2"
ValkyrieRobot = "0.2.1"
ValkyrieRobot = "0.2.2"
julia = "1.6"

[extras]
Expand Down
25 changes: 10 additions & 15 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@
"metadata": {},
"outputs": [],
"source": [
"Pkg.activate(temp=true)\n",
"Pkg.add(\"ValkyrieRobot\")\n",
"using ValkyrieRobot\n",
"\n",
"val = Valkyrie();\n",
"delete!(vis)\n",
"mvis = MechanismVisualizer(\n",
" val.mechanism, \n",
" URDFVisuals(ValkyrieRobot.urdfpath(), package_path=[dirname(dirname(ValkyrieRobot.urdfpath()))]),\n",
" vis);"
"urdfvisuals = URDFVisuals(\n",
" ValkyrieRobot.urdfpath(),\n",
" package_path=[dirname(dirname(ValkyrieRobot.urdfpath()))])\n",
"mvis = MechanismVisualizer(val.mechanism, urdfvisuals, vis);"
]
},
{
Expand Down Expand Up @@ -201,13 +203,6 @@
"set_configuration!(vis, [0.5]) \n",
"render(vis)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -216,17 +211,17 @@
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 1.3.1",
"display_name": "Julia 1.11.1",
"language": "julia",
"name": "julia-1.3"
"name": "julia-1.11"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.3.1"
"version": "1.11.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
15 changes: 4 additions & 11 deletions examples/interactive_manipulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@
" set_configuration!(mvis, configuration(x))\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -153,17 +146,17 @@
"lastKernelId": "7e34dd28-a64c-4428-9bea-63befbdea05d"
},
"kernelspec": {
"display_name": "Julia 1.3.1",
"display_name": "Julia 1.11.1",
"language": "julia",
"name": "julia-1.3"
"name": "julia-1.11"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.3.1"
"version": "1.11.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
34 changes: 17 additions & 17 deletions src/animate.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""
animate(vis::MechanismVisualizer,
animate(mvis::MechanismVisualizer,
times::Vector{Float64},
configurations::Vector{Vector{Float64}};
fps::Float64=60, realtimerate::Float64=1.)

Animate the given mechanism passing through a time-coded series of
configurations by linearly interpolating the configuration vectors.
"""
function animate(vis::MechanismVisualizer,
function animate(mvis::MechanismVisualizer,
times::Vector{Float64},
configurations::AbstractVector{<:AbstractVector{Float64}};
fps::Float64 = 60., realtimerate::Float64 = 1.)
fps::Float64=60.0, realtimerate::Float64=1.0)
@assert fps > 0
@assert 0 < realtimerate < Inf

state = vis.state
state = mvis.state
interpolated_configurations = interpolate((times,), configurations, Gridded(Linear()))
t0, tf = first(times), last(times)
framenum = 0
Expand All @@ -24,24 +24,24 @@ function animate(vis::MechanismVisualizer,
q = interpolated_configurations(t)
set_configuration!(state, q)
rbd.normalize_configuration!(state)
_render_state!(vis)
_render_state!(mvis)
framenum += 1
t == tf && break
end max_rate = fps
end

function MeshCat.Animation(mvis::MechanismVisualizer,
times::AbstractVector{<:Real},
configurations::AbstractVector{<:AbstractVector{<:Real}};
fps::Integer=30)
times::AbstractVector{<:Real},
configurations::AbstractVector{<:AbstractVector{<:Real}};
fps::Integer=30)
@assert axes(times) == axes(configurations)
interpolated_configurations = interpolate((times,), configurations, Gridded(Linear()))
animation = Animation()
animation = Animation(mvis.visualizer)
num_frames = floor(Int, (times[end] - first(times)) * fps)
for frame in 0 : num_frames
for frame in 0:num_frames
time = first(times) + frame / fps
let mvis = mvis, interpolated_configurations = interpolated_configurations, time=time
atframe(animation, frame) do
let mvis = mvis, interpolated_configurations = interpolated_configurations, time = time
atframe(animation, frame) do
set_configuration!(mvis, interpolated_configurations(time))
end
end
Expand All @@ -53,11 +53,11 @@ MeshCat.setanimation!(mvis::MechanismVisualizer, args...; kw...) =
setanimation!(visualizer(mvis), args...; kw...)

function MeshCat.setanimation!(mvis::MechanismVisualizer,
times::AbstractVector{<:Real},
configurations::AbstractVector{<:AbstractVector{<:Real}};
fps::Integer=30,
play::Bool=true,
repetitions::Integer=1)
times::AbstractVector{<:Real},
configurations::AbstractVector{<:AbstractVector{<:Real}};
fps::Integer=30,
play::Bool=true,
repetitions::Integer=1)
Base.depwarn("""
`setanimation!(mvis, times, configurations; ..)` is deprecated. Instead, you can construct an `Animation` and then call `setanimation!` with the result.

Expand Down
Loading