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

Spawn multiple objects in gazebo

asked 2013-01-13 07:07:04 -0500

Webo gravatar image

Hi there,

I'm recently started with ROS and now I'm trying to work with the gazebo simulator.

My question: How can a spawn an object, for example the blue box in the gazebo tutorials, more than one time (on different positions)?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
6

answered 2013-04-19 22:51:07 -0500

prasanna.kumar gravatar image

updated 2013-04-30 11:08:51 -0500

In gazebo you can re-use the same urdf to spawn the same object at different places by using different model names.

rosrun gazebo spawn_model -urdf -file box.urdf -model box1 -x 1.0 -y 1.0 -z 1.0

rosrun gazebo spawn_model -urdf -file box.urdf -model box2 -x 4.0 -y 4.0 -z 1.0
edit flag offensive delete link more
0

answered 2023-02-13 20:16:08 -0500

alexwu gravatar image

updated 2023-02-13 20:21:05 -0500

If you use the urdf_spawn. you can use this

<!-- AR_TAG Gazebo -->
<group ns="robot1">
    <include file="$(find px4)/launch/urdf_spawn.launch">
        <arg name="x" default="4" />
        <arg name="y" default="0.0" />
        <arg name="z" default="0.0" />
        <arg name="urdf_robot_file" default="$(find px4)/urdf/ar_tag.urdf" />
        <arg name="robot_name" default="ar_tag" />
    </include>
</group>

<group ns="robot2">
    <include file="$(find px4)/launch/urdf_spawn.launch">
        <arg name="x" default="4.14" />
        <arg name="y" default="0.0" />
        <arg name="z" default="0.0" />
        <arg name="urdf_robot_file" default="$(find px4)/urdf/ar_tag_s.urdf" />
        <arg name="robot_name" default="ar_tag_s" />
    </include>
</group>

Besides, the urdf_spawn file like this

<?xml version="1.0" encoding="UTF-8"?>
<launch>
    <arg name="x" default="0.0" />
    <arg name="y" default="0.0" />
    <arg name="z" default="0.0" />
    <arg name="urdf_robot_file" default="$(find px4)/urdf/ar_tag.urdf" />
    <arg name="robot_name" default="ar_tag" />

    <!-- This Version was created due to some errors seen in the V1 that crashed GAzebo or went too slow in spawn -->
    <!-- Load the URDF into the ROS Parameter Server -->
    <param name="robot_description" command="cat $(arg urdf_robot_file)" />

    <!-- 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 -x $(arg x) -y $(arg y) -z $(arg z)  -model $(arg robot_name) -param robot_description"/>
</launch>

ref: https://ubungmachtdenmeistersite.word...

edit flag offensive delete link more
0

answered 2013-04-19 15:38:41 -0500

It's too vague, I don't understand your motivation.

A simple solution is using the command(after running Gazebo):

rosrun gazebo spawn_model -urdf -file box.urdf -model box -x 1.0 -y 1.0 -z 1.0
edit flag offensive delete link more
0

answered 2018-09-14 15:24:53 -0500

lucasw gravatar image

Something like the following can be done inside a script, and for example any number of instances spawned in a for loop:

model_xml = rospy.get_param("/foo/robot_description")
pose = Pose()
pose.orientation.w = 1.0

model_name = "foo_" + str(i)  # or whatever, just needs to be unique
# may want to delet the model first
# delete_model = rospy.ServiceProxy('/gazebo/delete_model', DeleteModel)
# delete_model(model_name)

spawn_model = rospy.ServiceProxy('/gazebo/spawn_urdf_model', SpawnModel)
req = SpawnModelRequest()
req.model_name = model_name
req.model_xml = model_xml
# should this be unique so ros_control can use each individually?
req.robot_namespace = "/foo"
req.initial_pose = pose
resp = spawn_model(req)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-01-13 07:07:04 -0500

Seen: 2,722 times

Last updated: Feb 13 '23