00001
00002
00003 import time
00004
00005 import roslib
00006 roslib.load_manifest('cob_script_server')
00007 import rospy
00008
00009 from simple_script_server import script
00010
00011 import tf
00012 from geometry_msgs.msg import *
00013
00014 class GraspScript(script):
00015
00016 def Initialize(self):
00017
00018
00019 self.sss.init("tray")
00020 self.sss.init("torso")
00021 self.sss.init("arm")
00022 self.sss.init("sdh")
00023 self.sss.init("base")
00024
00025
00026 handle_arm = self.sss.move("arm","folded",False)
00027 handle_torso = self.sss.move("torso","home",False)
00028 handle_sdh = self.sss.move("sdh","home",False)
00029 self.sss.move("tray","down")
00030 handle_arm.wait()
00031 handle_torso.wait()
00032 handle_sdh.wait()
00033 if not self.sss.parse:
00034 print "Please localize the robot with rviz"
00035 self.sss.wait_for_input()
00036
00037 def Run(self):
00038 listener = tf.TransformListener(True, rospy.Duration(10.0))
00039 rospy.sleep(2)
00040
00041
00042 self.sss.move("base","kitchen")
00043 self.sss.move("arm","pregrasp")
00044 handle_sdh = self.sss.move("sdh","cylopen",False)
00045 handle_sdh.wait()
00046
00047
00048 cup = PointStamped()
00049 cup.header.stamp = rospy.Time.now()
00050 cup.header.frame_id = "/map"
00051 cup.point.x = -3.0
00052 cup.point.y = 0.08
00053 cup.point.z = 1.02
00054 rospy.sleep(2)
00055
00056 if not self.sss.parse:
00057 cup = listener.transformPoint('/arm_7_link',cup)
00058 rospy.sleep(2)
00059
00060 cup.point.z = cup.point.z - 0.2
00061
00062
00063 pregrasp_distance = 0.2
00064 grasp_offset = 0.05
00065 self.sss.move_cart_rel("arm",[[cup.point.x, cup.point.y, cup.point.z-grasp_offset-pregrasp_distance], [0, 0, 0]])
00066
00067 self.sss.move_cart_rel("arm",[[0.0, 0.0, pregrasp_distance], [0, 0, 0]])
00068
00069 self.sss.move("sdh","china_cup")
00070
00071 self.sss.move_cart_rel("arm",[[0.2, -0.1, -0.2], [0, 0, 0]])
00072
00073
00074
00075 handle01 = self.sss.move("arm","grasp-to-tray",False)
00076 self.sss.move("tray","up")
00077 handle01.wait()
00078 self.sss.move("arm","tray")
00079 self.sss.move("sdh","cylopen")
00080 self.sss.move_cart_rel("arm",[[0.0, 0.0, -0.1], [0, 0, 0]])
00081 handle01 = self.sss.move("arm","tray-to-folded",False)
00082 self.sss.sleep(4)
00083 self.sss.move("sdh","cylclosed",False)
00084 handle01.wait()
00085
00086
00087 self.sss.move("base","order")
00088 self.sss.say("Here's your drink.")
00089 self.sss.move("torso","nod")
00090
00091 if __name__ == "__main__":
00092 SCRIPT = GraspScript()
00093 SCRIPT.Start()