voltage_divider.py
Go to the documentation of this file.
00001 
00002 
00003 import numpy as np, math
00004 import matplotlib.pyplot as pp
00005 
00006 import roslib; roslib.load_manifest('sandbox_advait_darpa_m3')
00007 
00008 import hrl_lib.matplotlib_util as mpu
00009 
00010 
00011 
00012 # trying to see if it makes any difference if I choose R1 or R2 to be
00013 # the variable resistor in the voltage divider.
00014 #
00015 # Answer: NO. Something I should have realized without having to make
00016 # a plot.
00017 def which_variable():
00018     r_static = 2e3
00019     r_min = 800.
00020     r_max = 5e3
00021     r_step = 10.
00022     r_var = np.arange(r_min, r_max, r_step)
00023 
00024     v_cc = 5.
00025 
00026     # case I - variable resistor is R2
00027     v1 = r_var / (r_static + r_var) * v_cc
00028     # case II - variable resistor is R1
00029     v2 = r_static / (r_static + r_var) * v_cc
00030 
00031     mpu.figure()
00032     pp.plot(r_var, v1, 'b', label='variable R2')
00033     pp.plot(r_var, v2, 'g', label='variable R1')
00034     pp.xlabel('Variable Resistance')
00035     pp.ylabel('Voltage')
00036 
00037     mpu.legend()
00038     pp.show()
00039 
00040 
00041 # what is the effect of the pull up resistance. Can I choose a value
00042 # that is good for our application?
00043 def pull_up_resistor_value(rmax, rmin):
00044     n_r = 200
00045     n_pullups = 4
00046     adc_counts = 1024
00047     
00048     pullup_best = math.sqrt(rmax*rmin)
00049     pullup_max = 2 * pullup_best
00050     pullup_min = 0.5 * pullup_best
00051 
00052     pullup_max = 500
00053     pullup_min = 50
00054 
00055     pullup_step = (pullup_max - pullup_min) / n_pullups
00056     pullup_arr = np.arange(pullup_min, pullup_max, pullup_step)
00057 
00058     r_step = (rmax - rmin) / n_r
00059     r_var = np.arange(rmin, rmax, r_step)
00060 
00061     v_cc = 5.
00062     v_diff_list = []
00063 
00064     mpu.figure()
00065     for r_static in pullup_arr:
00066         v = r_var / (r_static + r_var) * v_cc
00067         pp.plot(r_var, v, mpu.random_color(), label='R1: %.1f'%r_static)
00068         v_diff_list.append(v[-1] - v[0])
00069 
00070     pp.xlabel('Variable Resistance')
00071     pp.ylabel('Voltage')
00072 
00073     mpu.legend()
00074 
00075     mpu.figure()
00076     pp.plot(pullup_arr, v_diff_list)
00077     pp.axvline(pullup_best, c='k', label='Analytically computed optimal value')
00078     pp.xlabel('Pull up resistance (ohms)')
00079     pp.ylabel('Difference in Voltage')
00080     mpu.legend()
00081 
00082     l1 = (r_static + rmin) / (r_static + rmax) * adc_counts
00083     l2 = rmin / rmax * (r_static + rmax) / (r_static + rmin) * adc_counts
00084 
00085     print 'ADC lost if piezo to GND:', l2
00086     print 'ADC lost if piezo to Vcc:', l1
00087 
00088     pp.show()
00089 
00090 
00091 
00092 if __name__ == '__main__':
00093     #which_variable()
00094 
00095     # Velostat
00096     rmax = 5e3
00097     rmin = 100
00098 
00099     # Eeonyx LTT-SL-PA-MM-1-58B
00100     #rmax = 15e3
00101     #rmin = 1000
00102 
00103     # Eeonyx LR-SL-PA-MM-1-54
00104     #rmax = 15e3
00105     #rmin = 1500
00106 
00107     # Eeonyx LVY-SL-PA-10E6 RP-3-89-3
00108     #rmax = 1.5e6
00109     #rmin = 150e3
00110 
00111     # Eeonyx NW170-SL-PA
00112     #rmax = 1.5e3
00113     #rmin = 130
00114 
00115     pull_up_resistor_value(rmax, rmin)
00116 
00117 
00118 
00119 


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