Go to the documentation of this file.00001
00002
00003 import roslib; roslib.load_manifest('assistive_teleop')
00004 import rospy
00005 from geometry_msgs.msg import PoseStamped, TwistStamped, Quaternion
00006 from tf import (TransformListener, ExtrapolationException,
00007 LookupException, ConnectivityException)
00008 from tf import transformations as trans
00009
00010 class TwistToPoseConverter(object):
00011 def __init__(self):
00012 self.twist_sub = rospy.Subscriber('/twist_in',
00013 TwistStamped,
00014 self.twist_cb)
00015 self.pose_pub = rospy.Publisher('/pose_out', PoseStamped)
00016 self.tf_listener = TransformListener()
00017 self.ee_frame = rospy.get_param("~ee_frame", '/l_gripper_tool_frame')
00018
00019 def get_ee_pose(self, link, frame='/torso_lift_link'):
00020 """Get current end effector pose from tf."""
00021 try:
00022 now = rospy.Time.now()
00023 self.tf_listener.waitForTransform(frame, link,
00024 now, rospy.Duration(8.0))
00025 pos, quat = self.tf_listener.lookupTransform(frame, link, now)
00026 except (LookupException, ConnectivityException,
00027 ExtrapolationException, Exception) as e:
00028 rospy.logwarn("[Node: "+rospy.get_name()[1:]+"]"+
00029 "TF Failure getting current "+
00030 "end-effector pose:\r\n %s" %e)
00031 return None, None
00032 return pos, quat
00033
00034 def twist_cb(self, ts):
00035 """Get current end effector pose and augment with twist command."""
00036 cur_pos, cur_quat = self.get_ee_pose(self.ee_frame, ts.header.frame_id)
00037 ps = PoseStamped()
00038 ps.header.frame_id = ts.header.frame_id
00039 ps.header.stamp = ts.header.stamp
00040 ps.pose.position.x = cur_pos[0] + ts.twist.linear.x
00041 ps.pose.position.y = cur_pos[1] + ts.twist.linear.y
00042 ps.pose.position.z = cur_pos[2] + ts.twist.linear.z
00043
00044 twist_quat = trans.quaternion_from_euler(ts.twist.angular.x,
00045 ts.twist.angular.y,
00046 ts.twist.angular.z)
00047
00048
00049 final_quat = trans.quaternion_multiply(twist_quat, cur_quat)
00050 ps.pose.orientation = Quaternion(*final_quat)
00051
00052 try:
00053 self.tf_listener.waitForTransform('/torso_lift_link',
00054 ps.header.frame_id,
00055 ps.header.stamp,
00056 rospy.Duration(8.0))
00057 pose_out = self.tf_listener.transformPose('/torso_lift_link', ps)
00058 except (LookupException, ConnectivityException,
00059 ExtrapolationException, Exception) as e:
00060 rospy.logwarn("[Node: "+rospy.get_name()[1:]+"]"+
00061 "TF Failure transforming goal pose"+
00062 "back to torso_lift_link:\r\n %s" %e)
00063 return
00064
00065 self.pose_pub.publish(pose_out)
00066
00067 if __name__=='__main__':
00068 rospy.init_node('twist_to_pose_node')
00069 converter = TwistToPoseConverter()
00070 rospy.spin()