class pend: NP = 400 tmax = 5.0 # We digitize oscillations for 10 seconds looping = False xlabel = 'Seconds' ylabel = 'Volts' size = [100,100] scale = None delay = 0.0 def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self, p): self.ph = p self.ph.select_adc(0) self.ph.set_adc_size(2) self.intro_msg() self.plot2d.setWorld(0, -5, self.tmax, 5) self.plot2d.mark_axes(self.xlabel,self.ylabel) def exit(self): self.looping = False def set_tmax(self,w): d = self.scale.get() self.tmax = float(d) self.plot2d.setWorld(0, -5, self.tmax, 5) self.plot2d.mark_axes(self.xlabel,self.ylabel) def clear(self,e): if self.looping == True: return self.plot2d.delete_lines() self.data.clear() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def calc_g(self,e): if self.data.points == []: return x = self.lentext.get() try: L = float(x) except: self.msgwin.msg('Set the length of the rod', 'red') return import phmath, math dat = [] for k in self.data.points: dat.append([k[0], k[1]]) res = phmath.fit_dsine(dat) fit = [] exp = [] for k in res[0]: fit.append([k[0],k[2]]) exp.append([k[0],k[3]]) self.data.traces.append(fit) self.col = self.data.get_col() self.plot2d.line(fit, self.col) self.col = self.data.get_col() self.plot2d.line(exp, self.col) D = res[1][4] T = 1.0 / res[1][1] r = 0.14 # radius of the rod R = 1.27 # radius of the ball density = 7.8 # density of iron m_rod = math.pi * r**2 * L * density m_ball = math.pi * 4 / 3 * R**3 * density # print m_rod,'',m_ball Lprime = ( (m_rod * L**2)/3 + (m_ball * 2/5 * R**2) + m_ball * \ (L+R)**2 ) / ( (m_rod * L)/2 + m_ball*(L+R) ) g = 4.0 * math.pi**2 * Lprime / (T * T) # print T, Lprime, g, D ss = 'T = %4.3f seconds. Length = %4.2f | g = %4.0f \ cm/sec2 | Damping factor = %4.3f\n'%(T,L,g,D) self.msgwin.showtext(ss) # g2 = 4.0 * math.pi**2 * L / (T * T) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def show_all(self,e): self.plot2d.delete_lines() self.data.index = 0 for tr in self.data.traces: self.plot2d.line(tr,self.data.get_col()) #------------------------------------------------------------------ def start(self,e): if self.ph == None: self.msgwin.msg('Connection not made yet', 'red') return if self.looping == False: # Same color if restarted self.col = self.data.get_col() self.msgwin.msg('Starting Pendulum Waveform digitization') self.looping = True v = self.ph.get_voltage_bip() # First reading is taken self.start_time = v[0] # Remember starting time self.data.points = [(0.0, v[1]/1000.0)] # initialize the list def accept_trace(self): self.data.traces.append(self.data.points) def update(self): if self.looping == False: return val = self.ph.get_voltage_bip() elapsed = val[0] - self.start_time self.data.points.append( (elapsed, val[1]/1000.0) ) self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col) if elapsed >= self.tmax: self.msgwin.msg('Digitization done for %2.1f seconds'%elapsed) self.accept_trace() self.looping = False def refresh(self,e): if self.looping == True: return self.intro_msg() def intro_msg(self): self.clear(None) self.msgwin.clear() self.msgwin.showtext('Connect DC motor output to Ch0, through an amplifier (gain = 100) and the '+\ 'Level Shifter.\nOscillate the pendulum and ') self.msgwin.showlink('Digitize', self.start) self.msgwin.showtext(' for ') if self.scale != None: self.scale.destroy() self.scale = Scale(None, command = self.set_tmax, \ from_ = 1, to=20, orient=HORIZONTAL, length=100, showvalue=1) self.scale.set(int(self.tmax)) self.msgwin.showwindow(self.scale) self.msgwin.showtext(' Seconds.\n') self.msgwin.showlink('Click Here', self.calc_g) self.msgwin.showtext(' to calculate period "T" by fitting the graph.\n Value of "g" is calculated '+\ 'assuming Length of the rod =') self.lentext = Entry(None, width = 4, fg = 'red') self.msgwin.showwindow(self.lentext) self.lentext.insert(END,'11.0') self.msgwin.showtext(' cm. and Bob diameter = 2.54 cm') self.msgwin.showlink('\nSave the latest trace', self.save) self.msgwin.showtext(' or ') self.msgwin.showlink('Save all Traces', self.save_all) self.msgwin.showtext(' to the text file') self.fntext = Entry(None, width =15, fg = 'red') self.msgwin.showwindow(self.fntext) self.fntext.insert(END,'pend.dat') self.msgwin.showtext(' ') self.msgwin.showlink('Display all Traces', self.show_all) self.msgwin.showtext(' ') self.msgwin.showlink('Clear all Traces', self.clear) self.msgwin.showtext(' ') self.msgwin.showlink('Xmgrace', self.analyze) self.msgwin.showtext(' ') self.msgwin.showlink('Refresh', self.refresh) self.msgwin.showtext('\n')
class rodpend: NP = 400 tmax = 10.0 # We digitize oscillations for 10 seconds maxcount = 10 looping = False xlabel = 'Number' ylabel = 'g' size = [100,100] scale = None def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self, p): self.ph = p self.ph.select_adc(0) self.ph.set_adc_size(2) self.intro_msg() self.plot2d.setWorld(0, -5, self.tmax, 5) self.plot2d.mark_axes(self.xlabel,self.ylabel) def exit(self): self.looping = False def clear(self,e): self.plot2d.delete_lines() self.data.clear() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def show_all(self,e): self.plot2d.delete_lines() self.data.index = 0 for tr in self.data.traces: self.plot2d.line(tr,self.data.get_col()) #------------------------------------------------------------------ def start(self,e): x = self.lentext.get() try: self.length = float(x) except: self.msgwin.msg('Set the length of the Pendulum', 'red') return x = self.numtext.get() try: self.maxcount = int(x) except: self.maxcount = 10 self.tmax = self.maxcount if self.ph == None: self.msgwin.msg('Connection not made yet', 'red') return if self.looping == False: # Same color if restarted self.col = self.data.get_col() self.msgwin.msg('Starting Measurement of gravity using Rod Pendulum') self.count = 0 t = self.ph.pendulum_period(3) # Every alternate rising edge # t = self.ph.multi_r2rtime(3,1) if t < 0: self.msgwin.msg('Pendulum Period Timeout Error', 'red') return t = t/1000000.0 self.pisqr = math.pi ** 2 g = 4.0 * self.pisqr * 2.0 * self.length / (3.0 * t * t) self.msgwin.showtext('\nPeriod Gravity') self.msgwin.showtext('\n%6.5f\t%4.1f'%(t,g)) # print self.pisqr, self.length, t, g self.data.points = [(self.count, g)] self.plot2d.setWorld(0, 0, self.tmax, g*1.2) self.plot2d.mark_axes(self.xlabel,self.ylabel) self.looping = True def accept_trace(self): self.data.traces.append(self.data.points) def update(self): if self.looping == False: return t = self.ph.pendulum_period(3) # Every alternate rising edge if t < 0: self.msgwin.msg('Pendulum Period Timeout Error', 'red') self.looping = False return print t t = t/1000000.0 self.pisqr = math.pi ** 2 g = 4.0 * self.pisqr * 2.0 * self.length / (3.0 * t * t) self.data.points.append( (self.count, g) ) self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col) self.msgwin.showtext('\n%6.5f\t%4.1f'%(t,g)) self.count = self.count + 1 if self.count >= self.maxcount: self.looping = False self.msgwin.msg('Measured gravity %d times'%self.count) self.accept_trace() time.sleep(t/2) # Always measure in the same direction def refresh(self,e): self.intro_msg() def intro_msg(self): # self.clear(None) self.msgwin.clear() self.msgwin.showtext('Connect the Light Barrier as shown in the '+\ 'photograph and set the pendulum oscillating. Phoenix will measure '+\ 'the Period of the pendulum and calculate the value of acceleration '+\ 'due to gravity. Measure the length of the pendulum and enter it '+\ 'The pendulum must be vertical in its resting position.\n') self.msgwin.showtext('Oscillate the Pendulum and ') self.msgwin.showlink('Click Here', self.start) self.msgwin.showtext(' to start the measurements.') self.msgwin.showtext(' Length = ') self.lentext = Entry(None, width = 5, fg = 'red') self.msgwin.showwindow(self.lentext) self.lentext.insert(END,'7.0') self.msgwin.showtext(' cm. Number of measurements = ') self.numtext = Entry(None, width = 5, fg = 'red') self.msgwin.showwindow(self.numtext) self.numtext.insert(END,str(self.maxcount)) self.msgwin.showlink('\nSave the latest trace', self.save) self.msgwin.showtext(' or ') self.msgwin.showlink('Save all Traces', self.save_all) self.msgwin.showtext(' to a text file named ') self.fntext = Entry(None, width =15, fg = 'red') self.msgwin.showwindow(self.fntext) self.fntext.insert(END,'rodpend.dat') self.msgwin.showtext(' or ') self.msgwin.showlink('Analyze', self.analyze) self.msgwin.showtext(' data online using Xmgrace.\n') self.msgwin.showlink('Display all Traces', self.show_all) self.msgwin.showtext(' , ') self.msgwin.showlink('Clear all Traces', self.clear) self.msgwin.showtext(' or ') self.msgwin.showlink('Refresh This Window', self.refresh) self.msgwin.showtext('\nCalculated g will be plotted.')
class pt100: NP = 400 delay = 0.03 # minimum delay between voltage reads tmax = 12.0 # Number of seconds for NP reads looping = False xlabel = 'Seconds' ylabel = 'Kelvin' gain = 11.0 # Assume PT100 output is amplified by 11 ccval = 1.0 # CCS nominal value is 1 mA maxtemp = 800.0 size = [100,100] del_scale = None np_scale = None def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self, p): self.ph = p self.ph.select_adc(0) self.ph.set_adc_size(2) self.intro_msg() self.tmax = self.delay * self.NP self.plot2d.setWorld(0, 0, self.tmax, self.maxtemp) self.plot2d.mark_axes(self.xlabel,self.ylabel) def exit(self): self.looping = False def set_delay(self,w): if self.looping: return d = self.del_scale.get() self.delay = float(d)/1000.0 self.plot2d.setWorld(0, 0, self.NP * self.delay, self.maxtemp) self.plot2d.mark_axes(self.xlabel,self.ylabel) if len(self.data.points) < 2: return self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col) def set_NP(self,w): d = self.np_scale.get() self.NP = d self.plot2d.setWorld(0, 0, self.NP * self.delay, self.maxtemp) self.plot2d.mark_axes(self.xlabel,self.ylabel) if len(self.data.points) < 2: return self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col) def clear(self,e): self.plot2d.delete_lines() self.data.clear() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def show_all(self,e): self.plot2d.delete_lines() self.data.index = 0 for tr in self.data.traces: self.plot2d.line(tr,self.data.get_col()) #------------------------------------------------------------------ def start(self,e): if self.ph == None: self.msgwin.msg('Connection not made yet', 'red') return if self.looping == False: # Same color if restarted self.col = self.data.get_col() self.msgwin.msg('Started Temperature Recording') self.looping = True self.data.points = [] def stop(self,e): self.msgwin.msg('Stopped Recording') self.accept_trace() self.looping = False def accept_trace(self): self.data.traces.append(self.data.points) def update(self): if self.looping == False: return if self.delay > 0: time.sleep(self.delay) val = self.ph.get_voltage() if self.data.points == []: self.start_time = val[0] temp = self.mv2cel(val[1]) self.data.points.append( (val[0]-self.start_time, temp) ) if len(self.data.points) < 2: return self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col) if len(self.data.points) >= self.NP: self.msgwin.msg('Temperature recording finished') self.accept_trace() self.looping = False def mv2cel(self,mv): self.offset = 0.0 mv = (mv - self.offset)/self.gain r = mv / self.ccval # Convert resistance to temperature for PT100 r0 = 100.0 A = 3.9083e-3 B = -5.7750e-7 c = 1 - r/r0 b4ac = math.sqrt( A*A - 4 * B * c) t = (-A + b4ac) / (2.0 * B) print t return t + 273 def calibrate(self,e): try: s = self.gaintext.get() self.gain = float(s) s = self.cctext.get() self.ccval = float(s) except: self.msgwin.msg('Error occured during calibration','red') def intro_msg(self): self.clear(None) self.msgwin.clear() self.msgwin.showtext('Resistance of the PT100 sensor is a function '+\ 'of temperature. The sonsor is connected to a 1mA constant current '+\ 'source an the voltage across the sensor is measured after '+\ 'sufficient amplification.') self.msgwin.showlink('Start', self.start) self.msgwin.showtext(' Start Recording Temperature') self.msgwin.showlink('Stop', self.stop) self.msgwin.showtext(' Stop Recording Temperature') self.msgwin.showlink('Save the latest trace', self.save) self.msgwin.showtext(' or ') self.msgwin.showlink('Save all Traces', self.save_all) self.msgwin.showtext(' to a file named ') self.fntext = Entry(None, width =20, fg = 'red') self.msgwin.showwindow(self.fntext) self.fntext.insert(END,'pt100.dat') self.msgwin.showtext(' (You can change the filename)\n') self.msgwin.showlink('Analyze', self.analyze) self.msgwin.showtext(' Process the data using Xmgrace.\n') self.msgwin.showlink('Display all Traces', self.show_all) self.msgwin.showtext(' to see all the data collected and ') self.msgwin.showlink('Clear all Traces', self.clear) self.msgwin.showtext(' Clear Everything ') self.msgwin.showtext('\nSet Maximum Number of Readings') if self.np_scale != None: self.np_scale.destroy() self.np_scale = Scale(None, command = self.set_NP, \ from_ = 10, to=1000, orient=HORIZONTAL, length=100, showvalue = 1) self.np_scale.set(self.NP) self.msgwin.showwindow(self.np_scale) self.msgwin.showtext(' and the Interval between readings ') if self.del_scale != None: self.del_scale.destroy() self.del_scale = Scale(None, command = self.set_delay, \ from_ = 30, to=1000, orient=HORIZONTAL, length=100, showvalue=1) self.del_scale.set(self.delay) self.msgwin.showwindow(self.del_scale) self.msgwin.showtext(' milli seconds.\n') self.msgwin.showtext('For calibration enter the amplifier gain ') self.gaintext = Entry(None, width =10, fg = 'red') self.msgwin.showwindow(self.gaintext) self.gaintext.insert(END,'11.0') self.msgwin.showtext(' and the CCS value') self.cctext = Entry(None, width =10, fg = 'red') self.msgwin.showwindow(self.cctext) self.cctext.insert(END,'1.0') self.msgwin.showtext('mA and ') self.msgwin.showlink('Click Here\n', self.calibrate)
class cap: NP = 200 adc_delay = 20 delay_vals = [10,20,50,100,200,500,1000] xlabel = 'milli seconds' ylabel = 'Volts' size = [100,100] def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self, fd): #Phoenix handler 'ph' is set by the caller self.intro_msg() self.ph = fd try: self.ph.select_adc(0) self.ph.set_adc_size(2) except: self.msgwin.msg('Connection NOT Established','red') def exit(self): # Do cleanup here try: self.ph.disable_set() except: pass def update(self): pass def clear(self,e): self.data.clear() self.plot2d.delete_lines() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def capture_trace(self): # Collect data and store in object 'data' # All conversion to be done here. setWorld according to 'trace' # xscale and yscale are specified # if axes are shown in different units phdata = self.ph.read_block(self.NP, self.adc_delay, 0) self.data.points = [] for k in phdata: self.data.points.append( (k[0]/1000.0, k[1]/1000.0) ) #microsec -> millisec ; millivolts -> volts self.data.traces.append(self.data.points) last = self.data.points[-1][0] second = self.data.points[-2][0] xmax = last + (last-second) self.plot2d.setWorld(0, 0, xmax, 5) # Set scale factors self.plot2d.mark_axes(self.xlabel, self.ylabel) # axes & labels self.plot2d.line(self.data.points, self.data.get_col()) def discharge(self,w): self.ph.write_outputs(8) time.sleep(1) self.ph.enable_set_low(3) self.capture_trace() def charge(self,w): self.ph.write_outputs(0) time.sleep(1) self.ph.enable_set_high(3) self.capture_trace() def set_adc_delay(self,w): d = self.adc_scale.get() self.adc_delay = self.delay_vals[d] if self.ph == None: return self.ph.set_adc_delay(self.adc_delay) self.plot2d.setWorld(0, 0, self.NP * self.adc_delay/1000.0, 5) self.plot2d.mark_axes(self.xlabel, self.ylabel) def calc_cap(self,e): if self.data.points == []: return x = self.restext.get() try: R = float(x) except: self.msgwin.msg('Set the Resistance value', 'red') return import phmath, math dat = [] for k in self.data.points: dat.append([k[0], k[1]]) res = phmath.fit_exp(dat) fit = [] for k in res[0]: fit.append([k[0],k[2]]) self.data.traces.append(fit) self.col = self.data.get_col() self.plot2d.line(fit, self.col) RC = -1.0/res[1][1] C = RC/R # print res[1][1], RC, R, C ss = 'RC = %4.3f . C = %4.3f\n'%(RC,C) self.msgwin.showtext(ss) def refresh(self,e): self.intro_msg() def intro_msg(self): self.clear(None) self.msgwin.clear() self.msgwin.showtext('Connect the Capacitor from CH0 to GND and '+\ 'Resistor from D3out to CH0. The Blue Texts are the Commands.\n') self.msgwin.showlink('Charge', self.charge) self.msgwin.showtext(' or ') self.msgwin.showlink('Discharge.', self.discharge) self.msgwin.showtext(' ') self.msgwin.showlink('Fit the Discharge Curve', self.calc_cap) self.msgwin.showtext(' and calculate the value of capacitance for R = ') self.restext = Entry(None, width = 4, fg = 'red') self.msgwin.showwindow(self.restext) self.restext.insert(END,'1.0') self.msgwin.showtext(' KOhm.\n') self.msgwin.showlink('Save Last Trace', self.save) self.msgwin.showtext(' or ') self.msgwin.showlink('Save all Traces', self.save_all) self.msgwin.showtext(' to a text file named ') self.fntext = Entry(None, width =20, fg = 'red') self.msgwin.showwindow(self.fntext) self.fntext.insert(END,'cap.dat') self.msgwin.showtext(' ') self.msgwin.showlink('Clear Traces', self.clear) self.msgwin.showtext(' ') self.msgwin.showlink('Xmgrace', self.analyze) self.msgwin.showtext(' ') self.msgwin.showlink('Refresh', self.refresh) self.msgwin.showtext('\n') self.adc_scale = Scale(None, command = self.set_adc_delay, \ from_ = 0, to=6, orient=HORIZONTAL, length=100, showvalue=0) self.adc_scale.set(1) self.msgwin.showwindow(self.adc_scale) self.msgwin.showtext(' Change time scale according to RC time constant.\n')
class induction: NP = 200 adc_delay = 500 delay_vals = [200,500,1000] looping = False xlabel = 'milli seconds' ylabel = 'Volts' size = [100,100] def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self,fd): self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000.0, 5) self.plot2d.mark_axes(self.xlabel, self.ylabel) self.intro_msg() self.ph = fd try: self.ph.select_adc(0) self.ph.set_adc_size(2) except: self.msgwin.msg('Connection NOT Established','red') def exit(self): self.looping = False def clear(self,e): self.data.clear() self.plot2d.delete_lines() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def show_all(self,e): self.plot2d.delete_lines() self.data.index = 0 for tr in self.data.traces: self.plot2d.line(tr,self.data.get_col()) def set_adc_delay(self,w): d = self.adc_scale.get() self.adc_delay = self.delay_vals[d] if self.ph == None: return self.ph.set_adc_delay(self.adc_delay) self.plot2d.setWorld(0, -5, self.NP * self.adc_delay/1000, 5) self.plot2d.mark_axes(self.xlabel, self.ylabel) #------------------------------------------------------------------ def start(self,e): if self.ph == None: self.msgwin.msg('Connection not made yet', 'red') return phdata = self.ph.read_block(self.NP, self.adc_delay, 1) if phdata == None: return self.data.points = [] for k in phdata: self.data.points.append( (k[0]/1000.0, k[1]/1000.0) ) # scale & copy self.limit = 0.0 # Find the present signal level for p in self.data.points: if abs(p[1]) > self.limit: self.limit = abs(p[1]) + 0.1 self.looping = True self.msgwin.msg('Scanning for Waveform (amplitude > %4.3f V)'%self.limit) # print self.limit def get_peaks(self): vmin = 5.0 vmax = -5.0 t1 = t2 = 0 for p in self.data.points: if p[1] < vmin: vmin = p[1] t1 = p[0] if p[1] > vmax: vmax = p[1] t2 = p[0] # print vmin, vmax if t1 < t2: # First peak is first return (t1,vmin), (t2,vmax) else: return (t2,vmax),(t1,vmin) def accept_trace(self): # print self.data.points self.data.traces.append(self.data.points) self.msgwin.msg('Waveform Captured. Click on Scan CH0 to repeat') def update(self): if self.ph == None: return if self.looping != True: return try: data = self.ph.read_block(self.NP, self.adc_delay, 1) if data == None: return except: return self.data.points = [] for k in data: self.data.points.append( (k[0]/1000.0, k[1]/1000.0) ) self.plot2d.delete_lines() self.plot2d.line(self.data.points,'black') for p in self.data.points: if abs(p[1]) > self.limit: self.peaks = self.get_peaks() tmax = self.NP * self.adc_delay / 1000.0 # micro to milli secs if self.peaks[0][0] > 0.2*tmax and self.peaks[1][0] < 0.8*tmax: self.looping = False self.accept_trace() break def intro_msg(self): self.clear(None) self.msgwin.clear() self.msgwin.showtext('Connect the coil as shown in the figure.\n') self.msgwin.showlink('Click Here', self.start) self.msgwin.showtext(' to start scanning.\n'+\ 'Drop the magnet into the coil from some height, until a trace is captured.\n'+\ 'You can repeat the whole process to acquire several waveforms.\n') self.msgwin.showlink('Save', self.save) self.msgwin.showtext(' the latest trace or ') self.msgwin.showlink('Save all Traces', self.save_all) self.msgwin.showtext(' to a file named ') self.fntext = Entry(None, width =20, fg = 'red') self.msgwin.showwindow(self.fntext) self.fntext.insert(END,'ind.dat') self.msgwin.showtext(' Send the data to ') self.msgwin.showlink('XmGrace', self.analyze) self.msgwin.showtext('\n') self.msgwin.showlink('View All', self.show_all) self.msgwin.showtext(' Traces captured so far. ') self.msgwin.showlink('Clear all Traces', self.clear)
class gravity: NP = 400 tmax = 10.0 # We digitize oscillations for 10 seconds maxcount = 10 looping = False xlabel = 'Number' ylabel = 'g' size = [100,100] scale = None def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self, p): self.ph = p self.intro_msg() self.plot2d.setWorld(0, -5, self.tmax, 5) self.plot2d.mark_axes(self.xlabel,self.ylabel) def exit(self): self.looping = False def update(self): pass def clear(self,e): self.plot2d.delete_lines() self.data.clear() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def show_all(self,e): self.plot2d.delete_lines() self.data.index = 0 for tr in self.data.traces: self.plot2d.line(tr,self.data.get_col()) #------------------------------------------------------------------ def attach(self,e): x = self.lentext.get() try: self.length = float(x) except: self.msgwin.msg('Set the Height', 'red') return if self.ph == None: self.msgwin.msg('Connection not made yet', 'red') return self.ph.write_outputs(1) self.msgwin.msg('Powered the Electromagnet') def measure(self,e): t = self.ph.clr2rtime(0,0) if t < 0: self.msgwin.msg('Timeout Error', 'red') return elif t < 20: self.msgwin.msg('Connection Error', 'red') return t = t + 4000.0 # 4 ms correction for magnetic retention t = t * 1.0e-6 # usec to sec print t, self.length g = 2.0 * self.length / t ** 2 self.msgwin.showtext('\n%7.6f\t%4.1f'%(t,g)) self.msgwin.msg('Done') def refresh(self,e): self.intro_msg() def intro_msg(self): self.msgwin.clear() self.msgwin.showtext('Connect the Electromagnet between Digital '+\ 'Output D0 and GND. '+\ 'Connect the loudspeaker between GND and the input of the inverting '+\ 'amplifier and set the gain resistor to 100 Ohms. '+\ ' Amplifier output goes to Digital Input D0 through a 1K resistor.\n') self.msgwin.showlink('Click Here', self.attach) self.msgwin.showtext(' to power the Electromagnet.') self.msgwin.showtext(' Height = ') self.lentext = Entry(None, width = 5, fg = 'red') self.msgwin.showwindow(self.lentext) self.lentext.insert(END,'30.0') self.msgwin.showtext(' cm.') self.msgwin.showlink('Click Here', self.measure) self.msgwin.showtext(' to Release the Ball from the magnet.')
class diode: NP = 500 looping = False xlabel = 'Volts' ylabel = 'mA' size = [100,100] dac_voltage = 0.0 adc_voltage = 0.0 step = 39.0 def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self, p): self.ph = p self.ph.select_adc(0) self.ph.set_adc_size(2) self.plot2d.setWorld(0, 0, 5, 5) self.plot2d.mark_axes(self.xlabel, self.ylabel) self.intro_msg() def exit(self): self.looping = False def clear(self,e): self.data.clear() self.plot2d.delete_lines() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def show_all(self,e): self.plot2d.delete_lines() self.data.index = 0 for tr in self.data.traces: self.plot2d.line(tr,self.data.get_col()) #------------------------------------------------------------------ def start(self,e): if self.ph == None: self.msgwin.msg('Connection not made yet', 'red') return if self.looping == False: # Same color if restarted in between self.col = self.data.get_col() self.msgwin.msg('Starting Diode IV measurement') self.data.points = [] self.looping = True self.dac_voltage = 0.0 def accept_trace(self): self.data.traces.append(self.data.points) def update(self): if self.ph == None: return if self.looping != True: return self.ph.set_voltage(self.dac_voltage) time.sleep(0.05) self.adc_voltage = self.ph.get_voltage()[1] # voltage and current converted into volts current = (self.dac_voltage - self.adc_voltage)/1000.0 self.data.points.append( (self.adc_voltage/1000.0, current)) if len(self.data.points) < 2: return self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col) self.dac_voltage = self.dac_voltage + self.step if self.dac_voltage > 5000: self.msgwin.msg('IV Plot Done') self.accept_trace() self.looping = False def intro_msg(self): self.clear(None) self.msgwin.clear() self.msgwin.showtext('Make the connections as shown above. The '+\ 'software changes the DAC voltage from 0 to 5V in steps and '+\ 'measure the resulting voltage across the diode. The current is '+\ 'calculated from the voltages at DAC and CH0, both are known. '+\ 'Connect a 1 uF capacitor from CH0 to ground for better results.'+\ 'You can take multiple traces. The operations are:\n') self.msgwin.showlink('Start', self.start) self.msgwin.showtext(' Start making the IV plot\n') self.msgwin.showlink('Analyze', self.analyze) self.msgwin.showtext(' the data using Xmgrace.\n') self.msgwin.showlink('Save the latest trace', self.save) self.msgwin.showtext(' or ') self.msgwin.showlink('Save all Traces', self.save_all) self.msgwin.showtext(' to a file named ') self.fntext = Entry(None, width =20, fg = 'blue') self.msgwin.showwindow(self.fntext) self.fntext.insert(END,'iv.dat') self.msgwin.showlink('Display all Traces', self.show_all) self.msgwin.showtext(' Shows the data collected so far\n') self.msgwin.showlink('Clear all Traces', self.clear) self.msgwin.showtext(' Clears all the data ')
class gm: NP = 400 countrate = 100.0 # Assume a 100 Hz count rate numtrials = 5 # 5 trials default duration = 1 # count for one second tube_voltage = 0.0 VMIN = 300.0 VOPT = 500.0 VMAX = 902.0 looping = False xlabel = 'Trial' ylabel = 'Count' size = [100,100] scale = None def __init__(self, parent, size, plot, msg): self.parent = parent self.plot2d = plot self.msgwin = msg x = Image.open(abs_path(photograph)) im = x.resize(size) self.size[0] = float(size[0]) self.size[1] = float(size[1]) self.image = ImageTk.PhotoImage(im) self.canvas = Canvas(parent, width = size[0], height = size[1]) self.canvas.create_image(0,0,image = self.image, anchor = NW) self.data = Data() def enter(self, p): self.ph = p self.ph.select_adc(0) self.ph.set_adc_size(2) self.plot2d.setWorld(0, 0, self.countrate, self.numtrials) self.plot2d.mark_axes(self.xlabel,self.ylabel) self.tube_voltage = self.ph.gm_set_voltage(self.VOPT) self.intro_msg() def exit(self): self.looping = False def clear(self,e): if self.looping == True: return self.plot2d.delete_lines() self.data.clear() def save(self,e): fname = self.fntext.get() if fname == None: return self.data.save(fname) self.msgwin.msg('Data saved to '+ fname) def analyze(self,e): self.data.analyze(self.xlabel, self.ylabel) def save_all(self,e): fname = self.fntext.get() if fname == None: return self.data.save_all(fname) self.msgwin.msg('Data saved to '+ fname) def show_all(self,e): self.plot2d.delete_lines() self.data.index = 0 for tr in self.data.traces: self.plot2d.line(tr,self.data.get_col()) #------------------------------------------------------------------ def start(self,e): x = self.durationtext.get() try: self.duration = int(x) except: self.msgwin.msg('Set the Duration of Counting', 'red') return x = self.trialstext.get() try: self.numtrials = int(x) except: self.numtrials = 5 if self.ph == None: self.msgwin.msg('Connection not made yet', 'red') return if self.looping == False: # Same color if restarted self.col = self.data.get_col() self.tube_voltage = self.ph.gm_set_voltage(self.tube_voltage) self.msgwin.msg('GM tube Counting Radiation.') self.msgwin.label.update() self.count = 0 gmc = self.ph.gm_get_count(self.duration) self.msgwin.showtext('\nCounts : %d '%(gmc)) self.data.points = [(self.count, gmc)] self.plot2d.setWorld(0, 0, self.numtrials, gmc * 1.5 + 5) self.xlabel = 'Trial' self.plot2d.mark_axes(self.xlabel,self.ylabel) self.count = self.count + 1 self.looping = True self.doing_gmchar = False def start_gmgraph(self,e): x = self.durationtext.get() try: self.duration = int(x) except: self.msgwin.msg('Set the Duration of Counting', 'red') return if self.looping == False: # Same color if restarted self.col = self.data.get_col() self.msgwin.msg('Drawing GM tube Characteristic (will take time)') self.msgwin.label.update() self.count = 0 self.tube_voltage = self.ph.gm_set_voltage(self.VOPT) gmc_max = self.ph.gm_get_count(self.duration) self.plot2d.setWorld(self.VMIN, 0, self.VMAX*1.1, gmc_max * 2 + 5) self.xlabel = 'Voltage' self.plot2d.mark_axes(self.xlabel,self.ylabel) self.tube_voltage = self.ph.gm_set_voltage(self.VMIN) gmc = self.ph.gm_get_count(self.duration) self.msgwin.showtext('\n(%4.0f,%d) '%(self.tube_voltage,gmc)) self.data.points = [(self.tube_voltage, gmc)] self.count = self.count + 1 self.looping = True self.doing_gmchar = True def accept_trace(self): self.data.traces.append(self.data.points) def update(self): if self.looping == False: return if self.doing_gmchar == True: if self.tube_voltage < 400: self.tube_voltage = self.ph.gm_set_voltage(self.tube_voltage + 20) else: self.tube_voltage = self.ph.gm_set_voltage(self.tube_voltage + 50) gmc = self.ph.gm_get_count(self.duration) self.data.points.append((self.tube_voltage, gmc)) self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col, smooth=False) self.msgwin.showtext('(%4.0f,%d) '%(self.tube_voltage,gmc)) self.count = self.count + 1 if self.tube_voltage > self.VMAX: self.looping = False self.msgwin.msg('GM Tube Characteristic Done.') # self.ph.gm_set_voltage(self.VOPT) self.set_tv(None) self.accept_trace() else: gmc = self.ph.gm_get_count(self.duration) self.data.points.append((self.count, gmc)) self.plot2d.delete_lines() self.plot2d.line(self.data.points, self.col, smooth=False) self.msgwin.showtext('%d '%(gmc)) self.count = self.count + 1 if self.count >= self.numtrials: self.looping = False self.msgwin.msg('Counting Over after %d trials'%self.numtrials) self.accept_trace() def set_tv(self, e): ss = self.tv_text.get() try: vset = float(ss) except: vset = 0 self.tube_voltage = self.ph.gm_set_voltage(vset) ss = '%5.0f'%self.tube_voltage self.gmtv_value.set(ss) def refresh(self,e): self.intro_msg() def intro_msg(self): self.msgwin.clear() self.msgwin.showtext('Connections: (1)Yellow - CNTR (2) Green - CH0 '+\ '(3) Blue - PWG (4) Black - GND (5) Red - 5V.\n','red') self.msgwin.showtext('Enter the Tube voltage ') self.tv_text = Entry(None, width = 5, fg = 'red') self.msgwin.showwindow(self.tv_text) self.tv_text.insert(END, '500') self.msgwin.showtext('Volts and ') self.msgwin.showlink('Click Here ', self.set_tv) self.msgwin.showtext(' to set it. Current Tube Voltage is ') self.gmtv_value = StringVar() self.gmtv_label = Label(None, width=5, textvariable = self.gmtv_value) self.msgwin.showwindow(self.gmtv_label) ss = '%5.0f'%self.tube_voltage self.gmtv_value.set(ss) self.msgwin.showtext('Volts\n') self.msgwin.showtext('Set the duration of Counting to') self.durationtext = Entry(None, width = 5, fg = 'red') self.msgwin.showwindow(self.durationtext) self.durationtext.insert(END,'1') self.msgwin.showtext('seconds and number of trials to') self.trialstext = Entry(None, width = 5, fg = 'red') self.msgwin.showwindow(self.trialstext) self.trialstext.insert(END,str(self.numtrials)) self.msgwin.showtext('.') self.msgwin.showlink('Click Here', self.start) self.msgwin.showtext(' to start counting. ') self.msgwin.showtext('For tube Characteristic ') self.msgwin.showlink('Click Here', self.start_gmgraph) self.msgwin.showtext('\n'); self.msgwin.showlink('Save the latest trace', self.save) self.msgwin.showtext(' or ') self.msgwin.showlink('Save all Traces', self.save_all) self.msgwin.showtext(' to a text file named ') self.fntext = Entry(None, width =15, fg = 'red') self.msgwin.showwindow(self.fntext) self.fntext.insert(END,'gmcount.dat') self.msgwin.showtext(' or ') self.msgwin.showlink('Analyze', self.analyze) self.msgwin.showtext(' data online using Xmgrace.\n') self.msgwin.showtext('You can also do ') self.msgwin.showlink('Display all Traces', self.show_all) self.msgwin.showtext(' , ') self.msgwin.showlink('Clear all Traces', self.clear) self.msgwin.showtext(' or ') self.msgwin.showlink('Refresh This Window', self.refresh) self.msgwin.showtext('\n')