Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import numpy as np, math
00018
00019 import roslib; roslib.load_manifest('hrl_common_code_darpa_m3')
00020 import hrl_lib.viz as hv
00021 import hrl_lib.util as ut
00022 import hrl_lib.transforms as tr
00023
00024 import rospy
00025 import tf
00026
00027 from visualization_msgs.msg import Marker
00028 from hrl_haptic_manipulation_in_clutter_msgs.msg import SkinContact
00029
00030 from hrl_haptic_manipulation_in_clutter_msgs.msg import TaxelArray
00031 from m3skin_ros.msg import TaxelArray as TaxelArray_Meka
00032 from hrl_msgs.msg import FloatArrayBare
00033 from geometry_msgs.msg import Point
00034 from geometry_msgs.msg import Vector3
00035
00036
00037 def taxel_array_cb(ta, callback_args):
00038 sc_pu, tf_lstnr = callback_args
00039 sc = SkinContact()
00040 sc.header.frame_id = '/torso_lift_link'
00041 sc.header.stamp = ta.header.stamp
00042
00043 pts = np.column_stack((ta.centers_x, ta.centers_y, ta.centers_z))
00044 nrmls = np.column_stack((ta.normals_x, ta.normals_y, ta.normals_z))
00045 fs = np.column_stack((ta.values_x, ta.values_y, ta.values_z))
00046
00047 t1, q1 = tf_lstnr.lookupTransform(sc.header.frame_id,
00048 ta.header.frame_id,
00049 rospy.Time(0))
00050
00051
00052 t1 = np.matrix(t1).reshape(3,1)
00053 r1 = tr.quaternion_to_matrix(q1)
00054
00055 if ta.link_names == []:
00056 real_skin_patch = True
00057 else:
00058 real_skin_patch = False
00059
00060
00061 pts = r1 * np.matrix(pts).T + t1
00062 nrmls = r1 * np.matrix(nrmls).T
00063 fs = r1 * np.matrix(fs).T
00064 fmags = ut.norm(fs).A1
00065
00066
00067
00068 if not real_skin_patch:
00069 idxs = np.where(fmags > 0.5)[0]
00070 else:
00071 idxs = np.where(fmags > 0.001)[0]
00072
00073 for i in idxs:
00074 p = pts[:,i]
00075 n1 = nrmls[:,i]
00076 n2 = fs[:,i]
00077
00078 if real_skin_patch:
00079 link_name = ta.header.frame_id
00080 else:
00081 link_name = ta.link_names[i]
00082
00083 sc.locations.append(Point(p[0,0], p[1,0], p[2,0]))
00084 sc.forces.append(Vector3(n2[0,0], n2[1,0], n2[2,0]))
00085 sc.normals.append(Vector3(n1[0,0], n1[1,0], n1[2,0]))
00086 sc.link_names.append(link_name)
00087 sc.pts_x.append(FloatArrayBare(p[0,:].A1))
00088 sc.pts_y.append(FloatArrayBare(p[1,:].A1))
00089 sc.pts_z.append(FloatArrayBare(p[2,:].A1))
00090
00091 sc_pub.publish(sc)
00092
00093
00094
00095 if __name__ == '__main__':
00096 import optparse
00097
00098
00099
00100
00101
00102
00103 node_nm = 'taxel_array_to_skin_contact'
00104
00105
00106
00107 rospy.init_node(node_nm)
00108
00109 tf_lstnr = tf.TransformListener()
00110
00111 skin_topic = '/skin/contacts'
00112 sc_pub = rospy.Publisher(skin_topic, SkinContact)
00113 rospy.Subscriber('/skin/taxel_array', TaxelArray,
00114 taxel_array_cb,
00115 callback_args = (sc_pub, tf_lstnr))
00116 rospy.Subscriber('/skin/taxel_array_meka', TaxelArray_Meka,
00117 taxel_array_cb,
00118 callback_args = (sc_pub, tf_lstnr))
00119 rospy.loginfo('Started taxel_array to skin_contact!')
00120
00121 rospy.spin()
00122
00123