wait_spawn.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # 
00003 #  testing, do not use 
00004 # 
00005 #
00006 # spawning things "in sequence"
00007 #
00008 # This quick hack waits for a topic to be published (presumably by the model we are waiting for)
00009 # then it accesses the factory service exposed by gazebo_ros_factory plugin for spawning models
00010 #
00011 # a better way to do this is by specifying
00012 # a list of model spawning dependencies, i.e. don't spawn cup unless table is present
00013 # to do this, we must make gazeob expose
00014 #   * service call to access all models
00015 #   * service call to access info about each model
00016 #   * service call to ping, create, kill, modify (pose) models
00017 # I guess one can construct this similar to rostopic or rosnode
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     # wait for p3d if user requests
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     # call service to spawn model
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 


pr2_plugs_gazebo_demo
Author(s): John Hsu
autogenerated on Mon Jan 6 2014 12:04:30