Go to the documentation of this file.00001
00002 import sys
00003 import math, numpy as np
00004
00005 import roslib; roslib.load_manifest('hrl_fabric_based_tactile_sensor')
00006 roslib.load_manifest('force_torque')
00007 import rospy
00008
00009 from hrl_msgs.msg import FloatArray
00010
00011 import force_torque.FTClient as ftc
00012 import hrl_lib.util as ut
00013
00014
00015 def adc_data_cb(msg):
00016 global adc_value
00017 adc_value = msg.data[0]
00018
00019 if __name__ == '__main__':
00020 import optparse
00021 p = optparse.OptionParser()
00022
00023 p.add_option('--collect_data', '--cd', action='store_true',
00024 dest='cd',
00025 help='collect FT and ADC data and save to pkl')
00026
00027 p.add_option('--pull_up', '-p', action='store', dest='pull_up',
00028 type=float, help='pull up resistor value')
00029
00030 p.add_option('--contact_area', '--ca', action='store', dest='ca',
00031 type=float, help='contact area (m^2)')
00032
00033 p.add_option('--viz_data', '--vd', action='store_true',
00034 dest='vd',
00035 help='visualize data collected with --cd')
00036
00037 opt, args = p.parse_args()
00038
00039 global adc_value
00040 adc_value = 0
00041
00042 if opt.cd:
00043 if not opt.pull_up:
00044 raise RuntimeError('provide a value for the pull-up resistor')
00045 if not opt.ca:
00046 raise RuntimeError('provide a value for the contact area')
00047
00048 rospy.Subscriber('adc_data', FloatArray, adc_data_cb)
00049
00050 rospy.init_node('taxel_calib_data_collector')
00051
00052 ft_client = ftc.FTClient('force_torque_ft1')
00053 ft_client.bias()
00054
00055 rospy.loginfo('waiting to get adc_value')
00056 while adc_value == 0:
00057 rospy.sleep(0.1)
00058
00059 adc_bias = adc_value
00060
00061 raw_input('Hit ENTER to start recording data')
00062
00063 duration = 20.
00064 t0 = rospy.get_time()
00065 t1 = t0 + duration
00066
00067 ft_l = []
00068 adc_l = []
00069 while rospy.get_time() < t1:
00070 rospy.sleep(0.02)
00071 adc_l.append(adc_value)
00072 ft_l.append(ft_client.read()[2,0])
00073
00074 d = {}
00075 d['adc'] = adc_l
00076 d['ft'] = ft_l
00077 d['adc_bias'] = adc_bias
00078 d['pull_up'] = opt.pull_up
00079 d['contact_area'] = opt.ca
00080
00081 ut.save_pickle(d, 'taxel_ft_calib_data.pkl')
00082
00083 if opt.vd:
00084 import matplotlib.pyplot as pp
00085 import hrl_lib.matplotlib_util as mpu
00086
00087 d = ut.load_pickle('taxel_ft_calib_data.pkl')
00088 ft_l = d['ft']
00089 adc_l = (d['adc_bias'] - np.array(d['adc'])).tolist()
00090
00091 print np.max(ft_l)
00092
00093 mpu.figure()
00094 pp.scatter(adc_l, ft_l, marker='x')
00095 pp.xlabel('ADC bias - ADC')
00096 pp.ylabel('FT_z')
00097 pp.show()
00098
00099