From 91d2dc4c659377ccd34e2cee3bff74ce13d5e3ba Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Tue, 6 Mar 2018 20:42:05 -0500 Subject: [PATCH 01/12] WIP: use mechanismgeometries.jl --- src/MeshCatMechanisms.jl | 1 + src/visualizer.jl | 61 +++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/MeshCatMechanisms.jl b/src/MeshCatMechanisms.jl index d4ef225..59c7eae 100644 --- a/src/MeshCatMechanisms.jl +++ b/src/MeshCatMechanisms.jl @@ -20,6 +20,7 @@ using FileIO: load using ColorTypes: RGBA using Interpolations: interpolate, Gridded, Linear using LoopThrottle: @throttle +using MechanismGeometries include("visualizer.jl") include("animate.jl") diff --git a/src/visualizer.jl b/src/visualizer.jl index f533c53..20aae7b 100644 --- a/src/visualizer.jl +++ b/src/visualizer.jl @@ -4,7 +4,7 @@ struct MechanismVisualizer{M <: MechanismState} modcount::Int function MechanismVisualizer(state::M, - frame_to_visuals::Associative{CartesianFrame3D}=create_visuals(state.mechanism), + frame_to_visuals::AbstractVector{<:VisualElement}=create_skeleton(state.mechanism), vis::Visualizer=Visualizer()) where {M <: MechanismState} mvis = new{M}(state, vis, rbd.modcount(state.mechanism)) _set_mechanism!(mvis, frame_to_visuals) @@ -21,29 +21,50 @@ MechanismVisualizer(m::MechanismState, fname::AbstractString, args...; kw...) = to_affine_map(tform::Transform3D) = AffineMap(rotation(tform), translation(tform)) -function _set_mechanism!(mvis::MechanismVisualizer, frame_to_visuals) +function _set_mechanism!(mvis::MechanismVisualizer, elements::AbstractVector{<:VisualElement}) + for (i, element) in enumerate(elements) + _set_element!(mvis, element, "geometry_$i") + end +end + +function _set_element!(mvis::MechanismVisualizer, element::VisualElement, name::AbstractString) mechanism = mvis.state.mechanism vis = mvis.visualizer - tree = mechanism.tree # TODO: tree accessor? - for vertex in rbd.Graphs.vertices(tree) - body = vertex - body_ancestors = rbd.Graphs.ancestors(vertex, tree) - for definition in rbd.frame_definitions(body) - frame = definition.from - 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["geometry_$i"] - setobject!(obj_vis, object) - settransform!(obj_vis, tform) - end - end - end - end + tree = mechanism.tree + # TODO: much of this information can be cached if this + # method becomes a performance bottleneck + body = rbd.body_fixed_frame_to_body(mechanism, element.frame) + body_ancestors = rbd.Graphs.ancestors(body, tree) + path = vcat(string.(reverse(body_ancestors)), string(element.frame)) + frame_vis = vis[path...] + definition = rbd.frame_definition(body, element.frame) + settransform!(frame_vis, to_affine_map(definition)) + setobject!(frame_vis[name], element.object) + settransform!(frame_vis[name], element.transform) end + + +# tree = mechanism.tree # TODO: tree accessor? +# for vertex in rbd.Graphs.vertices(tree) +# body = vertex +# body_ancestors = rbd.Graphs.ancestors(vertex, tree) +# for definition in rbd.frame_definitions(body) +# frame = definition.from +# path = vcat(string.(reverse(body_ancestors)), string(frame)) +# frame_vis = vis[path...] +# if frame in keys(elements) +# settransform!(frame_vis, to_affine_map(definition)) +# for (i, (object, tform)) in enumerate(elements[frame]) +# obj_vis = frame_vis["geometry_$i"] +# setobject!(obj_vis, object) +# settransform!(obj_vis, tform) +# end +# end +# end +# end +# end + function _render_state!(mvis::MechanismVisualizer, state::MechanismState=mvis.state) @assert mvis.state.mechanism === state.mechanism if rbd.modcount(state.mechanism) != mvis.modcount From fa090727c91e909359a06a57f8ef01c741c99235 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Tue, 6 Mar 2018 21:57:40 -0500 Subject: [PATCH 02/12] urdfs and skeletons working --- REQUIRE | 7 +- src/MeshCatMechanisms.jl | 10 +-- src/ode_callback.jl | 8 +-- src/parse_urdf.jl | 152 --------------------------------------- src/visualizer.jl | 26 +------ 5 files changed, 9 insertions(+), 194 deletions(-) delete mode 100644 src/parse_urdf.jl diff --git a/REQUIRE b/REQUIRE index 915deba..82b3897 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,12 +1,9 @@ julia 0.6 MeshCat 0.0.1 - ColorTypes 0.2.0 CoordinateTransformations 0.4.1 -FileIO 0.1.0 -GeometryTypes 0.4.0 Interpolations 0.3.6 -LightXML 0.4.0 LoopThrottle 0.0.1 -MeshIO 0.1.0 +MechanismGeometries +MeshCat 0.0.1 RigidBodyDynamics 0.4 diff --git a/src/MeshCatMechanisms.jl b/src/MeshCatMechanisms.jl index 59c7eae..4ae267f 100644 --- a/src/MeshCatMechanisms.jl +++ b/src/MeshCatMechanisms.jl @@ -6,25 +6,17 @@ export MechanismVisualizer, animate, MeshCatSink -using LightXML using MeshCat using MeshCat: AbstractMaterial, AbstractObject, MeshMaterial using CoordinateTransformations -using GeometryTypes using RigidBodyDynamics -using RigidBodyDynamics.Graphs -import RigidBodyDynamics: OdeIntegrators const rbd = RigidBodyDynamics -import MeshIO -using FileIO: load -using ColorTypes: RGBA using Interpolations: interpolate, Gridded, Linear using LoopThrottle: @throttle -using MechanismGeometries +using MechanismGeometries: VisualElement, parse_urdf_visuals, create_skeleton include("visualizer.jl") include("animate.jl") -include("parse_urdf.jl") include("ode_callback.jl") end # module diff --git a/src/ode_callback.jl b/src/ode_callback.jl index 5a40e0f..a0598b1 100644 --- a/src/ode_callback.jl +++ b/src/ode_callback.jl @@ -1,4 +1,4 @@ -mutable struct MeshCatSink{M <: MechanismState} <: OdeIntegrators.OdeResultsSink +mutable struct MeshCatSink{M <: MechanismState} <: rbd.OdeIntegrators.OdeResultsSink vis::MechanismVisualizer{M} min_wall_Δt::Float64 last_update_wall_time::Float64 @@ -8,12 +8,12 @@ mutable struct MeshCatSink{M <: MechanismState} <: OdeIntegrators.OdeResultsSink end end -function OdeIntegrators.initialize(sink::MeshCatSink, t, state) +function rbd.OdeIntegrators.initialize(sink::MeshCatSink, t, state) sink.last_update_wall_time = -Inf - OdeIntegrators.process(sink, t, state) + rbd.OdeIntegrators.process(sink, t, state) end -function OdeIntegrators.process(sink::MeshCatSink, t, state) +function rbd.OdeIntegrators.process(sink::MeshCatSink, t, state) wall_Δt = time() - sink.last_update_wall_time if wall_Δt > sink.min_wall_Δt set_configuration!(sink.vis, configuration(state)) diff --git a/src/parse_urdf.jl b/src/parse_urdf.jl deleted file mode 100644 index 83a3590..0000000 --- a/src/parse_urdf.jl +++ /dev/null @@ -1,152 +0,0 @@ -function parse_geometries(xml_geometry::XMLElement, package_path, file_path="") - geometries = Union{AbstractGeometry, AbstractMesh}[] - for xml_cylinder in get_elements_by_tagname(xml_geometry, "cylinder") - length = rbd.parse_scalar(Float32, xml_cylinder, "length") - radius = rbd.parse_scalar(Float32, xml_cylinder, "radius") - push!(geometries, HyperCylinder{3, Float32}(length, radius)) - end - for xml_box in get_elements_by_tagname(xml_geometry, "box") - size = Vec{3, Float32}(rbd.parse_vector(Float32, xml_box, "size", "0 0 0")) - push!(geometries, HyperRectangle(-size / 2, size)) - end - for xml_sphere in get_elements_by_tagname(xml_geometry, "sphere") - radius = rbd.parse_scalar(Float32, xml_sphere, "radius") - push!(geometries, HyperSphere(zero(Point{3, Float32}), radius)) - end - for xml_mesh in get_elements_by_tagname(xml_geometry, "mesh") - filename = attribute(xml_mesh, "filename") - dae_pattern = r".dae$" - replaced_extension_with_obj = false - if ismatch(dae_pattern, filename) - filename = replace(filename, dae_pattern, ".obj") - replaced_extension_with_obj = true - end - package_pattern = r"^package://" - - if ismatch(package_pattern, filename) - found_mesh = false - for package_directory in package_path - filename_in_package = joinpath(package_directory, replace(filename, package_pattern, "")) - if ispath(filename_in_package) - mesh = load(filename_in_package, GLUVMesh) - push!(geometries, mesh) - found_mesh = true - break - end - end - if !found_mesh - warning_message = "Could not find the mesh file: $(filename). I tried substituting the following folders for the 'package://' prefix: $(package_path)." - if replaced_extension_with_obj - warning_message *= " Note that I replaced the file's original extension with .obj to try to find a mesh in a format I can actually load." - end - warn(warning_message) - end - else - filename = joinpath(file_path, filename) - if ispath(filename) - mesh = load(filename) - push!(geometries, mesh) - else - warning_message = "Could not find the mesh file: $(filename)." - if replaced_extension_with_obj - warning_message *= " Note that I replaced the file's original extension with .obj to try to find a mesh in a format I can actually load." - end - warn(warning_message) - end - end - end - geometries -end - -function parse_material!(materials::Dict{String, <:AbstractMaterial}, xml_material) - if xml_material === nothing - return MeshLambertMaterial() - end - name = attribute(xml_material, "name") - material = get!(materials, name) do - MeshLambertMaterial() - end - xml_color = find_element(xml_material, "color") - if xml_color !== nothing - default = "0.7 0.7 0.7 1." - material.color = RGBA{Float32}(rbd.parse_vector(Float32, xml_color, "rgba", default)...) - end - material -end - -function parse_link!(materials::Dict, xml_link, - package_path=ros_package_path(), file_path="", tag="visual") - xml_visuals = get_elements_by_tagname(xml_link, tag) - visuals = Vector{Pair{Mesh, Transformation}} - visual_groups = map(xml_visuals) do xml_visual - xml_material = find_element(xml_visual, tag) - material = parse_material!(materials, find_element(xml_visual, "material")) - rot, trans = rbd.parse_pose(Float64, find_element(xml_visual, "origin")) - tform = AffineMap(rot, trans) - map(parse_geometries(find_element(xml_visual, "geometry"), package_path, file_path)) do geometry - Mesh(geometry, material) => tform - end - end - reduce(vcat, [], visual_groups) -end - -function create_graph(xml_links, xml_joints) - # create graph structure of XML elements - graph = DirectedGraph{Vertex{XMLElement}, Edge{XMLElement}}() - vertices = Vertex.(xml_links) - for vertex in vertices - add_vertex!(graph, vertex) - end - name_to_vertex = Dict(attribute(data(v), "name") => v for v in vertices) - for xml_joint in xml_joints - parent = name_to_vertex[attribute(find_element(xml_joint, "parent"), "link")] - child = name_to_vertex[attribute(find_element(xml_joint, "child"), "link")] - add_edge!(graph, parent, child, Edge(xml_joint)) - end - graph -end - -ros_package_path() = split(get(ENV, "ROS_PACKAGE_PATH", ""), ':') - -function parse_urdf_visuals(filename, mechanism; - package_path=ros_package_path(), file_path="", tag="visual") - xdoc = parse_file(filename) - xroot = LightXML.root(xdoc) - @assert LightXML.name(xroot) == "robot" - - xml_links = get_elements_by_tagname(xroot, "link") - xml_joints = get_elements_by_tagname(xroot, "joint") - xml_materials = get_elements_by_tagname(xroot, "material") - - graph = create_graph(xml_links, xml_joints) - roots = collect(filter(v -> isempty(in_edges(v, graph)), rbd.Graphs.vertices(graph))) - length(roots) != 1 && error("Can only handle a single root") - tree = SpanningTree(graph, first(roots)) - - materials = Dict{String, MeshMaterial}() - for xml_material in xml_materials - parse_material!(materials, xml_material) - end - -# name_to_body = Dict(string(body) => body for body in bodies(mechanism)) - name_to_frame_and_body = Dict(string(tf.from) => (tf.from, body) for body in bodies(mechanism) for tf in rbd.frame_definitions(body)) - - visuals = Dict( - map(rbd.Graphs.vertices(tree)) do vertex - xml_link = data(vertex) - - linkname = attribute(xml_link, "name") - framename = if vertex == rbd.Graphs.root(tree) - linkname - else - xml_joint = data(edge_to_parent(vertex, tree)) - jointname = attribute(xml_joint, "name") - string("after_", jointname) # TODO: create function in RBD, call it here - end - body_frame, body = name_to_frame_and_body[framename] - - vis = parse_link!(materials, xml_link, package_path, file_path, tag) - body_frame => vis - end - ) -end diff --git a/src/visualizer.jl b/src/visualizer.jl index 20aae7b..8882748 100644 --- a/src/visualizer.jl +++ b/src/visualizer.jl @@ -39,32 +39,10 @@ function _set_element!(mvis::MechanismVisualizer, element::VisualElement, name:: frame_vis = vis[path...] definition = rbd.frame_definition(body, element.frame) settransform!(frame_vis, to_affine_map(definition)) - setobject!(frame_vis[name], element.object) + setobject!(frame_vis[name], element.geometry, MeshLambertMaterial(color=element.color)) settransform!(frame_vis[name], element.transform) end - - -# tree = mechanism.tree # TODO: tree accessor? -# for vertex in rbd.Graphs.vertices(tree) -# body = vertex -# body_ancestors = rbd.Graphs.ancestors(vertex, tree) -# for definition in rbd.frame_definitions(body) -# frame = definition.from -# path = vcat(string.(reverse(body_ancestors)), string(frame)) -# frame_vis = vis[path...] -# if frame in keys(elements) -# settransform!(frame_vis, to_affine_map(definition)) -# for (i, (object, tform)) in enumerate(elements[frame]) -# obj_vis = frame_vis["geometry_$i"] -# setobject!(obj_vis, object) -# settransform!(obj_vis, tform) -# end -# end -# end -# end -# end - function _render_state!(mvis::MechanismVisualizer, state::MechanismState=mvis.state) @assert mvis.state.mechanism === state.mechanism if rbd.modcount(state.mechanism) != mvis.modcount @@ -86,7 +64,7 @@ function _render_state!(mvis::MechanismVisualizer, state::MechanismState=mvis.st end end -function RigidBodyDynamics.set_configuration!(mvis::MechanismVisualizer, args...) +function rbd.set_configuration!(mvis::MechanismVisualizer, args...) set_configuration!(mvis.state, args...) _render_state!(mvis) end From d575ab5683eccafa4e50f6667fbecc2511674baf Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 13:03:39 -0500 Subject: [PATCH 03/12] exports --- src/MeshCatMechanisms.jl | 4 +++- src/visualizer.jl | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/MeshCatMechanisms.jl b/src/MeshCatMechanisms.jl index 4ae267f..9057388 100644 --- a/src/MeshCatMechanisms.jl +++ b/src/MeshCatMechanisms.jl @@ -4,7 +4,9 @@ module MeshCatMechanisms export MechanismVisualizer, animate, - MeshCatSink + MeshCatSink, + parse_urdf_visuals, + create_skeleton using MeshCat using MeshCat: AbstractMaterial, AbstractObject, MeshMaterial diff --git a/src/visualizer.jl b/src/visualizer.jl index 8882748..434f70d 100644 --- a/src/visualizer.jl +++ b/src/visualizer.jl @@ -68,3 +68,5 @@ function rbd.set_configuration!(mvis::MechanismVisualizer, args...) set_configuration!(mvis.state, args...) _render_state!(mvis) end + +MeshCat.IJuliaCell(mvis::MechanismVisualizer) = MeshCat.IJuliaCell(mvis.visualizer) \ No newline at end of file From 3ab66613d3c718c5ec745c3e6c95c3c004d4751c Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 15:10:18 -0500 Subject: [PATCH 04/12] use much nicer AbstractGeometrySource implementation --- src/MeshCatMechanisms.jl | 7 ++++--- src/visualizer.jl | 9 +++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/MeshCatMechanisms.jl b/src/MeshCatMechanisms.jl index 9057388..c63e0cf 100644 --- a/src/MeshCatMechanisms.jl +++ b/src/MeshCatMechanisms.jl @@ -5,8 +5,9 @@ module MeshCatMechanisms export MechanismVisualizer, animate, MeshCatSink, - parse_urdf_visuals, - create_skeleton + Skeleton, + URDFVisuals, + visual_elements using MeshCat using MeshCat: AbstractMaterial, AbstractObject, MeshMaterial @@ -15,7 +16,7 @@ using RigidBodyDynamics const rbd = RigidBodyDynamics using Interpolations: interpolate, Gridded, Linear using LoopThrottle: @throttle -using MechanismGeometries: VisualElement, parse_urdf_visuals, create_skeleton +using MechanismGeometries: visual_elements, VisualElement, Skeleton, URDFVisuals, AbstractGeometrySource include("visualizer.jl") include("animate.jl") diff --git a/src/visualizer.jl b/src/visualizer.jl index 434f70d..9ff4af4 100644 --- a/src/visualizer.jl +++ b/src/visualizer.jl @@ -4,20 +4,17 @@ struct MechanismVisualizer{M <: MechanismState} modcount::Int function MechanismVisualizer(state::M, - frame_to_visuals::AbstractVector{<:VisualElement}=create_skeleton(state.mechanism), + source::AbstractGeometrySource=Skeleton(), vis::Visualizer=Visualizer()) where {M <: MechanismState} mvis = new{M}(state, vis, rbd.modcount(state.mechanism)) - _set_mechanism!(mvis, frame_to_visuals) + elements = visual_elements(state.mechanism, source) + _set_mechanism!(mvis, elements) _render_state!(mvis) mvis end end MechanismVisualizer(m::Mechanism, args...) = MechanismVisualizer(MechanismState{Float64}(m), args...) -MechanismVisualizer(m::Mechanism, fname::AbstractString, args...; kw...) = - MechanismVisualizer(m, parse_urdf_visuals(fname, m; kw...), args...) -MechanismVisualizer(m::MechanismState, fname::AbstractString, args...; kw...) = - MechanismVisualizer(m, parse_urdf_visuals(fname, m.mechanism; kw...), args...) to_affine_map(tform::Transform3D) = AffineMap(rotation(tform), translation(tform)) From d28127a27c98ad68e0f9b71e66ad6f1c8cbb1c0e Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 19:39:27 -0500 Subject: [PATCH 05/12] more demo --- mechanism-demo.ipynb | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/mechanism-demo.ipynb b/mechanism-demo.ipynb index d0297cf..e90b01d 100644 --- a/mechanism-demo.ipynb +++ b/mechanism-demo.ipynb @@ -1,5 +1,14 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "using Revise" + ] + }, { "cell_type": "code", "execution_count": null, @@ -31,8 +40,8 @@ "urdf = joinpath(Pkg.dir(\"MeshCatMechanisms\"), \"test\", \"urdf\", \"Acrobot.urdf\")\n", "robot = parse_urdf(Float64, urdf)\n", "delete!(vis)\n", - "mvis = MechanismVisualizer(robot, urdf, vis)\n", - "set_configuration!(mvis, [1.0, -0.5])" + "mvis = MechanismVisualizer(robot, URDFVisuals(urdf), vis)\n", + "set_configuration!(mvis, [0.0, 0.0])" ] }, { @@ -59,9 +68,8 @@ "delete!(vis)\n", "mvis = MechanismVisualizer(\n", " val.mechanism, \n", - " ValkyrieRobot.urdfpath(),\n", - " vis, \n", - " package_path=[dirname(dirname(ValkyrieRobot.urdfpath()))]);" + " URDFVisuals(ValkyrieRobot.urdfpath(), package_path=[dirname(dirname(ValkyrieRobot.urdfpath()))]),\n", + " vis);" ] }, { @@ -92,6 +100,19 @@ "set_configuration!(mvis, configuration(state))" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Handling robots with fixed joints\n", + "urdf = joinpath(Pkg.dir(\"MeshCatMechanisms\"), \"test\", \"urdf\", \"Acrobot.urdf\")\n", + "robot = parse_urdf(Float64, urdf)\n", + "RigidBodyDynamics.remove_fixed_tree_joints!(robot)\n", + "IJuliaCell(MechanismVisualizer(robot, URDFVisuals(urdf)))" + ] + }, { "cell_type": "code", "execution_count": null, From a8f8f52e46838790e0bafeb6af6ddfc23d6debf8 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 19:43:20 -0500 Subject: [PATCH 06/12] update travis --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 43ce807..6625276 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,9 +26,10 @@ addons: - libzmq3 ## uncomment the following lines to override the default test script -# script: -# - julia -e 'Pkg.clone("https://github.com/rdeits/MeshCat.jl"); Pkg.build("MeshCat")' -# - julia -e 'Pkg.clone(pwd()); Pkg.checkout("RigidBodyDynamics"); Pkg.build("MeshCatMechanisms"); Pkg.test("MeshCatMechanisms"; coverage=true)'; +script: + - julia -e 'Pkg.clone("https://github.com/rdeits/MeshCat.jl"); Pkg.build("MeshCat")' + - julia -e 'Pkg.clone("https://github.com/rdeits/MechanismGeometries.jl"); Pkg.build("MechanismGeometries")' + - julia -e 'Pkg.clone(pwd()); Pkg.checkout("RigidBodyDynamics"); Pkg.build("MeshCatMechanisms"); Pkg.test("MeshCatMechanisms"; coverage=true)'; after_success: # push coverage results to Codecov - julia -e 'cd(Pkg.dir("MeshCatMechanisms")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' From c2e08d99334861d98b83588b2df3ae49e5d8a1c5 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 19:56:55 -0500 Subject: [PATCH 07/12] fix tests --- test/runtests.jl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index b64212d..d5b50af 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,7 +16,7 @@ end @testset "URDF mechanism" begin urdf = joinpath(@__DIR__, "urdf", "Acrobot.urdf") robot = parse_urdf(Float64, urdf) - mvis = MechanismVisualizer(robot, urdf, vis) + mvis = MechanismVisualizer(robot, URDFVisuals(urdf), vis) set_configuration!(mvis, [1.0, -0.5]) @testset "simulation and animation" begin @@ -31,7 +31,7 @@ end robot = parse_urdf(Float64, urdf) RigidBodyDynamics.remove_fixed_tree_joints!(robot) delete!(vis) - mvis = MechanismVisualizer(robot, urdf, vis) + mvis = MechanismVisualizer(robot, URDFVisuals(urdf), vis) set_configuration!(mvis, [0.5]) @testset "simulation and animation" begin @@ -46,16 +46,15 @@ end delete!(vis) mvis = MechanismVisualizer( val.mechanism, - ValkyrieRobot.urdfpath(), - vis, - package_path=[dirname(dirname(ValkyrieRobot.urdfpath()))]) + URDFVisuals(ValkyrieRobot.urdfpath(), package_path=[ValkyrieRobot.packagepath()]), + vis) end @testset "visualization during simulation" begin urdf = joinpath(@__DIR__, "urdf", "Acrobot.urdf") robot = parse_urdf(Float64, urdf) delete!(vis) - mvis = MechanismVisualizer(robot, urdf, vis) + mvis = MechanismVisualizer(robot, URDFVisuals(urdf), vis) result = DynamicsResult{Float64}(robot) function damped_dynamics!(vd::AbstractArray, sd::AbstractArray, t, state) damping = 2. From 198febd9109bc99c2c12351dfb225f17ed40f00c Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 20:08:53 -0500 Subject: [PATCH 08/12] fix demo --- mechanism-demo.ipynb | 9 --------- test/runtests.jl | 11 ++++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mechanism-demo.ipynb b/mechanism-demo.ipynb index e90b01d..07ece6e 100644 --- a/mechanism-demo.ipynb +++ b/mechanism-demo.ipynb @@ -1,14 +1,5 @@ { "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "using Revise" - ] - }, { "cell_type": "code", "execution_count": null, diff --git a/test/runtests.jl b/test/runtests.jl index d5b50af..0081544 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -47,7 +47,16 @@ end mvis = MechanismVisualizer( val.mechanism, URDFVisuals(ValkyrieRobot.urdfpath(), package_path=[ValkyrieRobot.packagepath()]), - vis) + vis[:val_urdf]) + end + + @testset "valkyrie inertias" begin + val = Valkyrie(); + mvis = MechanismVisualizer( + val.mechanism, + Skeleton(), + vis[:val_inertia]) + settransform!(vis[:val_inertia], Translation(0, 2, 0)) end @testset "visualization during simulation" begin From d10dc9e8e3c7f32e4313a33c84406bacb8b37c41 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 20:10:43 -0500 Subject: [PATCH 09/12] missing import --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 0081544..faaa245 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,6 +3,7 @@ using MeshCat using MeshCatMechanisms using RigidBodyDynamics using RigidBodyDynamics.OdeIntegrators +using CoordinateTransformations: Translation using ValkyrieRobot using NBInclude From 76ec105ab8dc32b697b7835733cda1d731901130 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 20:14:50 -0500 Subject: [PATCH 10/12] more test tweaks --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index faaa245..3e90e55 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -63,8 +63,8 @@ end @testset "visualization during simulation" begin urdf = joinpath(@__DIR__, "urdf", "Acrobot.urdf") robot = parse_urdf(Float64, urdf) - delete!(vis) - mvis = MechanismVisualizer(robot, URDFVisuals(urdf), vis) + mvis = MechanismVisualizer(robot, URDFVisuals(urdf), vis[:acrobot][:robot]) + settransform!(vis[:acrobot], Translation(0, -2, 0)) result = DynamicsResult{Float64}(robot) function damped_dynamics!(vd::AbstractArray, sd::AbstractArray, t, state) damping = 2. From 822ffb2eaa6abdb82f8b140369032fd16a9d124c Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 22:29:16 -0500 Subject: [PATCH 11/12] update installation instructions --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e105d50..4fc4c86 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,27 @@ Features: * Animation of robot trajectories from RigidBodyDynamics.jl simulations * Live rendering of simulation progress using the `OdeIntegrators.OdeResultsSink` interface -# Related Projects +## Related Projects MeshCatMechanisms.jl provides similar functionality to [RigidBodyTreeInspector.jl](https://github.com/rdeits/RigidBodyTreeInspector.jl), but is built on top of the lighter-weight MeshCat viewer instead of [DrakeVisualizer.jl](https://github.com/rdeits/DrakeVisualizer.jl). +# Installation + +Stable release: + +```julia +Pkg.add("MeshCatMechanisms") +``` + +Latest and greatest: + +```julia +Pkg.add("MeshCatMechanisms") +Pkg.clone("https://github.com/rdeits/MechanismGeometries.jl") +Pkg.checkout("MeshCatMechanisms") +Pkg.checkout("MeshCat") +``` + # Usage See [mechanism-demo.ipynb](mechanism-demo.ipynb) From 1a082a5abf17870d83703438c9bee76b73dc8671 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Mar 2018 22:37:01 -0500 Subject: [PATCH 12/12] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fc4c86..6dff530 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://travis-ci.org/rdeits/MeshCatMechanisms.jl.svg?branch=master)](https://travis-ci.org/rdeits/MeshCatMechanisms.jl) [![codecov.io](http://codecov.io/github/rdeits/MeshCatMechanisms.jl/coverage.svg?branch=master)](http://codecov.io/github/rdeits/MeshCatMechanisms.jl?branch=master) -MeshCatMechanisms.jl adds support for visualizing mechanisms and robots from [RigidBodyDynamics.jl](https://github.com/tkoolen/RigidBodyDynamics.jl) with [MeshCat.jl](https://github.com/rdeits/MeshCat.jl). +MeshCatMechanisms.jl adds support for visualizing mechanisms and robots from [RigidBodyDynamics.jl](https://github.com/tkoolen/RigidBodyDynamics.jl) with [MeshCat.jl](https://github.com/rdeits/MeshCat.jl). All geometries are constructed using [MechanismGeometries.jl](https://github.com/rdeits/MechanismGeometries.jl). Features: