Skip to content

Commit 7d1f362

Browse files
authored
add URDF importer (#143)
* add URDF importer WIP * simplify * importer working reasonably well * add docs * move to extension * add test * add test targets * try again * add forgotten file * add test urdf files * tweak rendering * handle inertia transform
1 parent cb4e11e commit 7d1f362

File tree

13 files changed

+1090
-7
lines changed

13 files changed

+1090
-7
lines changed

Project.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1818

1919
[weakdeps]
2020
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
21+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
22+
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
23+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
24+
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
25+
2126

2227
[extensions]
2328
Render = ["Makie"]
29+
URDF = ["LightXML", "Graphs", "MetaGraphsNext", "JuliaFormatter"]
2430

2531
[compat]
2632
CoordinateTransformations = "0.6"
@@ -39,6 +45,10 @@ julia = "1"
3945
[extras]
4046
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
4147
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
48+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
49+
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
50+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
51+
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
4252

4353
[targets]
44-
test = ["OrdinaryDiffEq", "Test"]
54+
test = ["OrdinaryDiffEq", "Test", "JuliaFormatter", "LightXML", "Graphs", "MetaGraphsNext"]

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ makedocs(;
4343
],
4444
"Rotations and orientation" => "rotations.md",
4545
"3D rendering" => "rendering.md",
46+
"URDF import" => "urdf.md",
4647
])
4748

4849
deploydocs(;

docs/src/urdf.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# URDF import
2+
3+
Multibody.jl supports import of [URDF files](https://wiki.ros.org/urdf) by means of the function [`urdf2multibody`](@ref).
4+
The functionality requires the user to install and load the packages LightXML.jl, Graphs.jl, MetaGraphsNext.jl and JuliaFormatter.jl, e.g.,
5+
```julia
6+
using Pkg
7+
Pkg.add([
8+
"LightXML",
9+
"Graphs",
10+
"MetaGraphsNext",
11+
"JuliaFormatter"
12+
])
13+
using Multibody, LightXML, Graphs, MetaGraphsNext, JuliaFormatter
14+
```
15+
16+
17+
## Usage
18+
The following example demonstrates how to import a URDF file, the translated model is saved in file `multibody_urdf.jl`. `extras = true` makes the file self contained by including package imports, simulation and plotting.
19+
```julia
20+
filename = joinpath(dirname(pathof(Multibody)), "..", "test/doublependulum.urdf")
21+
out = "multibody_urdf.jl"
22+
urdf2multibody(filename; extras=true, out)
23+
24+
include(out) # Include model, perform simulation and plotting
25+
```
26+
27+
```@docs
28+
Multibody.urdf2multibody
29+
```

ext/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[deps]
22
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
3+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
4+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
35
JuliaSimCompiler = "8391cb6b-4921-5777-4e45-fd9aab8cb88d"
6+
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
47
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
8+
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
59
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
610
Multibody = "e1cad5d1-98ef-44f9-a79a-9ca4547f95b9"
711
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"

ext/Render.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ render!(scene, ::typeof(FreeMotion), sys, sol, t) = true
405405

406406

407407
function render!(scene, ::typeof(FixedTranslation), sys, sol, t)
408+
sol(sol.t[1], idxs=sys.render)==true || return true # yes, == true
408409
r_0a = get_fun(sol, collect(sys.frame_a.r_0))
409410
r_0b = get_fun(sol, collect(sys.frame_b.r_0))
410411
color = get_color(sys, sol, :purple)
@@ -508,7 +509,7 @@ function render!(scene, ::typeof(BodyBox), sys, sol, t)
508509
@assert isapprox(det(R0), 1.0, atol=1e-6)
509510
# NOTE: The rotation by this R and the translation with r_shape needs to be double checked
510511

511-
origin = Vec3f(0, -width/2, -height/2) + r_shape
512+
origin = Vec3f(-length/2, -width/2, -height/2) + r_shape
512513
extent = Vec3f(length, width, height)
513514
thing = Makie.Rect3f(origin, extent)
514515
m = mesh!(scene, thing; color, specular = Vec3f(1.5))
@@ -695,6 +696,9 @@ function rot_from_line(d)
695696
RotMatrix{3}([x y d])
696697
end
697698

699+
Multibody.render!(scene, ::typeof(Multibody.URDFRevolute), sys, sol, t) = false
700+
Multibody.render!(scene, ::typeof(Multibody.URDFPrismatic), sys, sol, t) = false
701+
698702
# ==============================================================================
699703
## PlanarMechanics
700704
# ==============================================================================

0 commit comments

Comments
 (0)