xacro宏中*参数块用法

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的介绍与使用

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
URDF是一种机器人描述文件格式,用于定义机器人的结构和几何特征。而Xacro是一种基于XML的机器人描述语言,可以使用(macros)来简化URDF的编写和维护。 将URDF文件转换为Xacro格式可以带来一些优势。首先,使用Xacro可以减少URDF文件的大小和复杂性。通过定义和重复使用,可以将重复、模板化的部分抽象出来,并在需要的地方进行引用。这样,我们可以避免在URDF文件不断重复编写相似的代码,显著简化了文件结构。 其次,Xacro还支持参数化和条件逻辑。这意味着我们可以根据需要调整机器人的参数,例如尺寸、质量或其它属性,而无需更改整个URDF文件。此外,我们还可以使用条件语句来编写更灵活的机器人模型,以适应不同的应用场景和需求。 最后,Xacro还支持包含其他文件,并且具备更强大的组织结构和层次化描述功能。我们可以将机器人的各个组件拆分为不同的文件,并通过包含(include)语句将它们整合在一起。这使得文件的组织和维护更加方便,也方便进行团队协作开发。 总的来说,通过将URDF转换为Xacro格式,我们可以更高效地编写和维护机器人模型。它简化了URDF文件的编写、减少了冗余代码、支持机器人参数化和条件逻辑,并且具备更强大的组织结构。这些优势使得URDF转Xacro成为建模机器人的一种常用方
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值