Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

for loop to create multiple objects in gazebo

environment: ros kinetic

I want to use for loop to create multiple objects in Gazebo.

I have achieved loading multiple objects in Gazebo.

The launch file is below:


  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>
  <arg name="world_name" default="$(find object_gazebo)/world/"/>
  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find object_description)/urdf/Banana.xacro'" />

  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="debug" value="$(arg debug)" />
    <arg name="gui" value="$(arg gui)" />
    <arg name="paused" value="$(arg paused)"/>
    <arg name="use_sim_time" value="$(arg use_sim_time)"/>
    <arg name="headless" value="$(arg headless)"/>
    <arg name="world_name" value="$(arg world_name)" />
  <group ns="banana1">
    <param name="tf_prefix" value="banana1_tf" />
    <include file="$(find object_gazebo)/launch/banana_base.launch" >
            <arg name="init_pose" value="-x 0 -y 0 -z 1.2 -R 1.570795 -P 1.570795 -Y 1.570795" />
            <arg name="robot_name" value="banana1" />
  <group ns="banana2">
    <param name="tf_prefix" value="banana2_tf" />
    <include file="$(find object_gazebo)/launch/banana_base.launch" >
      <arg name="init_pose" value="-x 0.25 -y 0.25 -z 1.2 -R 1.570795 -P 1.570795 -Y 1.570795" />
      <arg name="robot_name" value="banana2" />


    <arg name="robot_name" />
    <arg name="init_pose" />
    <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
    <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
        -model $(arg robot_name)
        -param /robot_description
        $(arg init_pose)" />
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />

And I can use python to start launch file:

import roslaunch
import rospy

uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
launch = roslaunch.parent.ROSLaunchParent(uuid, ["ws_path/src/object_gazebo/launch/object_world.launch"])

But if I want to create many bananas in Gazebo. This way is not that elegant. Is there any way more elegant?