Mastering ROS for Robotics Programming(Second Edition)
上QQ阅读APP看书,第一时间看更新

Using macros

One of the main features of xacro is that it supports macros. We can use xacro to  reduce the length of complex definitions. Here is a xacro definition we used in our code for inertial:

<xacro:macro name="inertial_matrix" params="mass"> 
  <inertial> 
       <mass value="${mass}" /> 
          <inertia ixx="0.5" ixy="0.0" ixz="0.0" 
          iyy="0.5" iyz="0.0" izz="0.5" /> 
   </inertial> 
</xacro:macro> 

Here, the macro is named inertial_matrix, and its parameter is mass. The mass parameter can be used inside the inertial definition using ${mass}. We can replace each inertial code with a single line, as given here:

  <xacro:inertial_matrix mass="1"/> 

The xacro definition improved the code readability and reduced the number of lines compared to urdf. Next, we will look at how to convert xacro to a URDF file.