标签:1.0 name lin 还需 script http code 运算 rop
前言:Xacro是一种宏语言,允许代码复用,使用Xacro可以减少URDF文件中的代码量。
参考自:http://wiki.ros.org/urdf/Tutorials/Using%20Xacro%20to%20Clean%20Up%20a%20URDF%20File
<param name="robot_description" command="xacro --inorder ‘$(find pr2_description)/robots/pr2.urdf.xacro‘" />
在urdf文件顶部,还需要指定命名空间,例如:
<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="firefighter">
<xacro:property name="width" value="0.2" /> <xacro:property name="bodylen" value="0.6" /> <link name="base_link"> <visual> <geometry> <cylinder radius="${width}" length="${bodylen}"/> </geometry> <material name="blue"/> </visual> <collision> <geometry> <cylinder radius="${width}" length="${bodylen}"/> </geometry> </collision> </link>
${}不止能替换值,还可以进行组合,例如:
<xacro:property name=”robotname” value=”marvin” /> <link name=”${robotname}s_leg” />
效果为:
<link name=”marvins_leg” />
可以进行四则运算,例如:
<cylinder radius="${wheeldiam/2}" length="0.1"/> <origin xyz="${reflect*(width+.02)} 0 0.25" />
例程为双腿模型:
<xacro:macro name="leg" params="prefix reflect"> <link name="${prefix}_leg"> <visual> <geometry> <box size="${leglen} 0.1 0.2"/> </geometry> <origin xyz="0 0 -${leglen/2}" rpy="0 ${pi/2} 0"/> <material name="white"/> </visual> <collision> <geometry> <box size="${leglen} 0.1 0.2"/> </geometry> <origin xyz="0 0 -${leglen/2}" rpy="0 ${pi/2} 0"/> </collision> <xacro:default_inertial mass="10"/> </link> <joint name="base_to_${prefix}_leg" type="fixed"> <parent link="base_link"/> <child link="${prefix}_leg"/> <origin xyz="0 ${reflect*(width+.02)} 0.25" /> </joint> <!-- A bunch of stuff cut --> </xacro:macro> <xacro:leg prefix="right" reflect="1" /> <xacro:leg prefix="left" reflect="-1" />
-END-
标签:1.0 name lin 还需 script http code 运算 rop
原文地址:https://www.cnblogs.com/chendeqiang/p/10336160.html