fabric_skin_registration.py
Go to the documentation of this file.
00001 
00002 import math, numpy as np
00003 from enthought.mayavi import mlab
00004 
00005 import roslib; roslib.load_manifest('hrl_fabric_based_tactile_sensor')
00006 roslib.load_manifest('hrl_meka_skin_sensor_darpa_m3')
00007 import rospy
00008 
00009 import hrl_lib.transforms as tr
00010 import hrl_lib.util as ut
00011 
00012 import hrl_meka_skin_sensor_darpa_m3.skin_patch_calibration as spc
00013 from m3skin_ros.srv import None_TransformArrayResponse
00014 from geometry_msgs.msg import Transform
00015 
00016 
00017 def plot_taxel_registration_dict(d, color):
00018     tar = d['transform_array_response']
00019     x_l, y_l, z_l = [], [], []
00020     for t in tar.data:
00021         x_l.append(t.translation.x)
00022         y_l.append(t.translation.y)
00023         z_l.append(t.translation.z)
00024 
00025     mlab.points3d(x_l, y_l, z_l, mode='sphere', color=color, scale_factor=0.002)
00026 
00027 
00028 # rdc - raw data client
00029 def compute_bias(rdc, n):
00030     rospy.loginfo('started bias computation ...')
00031     d_list = []
00032     for i in range(n):
00033         d_list.append(rdc.get_raw_data(fresh = True))
00034 
00035     d_arr = np.row_stack(d_list)
00036     mn = np.mean(d_arr, 0)
00037     std = np.std(d_arr, 0)
00038     bias_mn = mn
00039     bias_std = std
00040     rospy.loginfo('...done')
00041 
00042     return bias_mn, bias_std
00043 
00044 
00045 if __name__ == '__main__':
00046 
00047     if False:
00048         d = ut.load_pickle('taxel_registration_dict.pkl')
00049         plot_taxel_registration_dict(d, (0, 0, 1))
00050         d = ut.load_pickle('bah.pkl')
00051         plot_taxel_registration_dict(d, (0, 1, 0))
00052         mlab.show()
00053 
00054     if True:
00055         # assuming taxels distributed on a cylinder with the z-axis of the
00056         # TF frame corresponding to the axis of the cylinder.
00057         n_circum = 5
00058         n_axis = 3
00059         tf_link_name = '/wrist_LEFT'
00060 
00061         rad = 0.04
00062         dist_along_axis = 0.04
00063         angle_along_circum = 2*math.pi / n_circum
00064 
00065         offset_along_axis = 0.02
00066         offset_along_circum = math.radians(0)
00067 
00068         n_taxels = n_circum * n_axis
00069 
00070         # dummy values
00071         tar = None_TransformArrayResponse()
00072         for i in range(n_taxels):
00073             t = Transform()
00074             t.translation.x = i*dist_along_axis
00075             t.translation.y = i*dist_along_axis
00076             t.translation.z = 0.
00077 
00078             t.rotation.x = 0
00079             t.rotation.y = 0
00080             t.rotation.z = 0
00081             t.rotation.w = 1
00082             tar.data.append(t)
00083 
00084         rospy.init_node('fabric_skin_registration_node')
00085         
00086         rdc = spc.RawDataClient('/fabric_skin/taxels/raw_data')
00087         bias_mn, bias_std = compute_bias(rdc, 20)
00088 
00089         for i in range(n_axis):
00090             for j in range(n_circum):
00091                 raw_input('Press on taxel and hit ENTER')
00092                 dat = rdc.get_raw_data(True)
00093                 min_idx = np.argmin(dat-bias_mn)
00094                 ang = j*angle_along_circum + offset_along_circum
00095                 x = rad * math.cos(ang)
00096                 y = rad * math.sin(ang)
00097                 z = offset_along_axis + i * dist_along_axis
00098 
00099                 rot_mat = tr.Rz(-ang)*tr.Ry(math.radians(-90))
00100                 quat = tr.matrix_to_quaternion(rot_mat)
00101 
00102                 tar.data[min_idx].translation.x = x
00103                 tar.data[min_idx].translation.y = y
00104                 tar.data[min_idx].translation.z = z
00105 
00106                 tar.data[min_idx].rotation.x = quat[0]
00107                 tar.data[min_idx].rotation.y = quat[1]
00108                 tar.data[min_idx].rotation.z = quat[2]
00109                 tar.data[min_idx].rotation.w = quat[3]
00110 
00111         d = {}
00112         d['tf_name'] = tf_link_name
00113         d['transform_array_response'] = tar
00114         ut.save_pickle(d, 'taxel_registration_dict.pkl')
00115 
00116 
00117 
00118 


hrl_fabric_based_tactile_sensor
Author(s): Advait Jain, Advisor: Prof. Charles C. Kemp. Healthcare Robotics Lab, Georgia Tech
autogenerated on Wed Nov 27 2013 12:02:33