Hi,
With the help I got, I was able to do the following:
I create the xacro file for the object:
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="box_obstacle">
<xacro:arg name="row" default="0"/>
<xacro:arg name="col" default="0"/>
<xacro:arg name="width" default="1"/>
<xacro:arg name="height" default="1"/>
<link name="obstacle" type="fixed">
<inertial>
<origin xyz="$(arg row) $(arg col) 0.5" />
<mass value="1.0" />
<inertia ixx="0.0" ixy="0.0" ixz="0.0" iyy="0.0" iyz="0.0" izz="0.0" />
</inertial>
<visual>
<origin xyz="$(arg row) $(arg col) 0.5"/>
<geometry>
<box size="$(arg width) $(arg height) 1" />
</geometry>
</visual>
<collision>
<origin xyz="$(arg row) $(arg col) 0.5"/>
<geometry>
<box size="$(arg width) $(arg height) 1" />
</geometry>
</collision>
</link>
<gazebo reference="obstacle">
<static>true</static>
<material>Gazebo/Black</material>
</gazebo>
</robot>
and my launch file looks like this:
<launch>
<arg name="world" default="$(find my_package)/worlds/empty.world"/>
<!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(arg world)"/>
</include>
<param command="$(find xacro)/xacro.py $(find my_package)/objects/obstacle.urdf.xacro row:=6.5 col:=4.0 width:=3 height:=6" name="obstacle_0" />
<node args="-urdf -param obstacle_0 -model obstacle_0" name="spawn_obstacle_0" output="screen" pkg="gazebo_ros" respawn="false" type="spawn_model" />
<param command="$(find xacro)/xacro.py $(find my_package)/objects/obstacle.urdf.xacro row:=4.5 col:=4.0 width:=1 height:=2" name="obstacle_1" />
<node args="-urdf -param obstacle_1 -model obstacle_1" name="spawn_obstacle_1" output="screen" pkg="gazebo_ros" respawn="false" type="spawn_model" />
<param command="$(find xacro)/xacro.py $(find my_package)/objects/obstacle.urdf.xacro row:=-4.5 col:=-9.0 width:=9 height:=2" name="obstacle_2" />
<node args="-urdf -param obstacle_2 -model obstacle_2" name="spawn_obstacle_2" output="screen" pkg="gazebo_ros" respawn="false" type="spawn_model" />
</launch>
This works fine with few "obstacles", but when I try about 10 (instead of 3 here) the simulator doing weired things (I'm trying to attach images but >5 points are needed :()
<launch>
<arg name="world" default="$(find my_package)/worlds/empty.world"/>
<!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(arg world)"/>
</include>
<param command="$(find xacro)/xacro.py $(find my_package)/objects/obstacle.urdf.xacro row:=6.5 col:=4.0 width:=3 height:=6" name="obstacle_0" />
<node args="-urdf -param obstacle_0 -model obstacle_0" name="spawn_obstacle_0" output="screen" pkg="gazebo_ros" respawn="false" type="spawn_model" />
<param command="$(find xacro)/xacro.py $(find my_package)/objects/obstacle.urdf.xacro row:=4.5 col:=4.0 width:=1 height:=2" name="obstacle_1" />
<node args="-urdf -param obstacle_1 -model obstacle_1" name="spawn_obstacle_1" output="screen" pkg="gazebo_ros" respawn="false" type="spawn_model" />
<param command="$(find xacro)/xacro.py $(find my_package)/objects/obstacle.urdf.xacro row:=-4.5 col:=-9.0 width:=9 height:=2" name="obstacle_2 ...
(more)
Do you want to place models randomly? Or Do you want to place models with different sizes in world? What should be randomly size, position or both?
Hi, tnx for responding. Right now, my world file using multiple times <include> tag to include my object model (in the model the size is fixed to 1x1 and the position isn't determined) and adds <pose> tag for each. I'd like to be able to pass the "size" as a parameter to the included object.