posearray_wrench_publisher.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import roslib
00004 roslib.load_manifest('tf')
00005 roslib.load_manifest('rospy')
00006 roslib.load_manifest('adl_pr2_log')
00007 roslib.load_manifest('geometry_msgs')
00008 import rospy, optparse, math, time
00009 import numpy as np
00010 import tf
00011 from hrl_lib.msg import WrenchPoseArrayStamped
00012 from geometry_msgs.msg import WrenchStamped
00013 from geometry_msgs.msg import Pose
00014 
00015 
00016 
00017 def log_parse():
00018         parser = optparse.OptionParser('Input the source frame name \
00019                 and the target frame name')
00020 
00021         parser.add_option("-t", "--tool", action="store", type="string",\
00022                 dest="tool_frame", default="l_gripper_tool_frame")
00023         (options, args) = parser.parse_args()
00024 
00025         return options.tool_frame
00026 
00027 
00028 class posearray_wrench_publisher():
00029         def __init__(self):
00030                 self.tool_frame = '/'+log_parse()
00031                 self.head_frame = '/ellipse_frame'
00032 #               self.head_frame = '/'+log_parse()
00033                 self.torso_frame = '/torso_lift_link'
00034                 self.base_frame = '/base_link'
00035                 ft_topic = '/netft_gravity_zeroing/wrench_zeroed'
00036 
00037                 rospy.init_node('adl_poses_wrench', anonymous = True)
00038                 self.pub = rospy.Publisher('/adl_wrench_posearray',\
00039                                 WrenchPoseArrayStamped)
00040                 self.tflistener = tf.TransformListener()
00041                 self.force_sub = rospy.Subscriber(ft_topic, WrenchStamped, self.force_cb)
00042                 self.msg = WrenchPoseArrayStamped()
00043                 self.tool_pose = Pose()
00044                 self.head_pose = Pose()
00045                 self.torso_pose = Pose()
00046 
00047 
00048         def force_cb(self, f_msg):
00049                 self.msg.wrench = f_msg.wrench          
00050 
00051 
00052         def pose_wrench_pub(self):
00053                 while not rospy.is_shutdown():
00054                         self.tool_p, self.tool_q = self.tflistener.lookupTransform\
00055                                 (self.base_frame, self.tool_frame, rospy.Time(0))
00056                         self.head_p, self.head_q = self.tflistener.lookupTransform\
00057                                 (self.base_frame, self.head_frame, rospy.Time(0))
00058                         self.torso_p, self.torso_q = self.tflistener.lookupTransform\
00059                                 (self.base_frame, self.torso_frame, rospy.Time(0))
00060                         self.msg.header.stamp = rospy.Time.now()
00061                         self.msg.header.frame_id = self.base_frame
00062                         self.msg.poses = []
00063 
00064 #               poses[0] is the tool frame
00065                         self.tool_pose.position.x = self.tool_p[0]
00066                         self.tool_pose.position.y = self.tool_p[1]
00067                         self.tool_pose.position.z = self.tool_p[2]
00068                         self.tool_pose.orientation.x = self.tool_q[0]
00069                         self.tool_pose.orientation.y = self.tool_q[1]
00070                         self.tool_pose.orientation.z = self.tool_q[2]
00071                         self.tool_pose.orientation.w = self.tool_q[3]
00072                         self.msg.poses.append(self.tool_pose)
00073 #               poses[1] is the head frame
00074                         self.head_pose.position.x = self.head_p[0]
00075                         self.head_pose.position.y = self.head_p[1]
00076                         self.head_pose.position.z = self.head_p[2]
00077                         self.head_pose.orientation.x = self.head_q[0]
00078                         self.head_pose.orientation.y = self.head_q[1]
00079                         self.head_pose.orientation.z = self.head_q[2]
00080                         self.head_pose.orientation.w = self.head_q[3]
00081                         self.msg.poses.append(self.head_pose)
00082 #               poses[2] is the tool frame
00083                         self.torso_pose.position.x = self.torso_p[0]
00084                         self.torso_pose.position.y = self.torso_p[1]
00085                         self.torso_pose.position.z = self.torso_p[2]
00086                         self.torso_pose.orientation.x = self.torso_q[0]
00087                         self.torso_pose.orientation.y = self.torso_q[1]
00088                         self.torso_pose.orientation.z = self.torso_q[2]
00089                         self.torso_pose.orientation.w = self.torso_q[3]
00090                         self.msg.poses.append(self.torso_pose)
00091 
00092                         self.pub.publish(self.msg)
00093 #                       print '\nwrench:\n ', self.msg.wrench
00094 #                       print '\ntool_pose:\n ', self.msg.poses[0]
00095                         rospy.sleep(1/100.)
00096 
00097 
00098 if __name__ == '__main__':
00099         data = posearray_wrench_publisher()
00100         rospy.sleep(1)
00101         try:
00102                 data.pose_wrench_pub()
00103         except rospy.ROSInterruptException: pass
00104 


adl_pr2_log
Author(s): Aaron King
autogenerated on Wed Nov 27 2013 12:19:09