URDF Templating

URDF files let you explain the physical characteristics of your robot to a physics engine. Thats great. The bummer is the files tend to get long, and they are in XML (sigh).

In an attempt to wrangle Beaker’s growing URDF file, I decided to use a templating engine, Mustache. Because Mustache is in Ruby, I get variables (and all the power of Ruby) built in.

Now my main URDF file looks like this:

  {{> Colors}}

  {{> Body}}

  {{> Face}}

  {{#right_side}}

  {{> Wheel}}

  {{> wheel_indicator}}

  {{/right_side}}

  {{#left_side}}

  {{> Wheel}}

  {{> wheel_indicator}}

  {{/left_side}}

Now instead of hunting around a big XML file for Beaker’s wheels (and usually having to change a value in two places), I have a tiny (relatively speaking) wheel file.

Note I did not go crazy and turn all the values into variables. I variable-ized the values that might change as I tinker around.

Show me the Code

The folder for these templates can be found here. The final generated URDF file can be found here. The tiny script that does the building can be found here, and is run by simply calling

ruby instrutions.rb

What about Xacro

There is something in the ROS ecodsystem called Xacro, which is a macro language to achieve similar things. I just like Ruby. Ruby is our friend. And I like using a dedicated template engine. And I like Ruby.