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

Cleanup #4

Merged
merged 5 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
28 changes: 3 additions & 25 deletions src/animate.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
"""
Interpolations.jl requires that one(::Type{T}) be defined for any data
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like Interpolations.jl has fixed this issue, so this entire type is no longer required. Hooray!

type we want to interpolate. Rather than defining one(::Type{Vector}) here,
which might have unforeseen consequences in other packages, we'll create
a very simple wrapper type that just knows one() and *
"""
struct InterpolatableArray{A <: AbstractArray}
data::A
end

Base.one(::Type{InterpolatableArray{A}}) where {A} = 1
Base.:*(n::Number, a::InterpolatableArray) = n * a.data

rbd.normalize_configuration!(joint_type::JointType, q) = nothing
function rbd.normalize_configuration!(joint_type::QuaternionFloating, q)
n = norm(q[1:4])
for i = 1:4
q[i] /= n
end
end

"""
animate(vis::MechanismVisualizer,
times::Vector{Float64},
Expand All @@ -36,8 +15,7 @@ function animate(vis::MechanismVisualizer,
@assert 0 < realtimerate < Inf

state = vis.state
interp_values = [InterpolatableArray(c) for c in configurations]
interpolated_configurations = interpolate((times,), interp_values, Gridded(Linear()))
interpolated_configurations = interpolate((times,), configurations, Gridded(Linear()))
t0, tf = first(times), last(times)
framenum = 0
walltime0 = time()
Expand All @@ -53,5 +31,5 @@ function animate(vis::MechanismVisualizer,
end

animate(mechanism::Mechanism, times::Vector{Float64},
configurations::Vector{Vector{Float64}}) =
animate(Visualizer(mechanism), mechanism, times, configurations)
configurations::Vector{Vector{Float64}}; kw...) =
animate(MechanismVisualizer(mechanism), times, configurations; kw...)
6 changes: 3 additions & 3 deletions src/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ function _set_mechanism!(mvis::MechanismVisualizer, frame_to_visuals)
body_ancestors = rbd.Graphs.ancestors(vertex, tree)
for definition in rbd.frame_definitions(body)
frame = definition.from
path = Symbol.(vcat(string.(reverse(body_ancestors)), string(frame)))
path = vcat(string.(reverse(body_ancestors)), string(frame))
frame_vis = vis[path...]
if frame in keys(frame_to_visuals)
settransform!(frame_vis, to_affine_map(definition))
for (i, (object, tform)) in enumerate(frame_to_visuals[frame])
obj_vis = frame_vis[Symbol("geometry_", i)]
obj_vis = frame_vis["geometry_$i"]
setobject!(obj_vis, object)
settransform!(obj_vis, tform)
end
Expand All @@ -58,7 +58,7 @@ function _render_state!(mvis::MechanismVisualizer, state::MechanismState=mvis.st
settransform!(vis, to_affine_map(transform_to_root(state, body)))
else
body_ancestors = rbd.Graphs.ancestors(vertex, tree)
path = Symbol.(string.(reverse(body_ancestors)))
path = string.(reverse(body_ancestors))
tform = relative_transform(state, default_frame(body), default_frame(body_ancestors[2]))
settransform!(vis[path...], to_affine_map(tform))
end
Expand Down