Skip to content

feat(args): Allow specifying dynamic arg#382

Closed
peci1 wants to merge 1 commit intoros:ros2from
peci1:patch-2
Closed

feat(args): Allow specifying dynamic arg#382
peci1 wants to merge 1 commit intoros:ros2from
peci1:patch-2

Conversation

@peci1
Copy link
Copy Markdown
Contributor

@peci1 peci1 commented Mar 30, 2026

This PR allows a macro to specify args whose names are defined by the macro params, e.g.

<xacro:macro name="test" params="name">
  <xacro:arg name="${name}_arg" default="test" />
  <link name="$(arg ${name}_arg)" />
</xacro:macro>
<xacro:test name="a" />

This Xacro snippet defines argument a_arg which can be either defaulted or read from CLI args.

Without this PR, the above specification works only when the arg is passed from CLI and it doesn't work when the default should have been used.

I know this is a bit of double evaluation, but this one seems pretty useful to me. The use-case I'd like to get is a general macro for calibrated joints like this one:

<xacro:macro name="calibrated_fixed_joint" params="name parent child prefix:='' lump:='1'">
    <xacro:if value="${prefix == ''}">
        <xacro:property name="pref" value="${child}" />
    </xacro:if>
    <xacro:if value="${prefix != ''}">
        <xacro:property name="pref" value="${prefix}" />
    </xacro:if>
    <xacro:arg name="${pref}_pos_x" default="0.0" />
    <xacro:arg name="${pref}_pos_y" default="0.0" />
    <xacro:arg name="${pref}_pos_" default="0.0" />
    <xacro:arg name="${pref}_rpy_r" default="0.0" />
    <xacro:arg name="${pref}_rpy_p" default="0.0" />
    <xacro:arg name="${pref}_rpy_y" default="0.0" />
    <xacro:fixed_joint name="${name}" parent="$(arg prefix)${parent}" child="$(arg prefix)${child}"
                       xyz="$(arg ${pref}_pos_x) $(arg ${pref}_pos_y) $(arg ${pref}_pos_z)"
                       rpy="$(arg ${pref}_rpy_r) $(arg ${pref}_rpy_p) $(arg ${pref}_rpy_y)"
                       lump="${lump}"/>
</xacro:macro>

Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
@rhaschke
Copy link
Copy Markdown
Contributor

rhaschke commented Apr 7, 2026

Thanks for this improvement. Merged via da4b384 / 5dccc59.

@rhaschke rhaschke closed this Apr 7, 2026
@peci1
Copy link
Copy Markdown
Contributor Author

peci1 commented Apr 7, 2026

Thanks! I see you're still keping noetic-devel alive, that's nice. I guess this is for ROS-O?

@rhaschke
Copy link
Copy Markdown
Contributor

rhaschke commented Apr 7, 2026

Thanks! I see you're still keping noetic-devel alive, that's nice. I guess this is for ROS-O?

Yes, indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants