def plot_err_histogram(rel_list, abs_list, title): # plot relative error histogram. max_err = 1.0 bin_width = 0.05 # relative err. bins = np.arange(0. - bin_width / 2. - max_err, max_err + 2 * bin_width, bin_width) hist, bin_edges = np.histogram(np.array(rel_list), bins) mpu.figure() mpu.plot_histogram(bin_edges[:-1] + bin_width / 2., hist, width=bin_width * 0.8, xlabel='Relative Error', plot_title=title) # plot relative error histogram. max_err = 20 bin_width = 2 # relative err. bins = np.arange(0. - bin_width / 2. - max_err, max_err + 2 * bin_width, bin_width) hist, bin_edges = np.histogram(np.array(abs_list), bins) mpu.figure() mpu.plot_histogram(bin_edges[:-1] + bin_width / 2., hist, width=bin_width * 0.8, xlabel='Absolute Error', plot_title=title)
def pull_up_resistor_value(rmax, rmin): n_r = 200 n_pullups = 4 adc_counts = 1024 pullup_best = math.sqrt(rmax * rmin) pullup_max = 2 * pullup_best pullup_min = 0.5 * pullup_best pullup_max = 500 pullup_min = 50 pullup_step = (pullup_max - pullup_min) / n_pullups pullup_arr = np.arange(pullup_min, pullup_max, pullup_step) r_step = (rmax - rmin) / n_r r_var = np.arange(rmin, rmax, r_step) v_cc = 5. v_diff_list = [] mpu.figure() for r_static in pullup_arr: v = r_var / (r_static + r_var) * v_cc pp.plot(r_var, v, mpu.random_color(), label='R1: %.1f' % r_static) v_diff_list.append(v[-1] - v[0]) pp.xlabel('Variable Resistance') pp.ylabel('Voltage') mpu.legend() mpu.figure() pp.plot(pullup_arr, v_diff_list) pp.axvline(pullup_best, c='k', label='Analytically computed optimal value') pp.xlabel('Pull up resistance (ohms)') pp.ylabel('Difference in Voltage') mpu.legend() l1 = (r_static + rmin) / (r_static + rmax) * adc_counts l2 = rmin / rmax * (r_static + rmax) / (r_static + rmin) * adc_counts print 'ADC lost if piezo to GND:', l2 print 'ADC lost if piezo to Vcc:', l1 pp.show()
def pull_up_resistor_value(rmax, rmin): n_r = 200 n_pullups = 4 adc_counts = 1024 pullup_best = math.sqrt(rmax*rmin) pullup_max = 2 * pullup_best pullup_min = 0.5 * pullup_best pullup_max = 500 pullup_min = 50 pullup_step = (pullup_max - pullup_min) / n_pullups pullup_arr = np.arange(pullup_min, pullup_max, pullup_step) r_step = (rmax - rmin) / n_r r_var = np.arange(rmin, rmax, r_step) v_cc = 5. v_diff_list = [] mpu.figure() for r_static in pullup_arr: v = r_var / (r_static + r_var) * v_cc pp.plot(r_var, v, mpu.random_color(), label='R1: %.1f'%r_static) v_diff_list.append(v[-1] - v[0]) pp.xlabel('Variable Resistance') pp.ylabel('Voltage') mpu.legend() mpu.figure() pp.plot(pullup_arr, v_diff_list) pp.axvline(pullup_best, c='k', label='Analytically computed optimal value') pp.xlabel('Pull up resistance (ohms)') pp.ylabel('Difference in Voltage') mpu.legend() l1 = (r_static + rmin) / (r_static + rmax) * adc_counts l2 = rmin / rmax * (r_static + rmax) / (r_static + rmin) * adc_counts print 'ADC lost if piezo to GND:', l2 print 'ADC lost if piezo to Vcc:', l1 pp.show()
def plot_err_histogram(rel_list, abs_list, title): # plot relative error histogram. max_err = 1.0 bin_width = 0.05 # relative err. bins = np.arange(0.-bin_width/2.-max_err, max_err+2*bin_width, bin_width) hist, bin_edges = np.histogram(np.array(rel_list), bins) mpu.figure() mpu.plot_histogram(bin_edges[:-1]+bin_width/2., hist, width=bin_width*0.8, xlabel='Relative Error', plot_title=title) # plot relative error histogram. max_err = 20 bin_width = 2 # relative err. bins = np.arange(0.-bin_width/2.-max_err, max_err+2*bin_width, bin_width) hist, bin_edges = np.histogram(np.array(abs_list), bins) mpu.figure() mpu.plot_histogram(bin_edges[:-1]+bin_width/2., hist, width=bin_width*0.8, xlabel='Absolute Error', plot_title=title)
def which_variable(): r_static = 2e3 r_min = 800. r_max = 5e3 r_step = 10. r_var = np.arange(r_min, r_max, r_step) v_cc = 5. # case I - variable resistor is R2 v1 = r_var / (r_static + r_var) * v_cc # case II - variable resistor is R1 v2 = r_static / (r_static + r_var) * v_cc mpu.figure() pp.plot(r_var, v1, 'b', label='variable R2') pp.plot(r_var, v2, 'g', label='variable R1') pp.xlabel('Variable Resistance') pp.ylabel('Voltage') mpu.legend() pp.show()
rospy.sleep(0.02) adc_l.append(adc_value) ft_l.append(ft_client.read()[2,0]) d = {} d['adc'] = adc_l d['ft'] = ft_l d['adc_bias'] = adc_bias d['pull_up'] = opt.pull_up d['contact_area'] = opt.ca ut.save_pickle(d, 'taxel_ft_calib_data.pkl') if opt.vd: import matplotlib.pyplot as pp import hrl_lib.matplotlib_util as mpu d = ut.load_pickle('taxel_ft_calib_data.pkl') ft_l = d['ft'] adc_l = (d['adc_bias'] - np.array(d['adc'])).tolist() print np.max(ft_l) mpu.figure() pp.scatter(adc_l, ft_l, marker='x') pp.xlabel('ADC bias - ADC') pp.ylabel('FT_z') pp.show()
opt, args = p.parse_args() if not opt.direc: print 'Please specify a directory' sys.exit() nm_l = ut.get_bash_command_output('find ' + opt.direc + ' -name "*.pkl"') color_list = ['r', 'g', 'b'] for nm in nm_l: c = mpu.random_color() color_list.append(c) if True: mpu.figure() for nm, c in zip(nm_l, color_list): d = ut.load_pickle(nm) #d['adc_bias']=1023 # For stretching experiments with Sarvagya force_vs_adc(d, c) #force_vs_adc_2(d, c) pp.xlim((0, 1000)) pp.ylim((-10, 80)) print 'ADC bias: %d' % d['adc_bias'] # mpu.figure() # for nm, c in zip(nm_l, color_list): # d = ut.load_pickle(nm) # plot_uncertainty_in_force(d, c)
opt, args = p.parse_args() if not opt.direc: print 'Please specify a directory' sys.exit() nm_l = ut.get_bash_command_output('find '+opt.direc+' -name "*.pkl"') color_list = ['r', 'g', 'b'] for nm in nm_l: c = mpu.random_color() color_list.append(c) if True: mpu.figure() for nm, c in zip(nm_l, color_list): d = ut.load_pickle(nm) #d['adc_bias']=1023 # For stretching experiments with Sarvagya force_vs_adc(d, c) #force_vs_adc_2(d, c) pp.xlim((0,1000)) pp.ylim((-10,80)) print 'ADC bias: %d'%d['adc_bias'] # mpu.figure() # for nm, c in zip(nm_l, color_list): # d = ut.load_pickle(nm) # plot_uncertainty_in_force(d, c)
adc_l = [] while rospy.get_time() < t1: rospy.sleep(0.02) adc_l.append(adc_value) ft_l.append(ft_client.read()[2, 0]) d = {} d['adc'] = adc_l d['ft'] = ft_l d['adc_bias'] = adc_bias d['pull_up'] = opt.pull_up d['contact_area'] = opt.ca ut.save_pickle(d, 'taxel_ft_calib_data.pkl') if opt.vd: import matplotlib.pyplot as pp import hrl_lib.matplotlib_util as mpu d = ut.load_pickle('taxel_ft_calib_data.pkl') ft_l = d['ft'] adc_l = (d['adc_bias'] - np.array(d['adc'])).tolist() print np.max(ft_l) mpu.figure() pp.scatter(adc_l, ft_l, marker='x') pp.xlabel('ADC bias - ADC') pp.ylabel('FT_z') pp.show()