for loop to create multiple "group"s (or any element) in launch
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?