Go to the documentation of this file.00001
00002
00003 """
00004 Created on 5/8/15
00005
00006 @author: sampfeiffer
00007
00008 look_hand.py contains... a class to look at
00009 its own hand. It could be easily extended to look
00010 at any tf link
00011 """
00012 __author__ = 'sampfeiffer'
00013
00014
00015
00016
00017
00018
00019 import rospy
00020 import tf.transformations
00021
00022
00023 from control_msgs.msg import PointHeadActionGoal
00024 from geometry_msgs.msg import PointStamped
00025
00026
00027 HEADER = '\033[95m'
00028 OKBLUE = '\033[94m'
00029 OKGREEN = '\033[92m'
00030 WARNING = '\033[93m'
00031 FAIL = '\033[91m'
00032 ENDC = '\033[0m'
00033
00034 LOOK_TO_POINT_AS_GOAL_TOPIC = '/head_controller/point_head_action/goal'
00035
00036 class LookAtMyHand():
00037 """This class does stuff"""
00038
00039 def __init__(self):
00040
00041 rospy.loginfo("Setting publisher to " + LOOK_TO_POINT_AS_GOAL_TOPIC)
00042 self.pub_head_topic = rospy.Publisher(LOOK_TO_POINT_AS_GOAL_TOPIC, PointHeadActionGoal, queue_size=1)
00043
00044 self.tf_l = tf.TransformListener()
00045 rospy.sleep(2.0)
00046
00047
00048 def run(self):
00049 r = rospy.Rate(10)
00050 phag = PointHeadActionGoal()
00051 phag.header.frame_id = "/base_link"
00052 phag.goal.max_velocity = 1.0
00053 phag.goal.min_duration = rospy.Duration(0.2)
00054 phag.goal.target.header.frame_id = "/base_link"
00055 phag.goal.pointing_axis.x = 1.0
00056 phag.goal.pointing_frame = "/head_2_link"
00057 while not rospy.is_shutdown():
00058
00059 ps = PointStamped()
00060 ps.header.stamp = self.tf_l.getLatestCommonTime("/base_link", "/arm_7_link")
00061 ps.header.frame_id = "/arm_7_link"
00062 transform_ok = False
00063 while not transform_ok and not rospy.is_shutdown():
00064 try:
00065 arm7link_ps = self.tf_l.transformPoint("/base_link", ps)
00066 transform_ok = True
00067 except tf.ExtrapolationException as e:
00068 rospy.logwarn("Exception on transforming point... trying again \n(" + str(e) + ")")
00069 rospy.sleep(0.01)
00070 ps.header.stamp = self.tf_l.getLatestCommonTime("/base_link", "/arm_7_link")
00071 phag.goal.target.point = arm7link_ps.point
00072 rospy.loginfo("Sending: " + str(phag))
00073 self.pub_head_topic.publish(phag)
00074 r.sleep()
00075
00076 if __name__ == '__main__':
00077 rospy.init_node('look_at_my_hand')
00078 node = LookAtMyHand()
00079 node.run()
00080
00081
00082