I'm trying to generate random boxes in a world file for Gazebo simulator. I know how to create a model sdf, and how to include it from the world file.
Now I want to create different sizes of boxes in the world file using xacro and width/height parameters.
I can't get it work. Please help :)
Well, what I am going to describe is an alternative design that may serve as a workaround to your question and it goes like the following steps :
Step 1 : Create your object as a well parametrized xacro file (all parameters are included in the same file). A good tutorial (too long to be included in here) on HowTO this could be found in the Xacro URDF page.
Step 2 : include your xacro in a gazebo-robot launch file and test it's working fine till now. an example of this can be found in PR2 description here:
<!-- Convert an xacro and put on parameter server -->
<param name="robot_description" command="$(find xacro)/xacro.py $(find pr2_description)/robots/pr2.urdf.xacro" />
<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-param robot_description -urdf -model pr2" />
Step 3 : if you consider your object as a robot to launch in a gazebo world, a solution to pass parameters for its creation (in xacro file) could be by passing the needed arguments using prefix:=$(arg value)
like the following(explained in here):
<param name="robot_description" command="$(find xacro)/xacro.py '$(find my_robot_description)/urdf/my_robot.urdf.xacro' prefix:=$(arg ns)" />
in the xacro file you can simply get the passed argument using $(arg prefix)
This way, you can create your object in an xacro file, launch it in Gazebo using a ROS launch file and tweak it according to your needed value.
Furthermore, ROS launch files can pass parameters as well to its contents, so, your values can be also updated directly through command line :
roslaunch your_package launch_file.launch a:=1 b:=5
or stored in a parameter server for retrieval at launch time.
Hope that Helps, Cheers !