taxel_array_to_skin_contact.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 #
00004 # Sept 6, 2011
00005 # Going to also use this node to interface with the TaxelArray from
00006 # the Meka skin patch. For that I will need to accumulate the received
00007 # TaxelArray messages over time, since a single message will not be
00008 # sufficient to create a complete SkinContact message.
00009 #
00010 # Ignoring this for now and publishing a new SkinContact msg from
00011 # within the TaxelArray callback.
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' # has to be this and no other coord frame.
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                                       #ta.header.stamp)
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     # transform to the torso_lift_link frame.
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     # for fabric sensor and meka sensor, Advait moved the thresholding
00067     # etc within the calibration node. (June 13, 2012)
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 #    p = optparse.OptionParser()
00098 #    p.add_option('--meka_skin_patch', action='store_true',
00099 #                 dest='meka_skin_patch',
00100 #                 help='data coming from Meka skin patch')
00101 #    opt, args = p.parse_args()
00102 
00103     node_nm = 'taxel_array_to_skin_contact'
00104 #    if opt.meka_skin_patch:
00105 #        node_nm = 'taxel_array_to_skin_contact_for_meka_skin_patch'
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 


hrl_common_code_darpa_m3
Author(s): Advait Jain, Marc Killpack. Advisor: Prof. Charlie Kemp. Healthcare Robotics Lab, Georgia Tech
autogenerated on Wed Nov 27 2013 11:34:42