# URDF With XACRO ## What is XACRO **URDF** (Unified Robot Description Format) files are often used to describe the physical configuration of a robot. **Xacro** (XML Macros) is an extension of URDF that allows for modularity and reuse of code through macros and parameters. Xacro simplifies complex URDF files by reducing repetition and enabling parameterization. When using Xacros in URDF is it important to remember to add it to the XML file at the beginning. ```xml linenums="1" ... ``` ## XACRO Features Below is a list of the common features of XACRO and how they can be used. ### Variables, Parameters, and Math In XACRO use `xacro:property` to define variables that can be reused or parameterized in the Xacro file. Variables make the URDF more maintainable and flexible. You can math on these store values to help keep the robot dynamic. ```xml linenums="1" ``` ### Macros Xacro allows you to define reusable blocks of XML code using macros. Macros are defined with `` and given a name, then they can be used to repeat a section of XML code. ```xml linenums="1" ``` ### Conditionals Xacro allows the use of `if` and `unless` for conditional logic. This is useful for enabling and disabling features or customizing configurations based on parameters. ```xml linenums="1" ``` ### Loops XACRO also supports looping with `xacro:for`, enabling dynamic generation of repeated elements like links or joints. ```xml linenums="1" ``` ### Include and Modularity Xacro files can include other Xacro or URDF files using ``. This enables modularity, where different parts of a robot description can be stored in separate files. ```xml linenums="1" ``` ## Example XACRO File Here is a example of a URDF file for a small robot that uses XACRO. This is the main file: ```xml title="my_robot.urdf.xacro" linenums="1" ``` This is the file the contains the common properties: ```xml title="common_properties.xacro" linenums="1" ``` This is the file the contains the mobile base: ```xml title="mobile_base.xacro" linenums="1" ``` This is the file the contains the gazebo configs: ```xml title="mobile_base.xacro" linenums="1" Gazebo/Blue Gazebo/Gray Gazebo/Gray Gazebo/Gray 50 base_left_wheel_joint base_right_wheel_joint ${wheel_length + base_width} ${wheel_radius} cmd_vel true true true odom odom base_footprint ``` This is the file the contains the camera configs: ```xml title="mobile_base.xacro" linenums="1" Gazebo/Red 0 0 0 0 0 0 true 10.0 camera_link ```