def handle_ocv(handle, string, value): handle.ocv() while RealTime.ocv_on(): read = handle.parsedread() appender(read) if not RealTime.TickTock(False): return time.sleep(.01) if string == "galvo": print "equal" handle.galvanostat(value) elif string == "pot": potentiostat(handle, value)
def handle_ocv(handle,string,value): handle.ocv() while RealTime.ocv_on(): read = handle.parsedread() appender(read) if not RealTime.TickTock(False): return time.sleep(.01) if string == "galvo": print "equal" handle.galvanostat(value) elif string == "pot": potentiostat(handle,value)
def runGalvo(curr1=0.002, curr2=-0.002, vmax=1.6, vmin=0.9, cycles=4): #connecto to ardustat and setup resistance table #for i in range (0,3): a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) read = a.parsedread() print "Resistance table loaded" time.sleep(1) #create arrays + a function for logging data """ subplot(3,1,1) potLine, = plot(times,potential,'.') title("Potential vs. Time") ylabel("Potential (V)") subplot(3,1,2) curLine, = plot(times,current,'.') title("Current vs. Time") ylabel("Current (A)") subplot(3,1,3) resLine, = plot(times,numpy.array(potential)/numpy.array(current)) title("Resistance vs. Time") ylabel("Resistance (Ohms)") xlabel("Time (s)") #ion() # interaction mode needs to be turned off x = arange(0,2*pi,0.01) # we'll create an x-axis from 0 to 2 pi line, = plot(x,x) # this is our initial plot, and does nothing line.axes.set_ylim(-3,3) # set the range for our plot starttime = time.time() # this is our start time t = 0 # this is our relative start time """ """ #Step through values output = 0 print a.ocv() print -1 for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) print i #output = 0 #while output < 2: output = 1.24 #output = output + .01 print a.potentiostat(output) for i in range(0,300): #for i in range(0,100): time.sleep(.1) read = a.parsedread() appender(read) if str(a.ocv()) == "None": print "None" #connecto to ardustat and setup resistance table a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) time.sleep(.1) print a.ocv() for i in range(0,10): time.sleep(.1) read = a.parsedread() print "Appending initial values!" appender(read) if not RealTime.TickTock(False): return """ #output = 0 #while output < .001: #output = -curr # new line #print curr #print output numCycles = int (cycles) for i in range (0,numCycles): # new line #output = output + .00001 #output = -output # new line #print output if not RealTime.ocv_on(): if (i%2) == 0: a.galvanostat(curr1) else: a.galvanostat(curr2) #for i in range(0,3): if (i%2) == 0: voltage = vmin while voltage < vmax:#for i in range (0,100): # new line if RealTime.paused(): handle_paused() if RealTime.ocv_on(): handle_ocv(a,"galvo",curr1) time.sleep(.01) read = a.parsedread() appender(read) voltage = read['cell_ADC'] if not RealTime.TickTock(False): return else: voltage = vmax while voltage > vmin: if RealTime.paused(): handle_paused() if RealTime.ocv_on(): handle_ocv(a,"galvo",curr2) time.sleep(.01) read = a.parsedread() appender(read) voltage = read['cell_ADC'] if not RealTime.TickTock(False): return """ print a.ocv() for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) """ while True: if RealTime.ocv_on(): handle_ocv(a) elif not RealTime.TickTock(True): return """
def handle_paused(): while RealTime.paused(): if not RealTime.TickTock(False): return time.sleep(.1)
def runPot(vol=1.4, cur=.001, slope=.01): #connecto to ardustat and setup resistance table #for i in range (0,3): a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) time.sleep(1) #create arrays + a function for logging data """ subplot(3,1,1) potLine, = plot(times,potential,'.') title("Potential vs. Time") ylabel("Potential (V)") subplot(3,1,2) curLine, = plot(times,current,'.') title("Current vs. Time") ylabel("Current (A)") subplot(3,1,3) resLine, = plot(times,numpy.array(potential)/numpy.array(current)) title("Resistance vs. Time") ylabel("Resistance (Ohms)") xlabel("Time (s)") #ion() # interaction mode needs to be turned off x = arange(0,2*pi,0.01) # we'll create an x-axis from 0 to 2 pi line, = plot(x,x) # this is our initial plot, and does nothing line.axes.set_ylim(-3,3) # set the range for our plot starttime = time.time() # this is our start time t = 0 # this is our relative start time """ """ #Step through values output = 0 print a.ocv() print -1 for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) print i #output = 0 #while output < 2: output = 1.24 #output = output + .01 print a.potentiostat(output) for i in range(0,300): #for i in range(0,100): time.sleep(.1) read = a.parsedread() appender(read) if str(a.ocv()) == "None": #connecto to ardustat and setup resistance table a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) a.ocv() for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) read = a.parsedread() appender(read) voltage = volmeasured = read['cell_ADC'] while volmeasured < vol: voltage += slope a.potentiostat(voltage) read = a.parsedread() appender(read) volmeasured = read['cell_ADC'] if not RealTime.TickTock(False): return time.sleep(.01) """ if not RealTime.ocv_on(): potentiostat(a,vol) read = a.parsedread() appender(read) currmeasured = read['current'] #volmeasured = read['cell_ADC'] #vol = vol - volmeasured while True:#while currmeasured > cur: if RealTime.paused(): handle_paused() if RealTime.ocv_on(): handle_ocv(a,"pot",vol) read = a.parsedread() appender(read) currmeasured = read['current'] if not RealTime.TickTock(False): return time.sleep(.01) while True: if RealTime.ocv_on(): handle_ocv(a) elif not RealTime.TickTock(True): return
import threading import RealTime import poweroff import numpy as np #EMG ############################################################################################################ ## All you have to do is to call start_thread1 to start threading smoothly Real = RealTime.RealTime() # self.Real.set_GP_instance(self) Power = poweroff.poweroff() thread1 = None thread2 = None event_stop_thread1 = threading.Event() event_stop_thread2 = threading.Event() def start_thread1(): Real.Flag_Predict = True Real.b = np.empty( [0, 8] ) event_stop_thread1.clear() thread1 = threading.Thread( target=loop1 ) thread1.start() def loop1(): while not event_stop_thread1.is_set(): # if not self.stop_threads.is_set(): if Real.myo_device.services.waitForNotifications( 1 ): print(Real.predictions_array)
def __init__(self, parent=None): #pyqtgraph.setConfigOption('background', 'w') # before loading widget super(Main, self).__init__() self.setupUi(self) self.Real = RealTime.RealTime() self.Power=poweroff.poweroff() self.EMG_Modeling = EMG_Model.EMG_Model() self.cv = CV.CV() #self.Real.set_GP_instance(self) XStream.stdout().messageWritten.connect( self.textBrowser.insertPlainText ) XStream.stdout().messageWritten.connect( self.textBrowser.ensureCursorVisible ) XStream.stderr().messageWritten.connect( self.textBrowser.insertPlainText ) XStream.stderr().messageWritten.connect( self.textBrowser.ensureCursorVisible ) #self.emgplot = pg.PlotWidget( name='EMGplot' ) self.emgplot.setRange( QtCore.QRectF( -50, -200, 1000, 1400 ) ) self.emgplot.disableAutoRange() self.emgplot.setTitle( "EMG" ) self.emgcurve = [] for i in range( 8 ): c = self.emgplot.plot( pen=(i, 10) ) c.setPos( 0, i * 150 ) self.emgcurve.append( c ) self.emgcurve0 = [self.EMG1,self.EMG2,self.EMG3,self.EMG4,self.EMG5\ ,self.EMG6,self.EMG7,self.EMG8] for i in range (8): self.emgcurve0[i].plotItem.showGrid(True, True, 0.7) #self.emgcurve0[i].plotItem.setRange(yRange=[0, 1]) self.pushButton.clicked.connect(self.Real.start_MYO) self.pushButton_2.clicked.connect( self.start_thread2 ) # Start Predict self.pushButton_3.clicked.connect( self.stop_thread2 ) # Stop Predict self.pushButton_4.clicked.connect( self.disconnect_MYO) self.pushButton_5.clicked.connect(self.Power.power_off) self.pushButton_6.clicked.connect( self.clear_textBrowser ) self.pushButton_7.clicked.connect( self.start_thread1 )# start Graph1 self.pushButton_8.clicked.connect( self.stop_thread1 ) self.pushButton_9.clicked.connect( self.file_save_csv ) self.pushButton_11.clicked.connect( self.start_thread0 ) self.pushButton_12.clicked.connect( self.stop_thread0 ) self.pushButton_10.clicked.connect( self.saveEMGModel ) self.pushButton_10.setStyleSheet( "background-color: red" ) self.pushButton_13.clicked.connect( self.browseCSVEMGModel1 ) self.pushButton_14.clicked.connect( self.browseCSVEMGModel2 ) self.pushButton_15.clicked.connect( self.browseCSVEMGModel3 ) self.pushButton_16.clicked.connect( self.browseCSVEMGModel4 ) self.pushButton_21.clicked.connect( self.joinCSV1 ) self.pushButton_22.clicked.connect( self.joinCSV2 ) self.pushButton_23.clicked.connect( self.saveJoinCSV ) self.pushButton_17.clicked.connect( self.browsePickleEMGModel1 ) self.pushButton_18.clicked.connect( self.browsePickleEMGModel2 ) self.pushButton_19.clicked.connect( self.browseCVModel ) self.pushButton_20.clicked.connect( self.start_thread4 ) self.pushButton_20.setStyleSheet( "background-color: green" ) self.pushButton_24.clicked.connect( self.stop_thread4 ) self.pushButton_24.setStyleSheet( "background-color: red" ) self.pushButton_25.clicked.connect( QtCore.QCoreApplication.instance().quit ) self.path1 = self.path2 = self.path3 = self.path4 = self.path5 = self.path6 = self.path7 = self.path8 = None palette = QtGui.QPalette() palette.setColor(QtGui.QPalette.Foreground, QtCore.Qt.red) self.label.setPalette(palette) self.stop_request =True self.thread1 = None self.thread2 = None self.event_stop_thread0 = threading.Event() self.event_stop_thread1 = threading.Event() self.event_stop_thread2 = threading.Event() self.event_stop_thread3 = threading.Event() self.event_stop_thread4 = threading.Event()
def main(dashboardID): # Getting all dashboard data in dictionary format dashboardInfo = readDashboard.read(dashboardID) #calibration information from firebase files calibration = dashboardInfo["calibration"] pixelX = calibration["pixelX_vals"] pixelY = calibration["pixelY_vals"] #getting pixel coordinates from pixelX and pixelY pixel_array = [[pixelX[i], pixelY[i]] for i in range(len(pixelX))] lat = calibration["lat_vals"] lon = calibration["lon_vals"] #getting longitude and latitude coordinates from lat and lon lonlat_array = [[lat[i], lon[i]] for i in range(len(lat))] # Obtaining pixelMapper object from calibration information pm = PixelMapper.PixelMapper(pixel_array, lonlat_array, calibration["lonlat_origin"]) # Obtaining streamLink (statically or dynamically) from calibration # either "streamLink" or "streamWebpage" should be present in calibration streamLinkStatic = calibration["static"] streamLink = None #getting streamlink from calibration json file #sets the value of streamLinkStatic if ("streamLink" in calibration.keys()): streamLink = calibration["streamLink"] streamLinkStatic = True if (not streamLinkStatic): assert "streamWebpage" in calibration.keys() # For debug purposes static = True streamLink = "../sampleVideos/TimesSquare.mp4" # Opening the videoCApture object cap = cv2.VideoCapture() frame_index = 0 while True: print("FRAME", frame_index, "##############") # TODO: Refreshing every second may not be the best approach # if the streamLink is not static, then it's necessary to continuously refresh if (streamLinkStatic and frame_index == 0): cap.open(streamLink) if (not streamLinkStatic): streamLink = obtainStreamLink.get(calibration["streamWebpage"]) cap.open(streamLink) read, image = cap.read() if (not read): print("END") break # generating prediction from image output = pred.predict(image) #generates the realtime and aggregate analytics displayed on spaspect dashboard realData = RealTime.genRealData(pm, output, os.path.join(fbFilesDir, "realtime") + os.path.sep + dashboardID + ".json") aggData = Aggregate.genAggData(realData, os.path.join(fbFilesDir, "aggregate") + os.path.sep + dashboardID+ ".json") frame_index += 1 return 0
def runGalvo(curr1=0.002, curr2=-0.002, vmax=1.6, vmin=0.9, cycles=4): #connecto to ardustat and setup resistance table #for i in range (0,3): a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) read = a.parsedread() print "Resistance table loaded" time.sleep(1) #create arrays + a function for logging data """ subplot(3,1,1) potLine, = plot(times,potential,'.') title("Potential vs. Time") ylabel("Potential (V)") subplot(3,1,2) curLine, = plot(times,current,'.') title("Current vs. Time") ylabel("Current (A)") subplot(3,1,3) resLine, = plot(times,numpy.array(potential)/numpy.array(current)) title("Resistance vs. Time") ylabel("Resistance (Ohms)") xlabel("Time (s)") #ion() # interaction mode needs to be turned off x = arange(0,2*pi,0.01) # we'll create an x-axis from 0 to 2 pi line, = plot(x,x) # this is our initial plot, and does nothing line.axes.set_ylim(-3,3) # set the range for our plot starttime = time.time() # this is our start time t = 0 # this is our relative start time """ """ #Step through values output = 0 print a.ocv() print -1 for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) print i #output = 0 #while output < 2: output = 1.24 #output = output + .01 print a.potentiostat(output) for i in range(0,300): #for i in range(0,100): time.sleep(.1) read = a.parsedread() appender(read) if str(a.ocv()) == "None": print "None" #connecto to ardustat and setup resistance table a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) time.sleep(.1) print a.ocv() for i in range(0,10): time.sleep(.1) read = a.parsedread() print "Appending initial values!" appender(read) if not RealTime.TickTock(False): return """ #output = 0 #while output < .001: #output = -curr # new line #print curr #print output numCycles = int(cycles) for i in range(0, numCycles): # new line #output = output + .00001 #output = -output # new line #print output if not RealTime.ocv_on(): if (i % 2) == 0: a.galvanostat(curr1) else: a.galvanostat(curr2) #for i in range(0,3): if (i % 2) == 0: voltage = vmin while voltage < vmax: #for i in range (0,100): # new line if RealTime.paused(): handle_paused() if RealTime.ocv_on(): handle_ocv(a, "galvo", curr1) time.sleep(.01) read = a.parsedread() appender(read) voltage = read['cell_ADC'] if not RealTime.TickTock(False): return else: voltage = vmax while voltage > vmin: if RealTime.paused(): handle_paused() if RealTime.ocv_on(): handle_ocv(a, "galvo", curr2) time.sleep(.01) read = a.parsedread() appender(read) voltage = read['cell_ADC'] if not RealTime.TickTock(False): return """ print a.ocv() for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) """ while True: if RealTime.ocv_on(): handle_ocv(a) elif not RealTime.TickTock(True): return """
def runPot(vol=1.4, cur=.001, slope=.01): #connecto to ardustat and setup resistance table #for i in range (0,3): a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) time.sleep(1) #create arrays + a function for logging data """ subplot(3,1,1) potLine, = plot(times,potential,'.') title("Potential vs. Time") ylabel("Potential (V)") subplot(3,1,2) curLine, = plot(times,current,'.') title("Current vs. Time") ylabel("Current (A)") subplot(3,1,3) resLine, = plot(times,numpy.array(potential)/numpy.array(current)) title("Resistance vs. Time") ylabel("Resistance (Ohms)") xlabel("Time (s)") #ion() # interaction mode needs to be turned off x = arange(0,2*pi,0.01) # we'll create an x-axis from 0 to 2 pi line, = plot(x,x) # this is our initial plot, and does nothing line.axes.set_ylim(-3,3) # set the range for our plot starttime = time.time() # this is our start time t = 0 # this is our relative start time """ """ #Step through values output = 0 print a.ocv() print -1 for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) print i #output = 0 #while output < 2: output = 1.24 #output = output + .01 print a.potentiostat(output) for i in range(0,300): #for i in range(0,100): time.sleep(.1) read = a.parsedread() appender(read) if str(a.ocv()) == "None": #connecto to ardustat and setup resistance table a = ard.ardustat() a.connect(7777) a.debug = False #a.calibrate(15000,16) a.load_resistance_table(16) a.ocv() for i in range(0,10): time.sleep(.1) read = a.parsedread() appender(read) read = a.parsedread() appender(read) voltage = volmeasured = read['cell_ADC'] while volmeasured < vol: voltage += slope a.potentiostat(voltage) read = a.parsedread() appender(read) volmeasured = read['cell_ADC'] if not RealTime.TickTock(False): return time.sleep(.01) """ if not RealTime.ocv_on(): potentiostat(a, vol) read = a.parsedread() appender(read) currmeasured = read['current'] #volmeasured = read['cell_ADC'] #vol = vol - volmeasured while True: #while currmeasured > cur: if RealTime.paused(): handle_paused() if RealTime.ocv_on(): handle_ocv(a, "pot", vol) read = a.parsedread() appender(read) currmeasured = read['current'] if not RealTime.TickTock(False): return time.sleep(.01) while True: if RealTime.ocv_on(): handle_ocv(a) elif not RealTime.TickTock(True): return