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

Using properties

Using xacro, we can declare constants or properties that are the named values inside the xacro file, which can be used anywhere in the code. The main use of these constant definitions is, instead of giving hardcoded values on links and joints, we can keep constants, and it will be easier to change these values rather than finding the hardcoded values and replacing them.

An example of using properties is given here. We declare the base link and the pan link's length and radius. So, it will be easy to change the dimension here rather than changing the values in each one:

  <xacro:property name="base_link_length" value="0.01" /> 
  <xacro:property name="base_link_radius" value="0.2" /> 
  <xacro:property name="pan_link_length" value="0.4" /> 
  <xacro:property name="pan_link_radius" value="0.04" /> 

We can use the value of the variable by replacing the hardcoded value with the following definition:

  <cylinder length="${pan_link_length}" 
radius="${pan_link_radius}"/>

Here, the old value, "0.4", is replaced with "{pan_link_length}", and "0.04" is replaced with "{pan_link_radius}".