Go to the documentation of this file.00001
00002 import sys
00003 import numpy as np, math
00004
00005 import add_cylinder as ac
00006 import online_collision_detection as ocd
00007
00008 import roslib; roslib.load_manifest('arm_navigation_tutorials')
00009 import rospy
00010 from mapping_msgs.msg import CollisionObject
00011 from visualization_msgs.msg import Marker
00012
00013 import hrl_lib.transforms as tr
00014 import hrl_lib.viz as hv
00015
00016 roslib.load_manifest('hrl_pr2_lib')
00017 import hrl_pr2_lib.pr2_arms as pa
00018
00019 roslib.load_manifest('force_torque')
00020 import force_torque.FTClient as ftc
00021 import tf
00022
00023 class object_ft_sensors():
00024 def __init__(self):
00025 self.obj1_ftc = ftc.FTClient('force_torque_ft2')
00026 self.tf_lstnr = tf.TransformListener()
00027
00028 def get_forces(self, bias = True):
00029
00030
00031 f = self.obj1_ftc.read(without_bias = not bias)
00032 f = f[0:3, :]
00033
00034 trans, quat = self.tf_lstnr.lookupTransform('/torso_lift_link',
00035 '/ft2',
00036 rospy.Time(0))
00037 rot = tr.quaternion_to_matrix(quat)
00038 f = rot * f
00039 return -f
00040
00041 def bias_fts(self):
00042 self.obj1_ftc.bias()
00043
00044
00045 def get_arrow_text_markers(p, f, frame, m_id, duration):
00046 t_now = rospy.Time.now()
00047 q = hv.arrow_direction_to_quat(f)
00048 arrow_len = np.linalg.norm(f) * 0.04
00049
00050 scale = (arrow_len, 0.2, 0.2)
00051 m1 = hv.single_marker(p, q, 'arrow', frame, scale, m_id = m_id,
00052 duration = duration)
00053 m1.header.stamp = t_now
00054
00055 m2 = hv.single_marker(p, q, 'text_view_facing', frame,
00056 (0.1, 0.1, 0.1), m_id = m_id+1,
00057 duration = duration, color=(1.,0.,0.,1.))
00058 m2.text = '%.1f N'%(np.linalg.norm(f))
00059 m2.header.stamp = t_now
00060 return m1, m2
00061
00062
00063 if __name__ == '__main__':
00064 rospy.init_node('force_visualize_test')
00065 marker_pub = rospy.Publisher('/skin/viz_marker', Marker)
00066
00067 fts = object_ft_sensors()
00068 fts.bias_fts()
00069
00070 pr2_arms = pa.PR2Arms()
00071 r_arm, l_arm = 0, 1
00072 arm = r_arm
00073
00074 while not rospy.is_shutdown():
00075 f = fts.get_forces()
00076 p, r = pr2_arms.end_effector_pos(arm)
00077 m1, m2 = get_arrow_text_markers(p, f, 'torso_lift_link', 0, 1.)
00078 marker_pub.publish(m1)
00079 marker_pub.publish(m2)
00080 rospy.sleep(0.1)
00081
00082
00083
00084
00085
00086
00087
00088
00089