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

Revision history [back]

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)