ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

for loop to create multiple "group"s (or any element) in launch

asked 2019-09-26 22:43:34 -0500

TouchDeeper gravatar image

updated 2021-01-07 00:53:59 -0500

130s gravatar image

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:

object_world.launch

<launch>
  <!-- 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/table.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)" />
  </include>
  <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" />
    </include>
  </group>
  <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" />
    </include>
  </group>
</launch>

banana_base.launch

<launch>
    <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"
          args="-urdf
        -model $(arg robot_name)
        -param /robot_description
        $(arg init_pose)" />
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
</launch>

And I can use python to start launch file:

import roslaunch
import rospy

uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
roslaunch.configure_logging(uuid)
launch = roslaunch.parent.ROSLaunchParent(uuid, ["ws_path/src/object_gazebo/launch/object_world.launch"])
launch.start()
try:
  launch.spin()
finally:
  launch.shutdown()

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-01-07 00:55:08 -0500

130s gravatar image

I modified the title as the core of your question seems to be about .launch and is irrelevant to Gazebo.

Then populating an xml element N times in .launch is kind of FAQ, and the best I've found is #q229489.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-09-26 22:43:34 -0500

Seen: 1,911 times

Last updated: Jan 07 '21