Skip to content
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

Deprecate setanimation!(mvis, t, q) in favor of setanimation!(mvis, animation) #38

Merged
merged 2 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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.6.0"
version = "0.7.0"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down
29 changes: 14 additions & 15 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"source": [
"## Animating a Trajectory\n",
"\n",
"You can animate a trajectory (a list of times and configurations) with the `setanimation!()` function. To create an animation and play it in the visualizer, you just need to do:"
"You can animate a trajectory (a list of times and configurations) by creating an `Animation` and calling `setanimation!` to pass it to the visuailzer:"
]
},
{
Expand All @@ -60,7 +60,8 @@
"metadata": {},
"outputs": [],
"source": [
"setanimation!(mvis, t, q)"
"animation = Animation(mvis, t, q)\n",
"setanimation!(mvis, animation)"
]
},
{
Expand Down Expand Up @@ -124,16 +125,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The triad and point are included in the MeshCat scene tree, so each will move along with the body to which it's attached:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"setanimation!(mvis, t, q)"
"The triad and point are included in the MeshCat scene tree, so each will move along with the body to which it's attached. \n",
"\n",
"\n",
"Try clicking \"Animation\" -> \"default\" -> \"play\" again in the MeshCat window. You should see the arm animation repeat, and the point and triad you've added will move as well. "
]
},
{
Expand Down Expand Up @@ -206,16 +201,20 @@
}
],
"metadata": {
"@webio": {
"lastCommId": "3bd05bbcc8404a329198a25d86e23539",
"lastKernelId": "cc89f867-0754-4f63-b35b-9e38ff54bdd4"
},
"kernelspec": {
"display_name": "Julia 0.6.4",
"display_name": "Julia 1.3.1",
"language": "julia",
"name": "julia-0.6"
"name": "julia-1.3"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.4"
"version": "1.3.1"
}
},
"nbformat": 4,
Expand Down
10 changes: 7 additions & 3 deletions examples/interactive_manipulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,20 @@
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 0.7.0",
"display_name": "Julia 1.3.1",
"language": "julia",
"name": "julia-0.7"
"name": "julia-1.3"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.7.0"
"version": "1.3.1"
}
},
"nbformat": 4,
Expand Down
25 changes: 21 additions & 4 deletions src/animate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,31 @@ function MeshCat.Animation(mvis::MechanismVisualizer,
return animation
end

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)
q0 = copy(configuration(state(mvis)))
animation = Animation(mvis, times, configurations; fps=fps)
setanimation!(visualizer(mvis), animation, play=play, repetitions=repetitions)
set_configuration!(state(mvis), q0)
Base.depwarn("""
`setanimation!(mvis, times, configurations; ..)` is deprecated. Instead, you can construct an `Animation` and then call `setanimation!` with the result.

For examle, if you previously did:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example


```
setanimation!(mvis, times, configurations, fps=30, play=true)
```

You should now do:

```
animation = Animation(mvis, times, configurations, fps=25)
setanimation!(mvis, animation, play=true)
```
""", :setanimation_t_q)
animation = Animation(mvis, times, configurations, fps=fps)
setanimation!(mvis, animation, play=play, repetitions=repetitions)
end
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ vis = Visualizer()
setelement!(mvis, Point3D(default_frame(bodies(robot)[3]), 0.2, 0.2, 0.2))

@testset "simulation and animation" begin
state = MechanismState(robot, randn(2), randn(2))
t, q, v = simulate(state, 5.0);
animate(mvis, t, q)
animation = Animation(mvis, t, q)
setanimation!(mvis, animation)
end

@testset "deprecated `setanimation!`" begin
state = MechanismState(robot, randn(2), randn(2))
t, q, v = simulate(state, 5.0);
animate(mvis, t, q)
Expand All @@ -48,7 +56,7 @@ vis = Visualizer()
state = MechanismState(robot, randn(1), randn(1))
t, q, v = simulate(state, 5.0);
animate(mvis, t, q)
setanimation!(mvis, t, q)
setanimation!(mvis, Animation(mvis, t, q))
end
end

Expand Down