cody_tactile_sleeve_driver_node.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import sys
00004 import math, numpy as np
00005 
00006 import roslib; roslib.load_manifest('hrl_fabric_based_tactile_sensor')
00007 import rospy
00008 from hrl_msgs.msg import FloatArray
00009 
00010 import hrl_lib.util as ut
00011 import hrl_lib.transforms as tr
00012 
00013 import hrl_fabric_based_tactile_sensor.adc_publisher_node as apn
00014 
00015 from m3skin_ros.msg import RawTaxelArray
00016 from geometry_msgs.msg import Transform
00017 
00018 from m3skin_ros.srv import None_TransformArray, None_TransformArrayResponse
00019 from m3skin_ros.srv import None_String
00020 
00021 
00022 class Tactile_Sleeve():
00023     def __init__(self):
00024         self.tar_forearm = None_TransformArrayResponse()
00025         self.setup_forearm_taxels_transforms()
00026 
00027         self.tar_wrist = None_TransformArrayResponse()
00028         self.setup_wrist_taxels_transforms()
00029 
00030     def setup_forearm_taxels_transforms(self):
00031         n_circum = 4
00032         n_axis = 3
00033         self.link_name_forearm = '/wrist_LEFT'
00034 
00035         rad = 0.04
00036         dist_along_axis = 0.065
00037         angle_along_circum = 2*math.pi / n_circum
00038 
00039         offset_along_axis = 0.02
00040         offset_along_circum = math.radians(-45)
00041 
00042         n_taxels = n_circum * n_axis
00043 
00044         self.tar_forearm.data = [None for i in range(n_taxels)]
00045         # mapping the taxels to the raw ADC list.
00046         idx_list = [6,9,0,3,7,10,1,4,8,11,2,5]
00047         for i in range(n_axis):
00048             for j in range(n_circum):
00049                 t = Transform()
00050                 ang = j*angle_along_circum + offset_along_circum
00051                 t.translation.x = rad * math.cos(ang)
00052                 t.translation.y = rad * math.sin(ang)
00053                 t.translation.z = offset_along_axis + i * dist_along_axis
00054 
00055                 rot_mat = tr.Rz(-ang)*tr.Ry(math.radians(-90))
00056                 quat = tr.matrix_to_quaternion(rot_mat)
00057 
00058                 t.rotation.x = quat[0]
00059                 t.rotation.y = quat[1]
00060                 t.rotation.z = quat[2]
00061                 t.rotation.w = quat[3]
00062                 self.tar_forearm.data[idx_list[i*n_circum+j]] = t
00063 
00064     def setup_wrist_taxels_transforms(self):
00065         self.link_name_wrist = '/handmount_LEFT'
00066         n_circum = 4
00067         dist_along_axis = 0.065
00068         angle_along_circum = 2*math.pi / n_circum
00069 
00070         offset_along_circum = math.radians(-45)
00071 
00072         self.tar_wrist.data = [None for i in range(13)]
00073 
00074         # mapping the taxels to the raw ADC list.
00075         idx_list = [6,9,2,5]
00076         n_axis = 1
00077         rad = 0.03
00078         offset_along_axis = -0.04
00079         for i in range(n_axis):
00080             for j in range(n_circum):
00081                 t = Transform()
00082                 ang = j*angle_along_circum + offset_along_circum
00083                 t.translation.x = rad * math.cos(ang)
00084                 t.translation.y = rad * math.sin(ang)
00085                 t.translation.z = offset_along_axis + i * dist_along_axis
00086 
00087                 rot_mat = tr.Rz(-ang)*tr.Ry(math.radians(-90))
00088                 quat = tr.matrix_to_quaternion(rot_mat)
00089 
00090                 t.rotation.x = quat[0]
00091                 t.rotation.y = quat[1]
00092                 t.rotation.z = quat[2]
00093                 t.rotation.w = quat[3]
00094                 self.tar_wrist.data[idx_list[i*n_circum+j]] = t
00095 
00096         # mapping the taxels to the raw ADC list.
00097         idx_list = [8,11,0,3,7,10,1,4]
00098         n_axis = 2
00099         rad = 0.02
00100         offset_along_axis = -0.17
00101         for i in range(n_axis):
00102             for j in range(n_circum):
00103                 t = Transform()
00104                 ang = j*angle_along_circum + offset_along_circum
00105                 t.translation.x = rad * math.cos(ang)
00106                 t.translation.y = rad * math.sin(ang)
00107                 t.translation.z = offset_along_axis + i * dist_along_axis
00108 
00109                 rot_mat = tr.Rz(-ang)*tr.Ry(math.radians(-90))
00110                 quat = tr.matrix_to_quaternion(rot_mat)
00111 
00112                 t.rotation.x = quat[0]
00113                 t.rotation.y = quat[1]
00114                 t.rotation.z = quat[2]
00115                 t.rotation.w = quat[3]
00116                 self.tar_wrist.data[idx_list[i*n_circum+j]] = t
00117 
00118         t = Transform()
00119         t.translation.x = 0.
00120         t.translation.y = 0
00121         t.translation.z = -0.2
00122         rot_mat = tr.Rx(math.radians(180))
00123         quat = tr.matrix_to_quaternion(rot_mat)
00124 
00125         t.rotation.x = quat[0]
00126         t.rotation.y = quat[1]
00127         t.rotation.z = quat[2]
00128         t.rotation.w = quat[3]
00129         self.tar_wrist.data[12] = t
00130 
00131     def local_coord_frames_forearm_cb(self, req):
00132         return self.tar_forearm
00133     
00134     def local_coord_frames_wrist_cb(self, req):
00135         return self.tar_wrist
00136     
00137     def link_name_forearm_cb(self, req):
00138         return self.link_name_forearm
00139 
00140     def link_name_wrist_cb(self, req):
00141         return self.link_name_wrist
00142 
00143 
00144 if __name__ == '__main__':
00145     import optparse
00146     p = optparse.OptionParser()
00147 
00148     p.add_option('--wrist', action='store_true',
00149                  dest='wrist',
00150                  help='node for the wrist taxels of the sleeve')
00151     p.add_option('--forearm', action='store_true',
00152                  dest='forearm',
00153                  help='node for the forearm taxels of the sleeve')
00154     p.add_option('--serial_dev', action='store',
00155                  dest='serial_dev_name', type='string',
00156                  help='path to the arduino serial device')
00157 
00158     opt, args = p.parse_args()
00159 
00160     raw_data_forearm_pub = rospy.Publisher('taxels/raw_data',
00161                                            RawTaxelArray)
00162 
00163     ts = Tactile_Sleeve()
00164 
00165     if opt.forearm:
00166         rospy.Service('taxels/srv/local_coord_frames',
00167                       None_TransformArray, ts.local_coord_frames_forearm_cb)
00168         rospy.Service('taxels/srv/link_name', None_String,
00169                       ts.link_name_forearm_cb)
00170         n_taxels = 12
00171     elif opt.wrist:
00172         rospy.Service('taxels/srv/local_coord_frames',
00173                       None_TransformArray, ts.local_coord_frames_wrist_cb)
00174         rospy.Service('taxels/srv/link_name', None_String,
00175                       ts.link_name_wrist_cb)
00176         n_taxels = 13
00177     else:
00178         rospy.logerr('Specify either --forearm or --wrist')
00179         sys.exit()
00180 
00181     rospy.init_node('fabric_tactile_sleeve_driver_node')
00182 
00183     baudrate = 115200
00184     dev = apn.setup_serial(opt.serial_dev_name, baudrate)
00185 
00186     for i in range(10):
00187         dev.readline()
00188     
00189     rospy.loginfo('Started publishing data')
00190 
00191     rta = RawTaxelArray()
00192     while not rospy.is_shutdown():
00193         rta.val_z = apn.get_adc_data(dev, 16)[0:n_taxels]
00194         raw_data_forearm_pub.publish(rta)
00195 
00196     dev.close()
00197 
00198 


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