*******************
Xacro
*******************
Xacro is an Xml macro that introduce the use of macros in an urdf file. It allow the use of variables, math and macros.
And let us divide the robot model in different files.
Xacro syntax
==============
Property
----------
Instead of defining constant values, we can use variables, called property in xacro.
.. code:: xml
In the previous snippet we create two properties with default values: ::
In the ``geometry`` tag, instead of using constant values, we assign the properties just defined to the radius and the length. Note the use of ``${}``.
Math
------
.. code:: xml
Macro
--------
Marco are piece of code that can be used as functions.
.. code:: xml
When need the macro can be called by name:
.. code:: xml
When called, the macro content will placed where is called.
Macros can accept also input parameters:
.. code:: xml
Can be called in this way:
.. code:: xml
Macros input parameters can be also blocks or macros. When we need to pass a block as a parameter to another macro, we precede the parameter name with ``*``.
.. code:: xml
In this snippet, we have 2 parameters. The first parameter ``name`` is a string, the second one ``shape`` is a block.
A block is defined as follow:
.. code:: xml
The macro can be called ?????????????????:
.. code:: xml
Example
---------
Here is defined a macro called leg. As the model have two legs, in order to avoid duplicated code, we define a macro with two paramters,
``prefix`` that is part of the link and joint names. And ``reflect`` to define the position of the leg respect to the axis.
.. code:: xml
Xacro to urdf
================
Once an xacro file is defined it must be converted to urdf file in order to be used. ::
rosrun xacro xacro scara.xacro --inorder > scara_generated.urdf
The command can be integrated inside a launch file.
.. code:: xml
Or better it can be parameterized:
.. code:: xml
We will defined a new launch file:
.. code:: xml
:download:`Download display3.launch <../../../code/Robots/epson_g3_description/launch/display3.launch>`
Scara robot with xacro
==========================
:download:`Download scara.xacro <../../../code/Robots/epson_g3_description/urdf/scara.xacro>`
Include files
==============
When the robot model is complex, it is convenient to divide the definition in different files. Suppose we have a modile robot. We can create at least 2 files. One file to define the wheel and the other one the robot, where the wheel file will be included.
Let' create a file called ``wheel.xacro``, where we define different marcos and properties.
.. code:: xml
This file can be included in other xacro file:
.. code:: xml
And the macro ``wheel`` defined in the file ``wheel.xarco`` can be called:
.. code:: xml