xacro宏中*参数块用法

本文深入解析xacro宏的定义与使用,展示如何通过宏参数实现模块化与复用,特别关注宏参数类型及其在实际场景中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

7.Macros

The main feature of xacro is its support for macros. Define macros with the macro tag, and specify the macro name and the list of parameters. The list of parameters should be whitespace separated. They become macro-local properties.
xacro的主要特性是它对宏的支持。 使用宏标签定义宏,并指定宏名称和参数列表。 参数列表应以空格分隔。 它们变成宏观本地属性。

<xacro:macro name="pr2_caster" params="suffix *origin **content **anothercontent">
  <joint name="caster_${suffix}_joint">
    <axis xyz="0 0 1" />
  </joint>
  <link name="caster_${suffix}">
    <xacro:insert_block name="origin" />
    <xacro:insert_block name="content" />
    <xacro:insert_block name="anothercontent" />
  </link>
</xacro:macro>

<xacro:pr2_caster suffix="front_left">
  <pose xyz="0 1 0" rpy="0 0 0" />
  <container>
    <color name="yellow"/>
    <mass>0.1</mass>
  </container>
  <another>
    <inertial>
      <origin xyz="0 0 0.5" rpy="0 0 0"/>
      <mass value="1"/>
      <inertia ixx="100"  ixy="0"  ixz="0" iyy="100" iyz="0" izz="100" />
    </inertial>
  </another>
</xacro:pr2_caster>

The example declares a macro “pr2_caster”, which takes two parameters: suffix and origin. Note that “origin” is starred. This indicates that origin is a block parameter instead of a simple text parameter. Look ahead to the use of pr2_caster. The suffix property is defined in the pr2_caster tag as an attribute, but no origin property is defined. Instead, origin refers to the first element inside (the “pose” block, in this case). The double-starred version (“content”, “anothercontent”) allows to insert an arbitrary number of elements that are passed within elements subsequently available (“container”, “another” respectively in the example above). This example expands to the following:
该示例声明了一个宏“pr2_caster”,它有两个参数:suffix和origin。 请注意,“origin”已加星标。 这表明origin是一个块参数,而不是一个简单的文本参数。 向前看pr2_caster的使用。 后缀属性在pr2_caster标记中定义为属性,但没有定义origin属性。 相反,origin指的是第一个元素(在这种情况下是“pose”块)。 双星号版本(“content”,“anothercontent”)允许插入在随后可用的元素(在上面的示例中分别是“container”,“another”)中传递的任意数量的元素。 此示例扩展为以下内容:

<joint name="caster_front_left_joint">
  <axis xyz="0 0 1" />
</joint>
<link name="caster_front_left">
  <pose xyz="0 1 0" rpy="0 0 0" />
  <color name="yellow" />
  <mass>0.1</mass>
  <inertial>
    <origin xyz="0 0 0.5" rpy="0 0 0"/>
    <mass value="1"/>
    <inertia ixx="100"  ixy="0"  ixz="0" iyy="100" iyz="0" izz="100" />
  </inertial>
</link>

Multiple block parameters will be processed in the specified order:
将按指定的顺序处理多个块参数:

<xacro:macro name="reorder" params="*first *second">
  <xacro:insert_block name="second"/>
  <xacro:insert_block name="first"/>
</xacro:macro>
<reorder>
  <first/>
  <second/>
</reorder>

参考网址:
ROS wiki:xacro
ROS官方教程[翻译]—xacro的介绍与使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值