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

Added visualize function without storage #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
45 changes: 41 additions & 4 deletions src/visuals/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N};

# Build robot in the visualizer
build && build_robot(mechanism;
vis, show_joint, show_contact, show_frame, color, name, visualize_floor)
vis, show_joint, joint_radius, show_contact, show_frame, color, name, visualize_floor)

# Create animations
timestep_max = 1/framerate
Expand All @@ -56,8 +56,7 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N};
if show_joint
for (jd, joint) in enumerate(mechanism.joints)
if joint.child_id == body.id
radius = 0.1
joint_shape = Sphere(radius,
joint_shape = Sphere(joint_radius,
position_offset=joint.translational.vertices[2],
color=RGBA(0.0, 0.0, 1.0, 0.5))
visshape = convert_shape(joint_shape)
Expand Down Expand Up @@ -116,6 +115,44 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N};
return_animation ? (return vis, animation) : (return vis)
end

"""
visualize(mechanism; vis, build, show_contact, animation, color, name)

visualize mechanism pose from current state

mechanism: Mechanism
vis: Visualizer
build: flag to construct mechanism visuals (only needs to be built once)
show_contact: flag to show contact locations on system
color: RGBA
name: unique identifier for mechanism
"""
function visualize(mechanism::Mechanism;
vis::Visualizer=Visualizer(),
framerate=60, # Inf for 1/timestep
build::Bool=true,
show_joint=false,
joint_radius=0.1,
show_contact=false,
show_frame=false,
animation=nothing,
color=nothing,
name::Symbol=:robot,
return_animation=false,
visualize_floor=true) where {T,N}

# Create 1 step storage from current body state
storage = Storage(1, length(mechanism.bodies))
for (i, body) in enumerate(mechanism.bodies)
storage.x[i][1] = body.state.x2
storage.q[i][1] = body.state.q2
end

visualize(mechanism, storage;
vis, framerate, build, show_joint, joint_radius, show_contact, show_frame,
animation, color, name, return_animation, visualize_floor)
end

"""
build_robot(mechanism; vis, show_contact, name, color)

Expand Down Expand Up @@ -242,7 +279,7 @@ function animate_node!(storage::Storage{T,N}, id, shape, animation, shapevisuali
x = storage.x[id][i]
q = storage.q[id][i]
atframe(animation, frame_id) do
set_node!(x, q, shape, shapevisualizer, showshape)
set_node!(x, q, shape, shapevisualizer, showshape)
Copy link
Member

Choose a reason for hiding this comment

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

Remove identation

end
frame_id += 1
end
Expand Down