Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import roslib, time
00020 roslib.load_manifest('gazebo_plugins')
00021
00022 import rospy, sys
00023 import string
00024 import math
00025
00026 from gazebo_plugins import gazebo_plugins_interface
00027 from gazebo_plugins.msg import GazeboModel
00028 from geometry_msgs.msg import Pose, Point, Quaternion
00029 import tf.transformations as tft
00030
00031 wait_topic_initialized = False
00032 def usage():
00033 print '''Commands:
00034 wait_spawn.py <param name> <model name> <namespace> <topic name> <initial pose: x y z R P Y>
00035 '''
00036 sys.exit(1)
00037
00038 def waitForTopic(any):
00039 global wait_topic_initialized
00040 wait_topic_initialized = True
00041
00042 if __name__ == "__main__":
00043 global wait_topic_initialized
00044 print len(sys.argv)
00045 if len(sys.argv) < 11:
00046 print usage()
00047
00048 rospy.init_node("spawn_wait", anonymous=True)
00049
00050
00051 param_name = sys.argv[1]
00052 model_name = sys.argv[2]
00053 namespace = sys.argv[3]
00054 topic_name = sys.argv[4]
00055 lx = float(sys.argv[5])
00056 ly = float(sys.argv[6])
00057 lz = float(sys.argv[7])
00058 rx = float(sys.argv[8])
00059 ry = float(sys.argv[9])
00060 rz = float(sys.argv[10])
00061 q = tft.quaternion_from_euler(rx,ry,rz)
00062 model_msg = GazeboModel(model_name,param_name,GazeboModel.URDF_PARAM_NAME,namespace,Pose(Point(lx,ly,lz),Quaternion(q[0],q[1],q[2],q[3])))
00063
00064
00065 print "waiting for topic ",topic_name," before spawning ",model_name," from param ",param_name," in namespace ",namespace,rx, ry, rz
00066 rospy.Subscriber(topic_name, rospy.AnyMsg, waitForTopic)
00067 while not wait_topic_initialized:
00068 time.sleep(0.5)
00069
00070 print "spawning..."
00071
00072 success = gazebo_plugins_interface.load_model(model_msg)
00073 if success:
00074 print "spawning ",model_name," success!"
00075 else:
00076 print "spawning ",model_name," failed, see console for details."
00077