ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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

3 Answers

Sort by ยป oldest newest most voted

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 2,264 times

Last updated: Sep 14 '18