Skip to content

Adding support for python macros #168

@Zabot

Description

@Zabot

A while back I wrote a python script that generated static xacro macros from a directory of .stls that could be imported into you main .xacro as hardware.xacro and significantly simplified the robot description. Unfortunately it was limited in the macros it could generate, because the support for mathematical operations in xacro is limited. We could allow for some more complex xacro macros with some kind of <xacro:python> block that functions similarly to a macro block, but replaces the contents with the value returned by a python function, something along these lines:

def mesh_link(name, mesh):
    # Calculate bounding box and inertial tensor from STL
    visual_block = ...
    collision_block = ...
    inertial_block = ...
    return '<link name="{}">{}{}{}</link>'
        .format(name, visual_block, inertial_block, collision_block)
<xacro:python name="mesh_link" name="wheel"
    mesh="$(find robot_description)/meshes/wheel.stl"/>

My mesh property calculation macro is the only concrete use case I've come up with so far, but I could imagine some other more powerful macros that further simplify the process of robot description. What do you all think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions