Gazebo | Ignition | Community
Ask Your Question

How can I declare a variable in model.sdf file?

asked 2016-08-05 09:16:20 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi everyone,

I hope this is not a silly question. Is there a way to declare a variable in model.sdf file of a robot and use it multiple times? I've made a hexapod and it has some fixed values such as link length or width. If I want to change one leg's values I have to do the same for all the others. I believe this is done by xacro files in ROS but what if I want to do this without ROS?

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-05 12:15:38 -0600

chapulina gravatar image

You could use embedded ruby to generate parametrized models.

  • Here's an example of an SDF model with embedded ruby.

  • Here's an example of an SDF world with embedded ruby.

To regenerate the SDF from the erb template in the command line:

erb model.rsdf > model.sdf

Obs: see this answer.

edit flag offensive delete link more


Thank you so much chapulina! This works very well. I was also thinking of something that I can implement a method in the sdf's API in order to declare a variable or anything I wish. For instance, when I look at the joint.sdf file in the sdformat directory, I can see the joint element's attributes or its elements. I tried to make my own element like declaration.sdf and gave a name and a value as attributes. However it didn't work at all. Would there be another way to do so?

elmuhn gravatar imageelmuhn ( 2016-08-08 05:04:15 -0600 )edit
Login/Signup to Answer

Question Tools



Asked: 2016-08-05 09:16:20 -0600

Seen: 4,154 times

Last updated: Aug 05 '16