Go to the documentation of this file.00001 import roslib
00002 roslib.load_manifest('pr2_laser_follow_behavior')
00003 import rospy
00004 from geometry_msgs.msg import PointStamped
00005 from geometry_msgs.msg import PoseStamped
00006 import hrl_lib.tf_utils as tfu
00007 import tf
00008
00009 class FollowPointBehavior:
00010
00011 def __init__(self):
00012 rospy.Subscriber('cursor3dcentered', PointStamped, follow_point_cb)
00013 self.move_pub = rospy.Publisher('move_base_simple/goal', PoseStamped)
00014 self.tflistener = tf.TransformListener()
00015
00016 def follow_point_cb(self, point_stamped):
00017 point_head = point_stamped.point
00018
00019 base_T_head = tfu.transform('/base_link', point_stamped.header.frame_id, self.tflistener)
00020 point_mat_head = tfu.translation_matrix([point.x, point.y, point.z])
00021 point_mat_base = base_T_head * point_mat_head
00022 t_base, o_base = tfu.matrix_as_tf(point_mat_base)
00023 x = t_base[0]
00024 y = t_base[1]
00025 angle = math.atan2(y, x)
00026
00027 ps = PoseStamped()
00028 ps.header.frame_id = '/base_link'
00029 ps.pose.position.x = x
00030 ps.pose.position.y = y
00031 ps.pose.position.z = 0.
00032
00033 q = tf.transformations.quaternion_from_euler(angle, 0, 0)
00034 ps.pose.orientation.x = q[0]
00035 ps.pose.orientation.y = q[1]
00036 ps.pose.orientation.z = q[2]
00037 ps.pose.orientation.w = q[3]
00038 self.move_pub.publish(ps)
00039
00040 def run(self):
00041 r = rospy.Rate(10)
00042 while not rospy.is_shutdown():
00043 r.sleep()
00044
00045 if __name__ == '__main__':
00046 rospy.init_node('follow_point_node', anonymous=True)
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067