#!/usr/bin/env python

import sys
import rospy
from gazebo_msgs.srv import *
from geometry_msgs.msg import Pose

model_database_template = """<sdf version="1.4">
  <world name="default">
    <include>
      <uri>model://MODEL_NAME</uri>
    </include>
  </world>
</sdf>""" 

def spawn_model(model_name,model_xml,robot_namespace, initial_pose, reference_frame):
    rospy.wait_for_service('/gazebo/spawn_model')
    try:
        spawn_model = rospy.ServiceProxy('/gazebo/spawn_model', spawn_model)
        resp1 = spawn_model(model_name,model_xml,robot_namespace, initial_pose, reference_frame)
        return resp1.success
    except rospy.ServiceException, e:
        print "Service call failed: %s"%e

if __name__ == "__main__":
    if len(sys.argv) > 1:
        rospy.init_node('spawn_model')
        initial_pose = Pose()
        model_name = sys.argv[1]
        model_xml = open("../models/ROSCock.sdf").read()
        robot_namespace = rospy.get_namespace()
        reference_frame = ""
        resp = spawn_model(model_name,model_xml,robot_namespace,initial_pose, reference_frame)
