xacro文件是urdf文件的进阶版,可以通过宏定义,文件包含来精简模型文件。还可以通过定义常量、变量等来反复调用,相当有用哦~~
先贴代码:
<?xml version="1.0" ?>
<robot name="fourwheelrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!--Defineing namespace-->
<!--property list -->
<xacro:property name="M_PI" value="3.141592"/>
<xacro:property name="base_mass" value="20" />
<xacro:property name="base_length" value="0.80"/>
<xacro:property name="base_width" value="0.550"/>
<xacro:property name="base_height" value="0.30"/>
<xacro:property name="wheel_mass" value="2" />
<xacro:property name="wheel_radius" value="0.122"/>
<xacro:property name="wheel_length" value="0.062"/>
<xacro:property name="wheel_joint_x" value="0.25"/>
<xacro:property name="wheel_joint_y" value="0.306"/>
<xacro:property name="wheel_joint_z" value="-0.1"/>
<!--Defineing the colors-->
<material name="black">
<color rgba="0 0 0 1"/>
</material>
<material name="yellow">
<color rgba="1 0.4 0 1"/>
</material>
<!-- Macro for inertia matrix -->
<xacro:macro name="cylinder_inertial_matrix" params="m r h">
<inertial>
<mass value="${m}" />
<inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"
iyy="${m*(3*r*r+h*h)/12}" iyz = "0"
izz="${m*r*r/2}" />
</inertial>
</xacro:macro>
<xacro:macro name="box_inertial_matrix" params="m a b c">
<inertial>
<mass value="${m}" />
<inertia ixx="${m*(b*b+c*c)/12}" ixy = "0" ixz = "0"
iyy="${m*(c*c+a*a)/12}" iyz = "0"