URDF import
Multibody.jl supports import of URDF files by means of the function urdf2multibody
. The functionality requires the user to install and load the packages LightXML.jl, Graphs.jl, MetaGraphsNext.jl and JuliaFormatter.jl, e.g.,
using Pkg
Pkg.add([
"LightXML",
"Graphs",
"MetaGraphsNext",
"JuliaFormatter"
])
using Multibody, LightXML, Graphs, MetaGraphsNext, JuliaFormatter
Usage
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.
filename = joinpath(dirname(pathof(Multibody)), "..", "test/urdf/doublependulum.urdf")
out = "multibody_urdf.jl"
urdf2multibody(filename; extras=true, out)
include(joinpath(pwd(), out)) # Include model, perform simulation and plotting
Docstring
Multibody.urdf2multibody
— Functionurdf2multibody(filename::AbstractString; extras=false, out=nothing, worldconnection = :rigid)
Translate a URDF file into a Multibody model. Only available if LightXML.jl, Graphs.jl, MetaGraphs.jl and JuliaFormatter.jl are manually installed and loaded by the user.
Example usage:
using Multibody, ModelingToolkit, JuliaSimCompiler, LightXML, Graphs, MetaGraphsNext, JuliaFormatter
urdf2multibody(joinpath(dirname(pathof(Multibody)), "..", "test/doublependulum.urdf"), extras=true, out="/tmp/urdf_import.jl")
Keyword arguments
extras=false
: Iftrue
, the generated code will include package imports, a simulation of the model and a rendering of the model.out=nothing
: If provided, the generated code will be written to this file, otherwise the string will only be returned.worldconnection=:rigid
: If:rigid
, the world frame will be connected to the root link with a rigid connection. If a joint constructor is provided, this component will be instantiated and the root link is connected to the world through this, e.g.,worldconnection = FreeMotion
,()->Prismatic(n=[0, 1, 0])
etc.
render_fixed = false
: Whether or not to render "fixed" joints. These joints aren't actually joints (no degrees of freedom), they are translated to FixedTranslation or FixedRotation components.
Limitations
The URDF import currently has the following limitations:
- Sensors are not imported.
- Transmissions are not imported.
friction
is not translated, butdamping
is translated to a 1DDamping
component attached using anaxisflange
.- Meshes are not fully supported yet, they will be imported as generic shapes (inertial properties are imported).
Structure of the translated model
URDF does not store the transformation implied by links in the link itself, instead, the links store visual and inertial geometry information, while the translation between frames is implied by the origin of the following joint(s). Therefore, we do generally not make use of the r
argument to bodies, and let this be arbitrarily set. The transformation between two joints is instead encoded as a r
and R
arguments to each joint, where joints are wrapped in URDFRevolute
and URDFPrismatic
components respectively. Internally, these wrapper components are comprised of a transformation, FixedTranslation
or FixedRotation
, followed by the actual joint. The interface to these special joints are identical to their non-wrapped counterparts, i.e., they have the frame_a
and frame_b
connectors as expected. Due to this approach, we always connect to the frame_a
connector of links/bodies and let frame_b
be unused.