How to Convert a Xacro File to URDF and Then to SDF

arrow-pointing-right

If you are using ROS and Gazebo and have a URDF robot file that has Xacro in it (i.e. XML macros) like this one, you can convert this file to a pure URDF file in Ubuntu Linux using the following command (everything below goes on the same line inside the Linux terminal window):

xacro two_wheeled_robot.urdf > two_wheeled_robot_without_xacro.urdf

You can then convert the URDF file without Xacro into an SDF file if you wish. Here is the command to do that:


gz sdf -p two_wheeled_robot_without_xacro.urdf > two_wheeled_robot.sdf

That’s it!