def pumping_operation(day,hour,minute,frequency_sampling,num_samples,operate_arduino_object,starting_well=0): samplingObject=CFlow.sampleHandling() click_object=CFlow.click(sample_counter=starting_well) click_object.set_measuring_times(day,hour,minute,frequency_sampling,num_samples) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object=CFlow.read_fcs('C:\\Users\\localadmin\\Desktop\\Results','ecoli') while click_object.set_waiting_time()==0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f',click_object.waiting_time) samplingObject.bring_sample(operate_arduino_object,sample=click_object.measuring_times[click_object.time_counter][1]) click_object.sample() click_object.run(click_object.measuring_times[click_object.time_counter][1]) click_object.export() time.sleep(1) click_object.moveFiles('C:\\Users\\localadmin\\Desktop','C:\\Users\\localadmin\\Desktop\\Results')###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM FEEDBACK ## click_object.backflush() operate_arduino_object.push_to_cytometer(2) operate_arduino_object.cytometer_to_waste(2) operate_arduino_object.push_to_cytometer(2) operate_arduino_object.cytometer_to_waste(2) operate_arduino_object.push_to_cytometer(2) operate_arduino_object.cytometer_to_waste(2) return
def pumping_operation(day, hour, minute, frequency, num_samples, operate_arduino_object, starting_well=0): click_object = CFlow.click(sample_counter=starting_well) click_object.set_measuring_times( day, hour, minute, frequency, num_samples ) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object = CFlow.read_fcs('C:\\Users\\rumarc\\Desktop\\Results', 'ecoli') operate_arduino_object.operate_led(1, 256) #### operate_arduino_object.operate_led(2, 0 * 256) #### ##Feedback constants I = 0 P = 0 kp = 0.8 ki = 0.08 ref = 0.66 #Reference value for controller ## while click_object.set_waiting_time() == 0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f', click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles( 'C:\\Users\\rumarc\\Desktop', 'C:\\Users\\rumarc\\Desktop\\Results' ) ###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM FEEDBACK GFP_mean = read_fcs_object.get_last_data(click_object) logging.info('GFP mean is: %f', GFP_mean) print(GFP_mean) I = ki * (ref - GFP_mean) + I print(I) logging.info('Integral parameter value is: %f', I) P = kp * (ref - GFP_mean) print(P) logging.info('Proportional parameter value is: %f', P) LED_signal = P + I if LED_signal < 0: LED_signal = 0 elif LED_signal > 1: LED_signal = 1 logging.info('LED signal is: %f', LED_signal) print(LED_signal) LED_signal = LED_signal * 256 operate_arduino_object.operate_led(2, LED_signal) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) return
def pumping_operation(day,hour,minute,frequency,num_samples,operate_arduino_object,starting_well=0): click_object=CFlow.click(sample_counter=starting_well) click_object.set_measuring_times(day,hour,minute,frequency,num_samples) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object=CFlow.read_fcs('C:\\Users\\rumarc\\Desktop\\Results','ecoli') operate_arduino_object.operate_led(1,256)#### operate_arduino_object.operate_led(2,0*256)#### ##Feedback constants I=0 P=0 kp=6.8 ki=0.5 ref=0.07 #Reference value for controller ## while click_object.set_waiting_time()==0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f',click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles('C:\\Users\\rumarc\\Desktop','C:\\Users\\rumarc\\Desktop\\Results')###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM FEEDBACK GFP_variance=read_fcs_object.get_last_data(click_object,'variance') logging.info('GFP variance is: %f',GFP_variance) if GFP_variance>ref: kp=13.6 ki=1.5 if GFP_variance<ref*0.9: kp=6.8 ki=0.5 print(GFP_variance) I=ki*(ref-GFP_variance)+I if I<0: I=0 print(I) logging.info('Integral parameter value is: %f',I) P=kp*(ref-GFP_variance) print(P) logging.info('Proportional parameter value is: %f',P) LED_signal=P+I if LED_signal<0: LED_signal=0 elif LED_signal>1: LED_signal=1 logging.info('LED signal is: %f',LED_signal) print(LED_signal) LED_signal=LED_signal*256 operate_arduino_object.operate_led(2,LED_signal) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) return
def pumping_operation(day, hour, minute, frequency, num_samples, operate_arduino_object, starting_well=0): click_object = CFlow.click(sample_counter=starting_well) click_object.set_measuring_times( day, hour, minute, frequency, num_samples ) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object = CFlow.read_fcs('C:\\Users\\rumarc\\Desktop\\Results', 'ecoli') operate_arduino_object.operate_led(1, 256) #### operate_arduino_object.operate_led(2, 0 * 256) #### ##controller setup controller = CFlow.MPC() reference = np.zeros(shape=(1, (num_samples + 2))) + 0.66 LED_signal = 0 ####Need to add something to subtract initial offset from data!!! ## cycle = 0 offset = 0 #This is the offset that will be applied to both the GFP mean and the reference value. This is because the model fitting was done subtracting the initial timepoint from all the data. while click_object.set_waiting_time() == 0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f', click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles( 'C:\\Users\\rumarc\\Desktop', 'C:\\Users\\rumarc\\Desktop\\Results' ) ###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM CONTTROL GFP_mean = read_fcs_object.get_last_data(click_object) logging.info('GFP mean is: %f', GFP_mean) print(GFP_mean) if cycle == 0: offset = GFP_mean controller.kalmanFilter(LED_signal, GFP_mean - offset) LED_signal = controller.multiPrediction(reference[0][cycle:cycle + 5] - offset) ####!!!! logging.info('LED signal is: %f', LED_signal) logging.info('reference is: %f', reference[0][cycle]) print(LED_signal) operate_arduino_object.operate_led(2, LED_signal * 256) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) cycle += 1 return
def pumping_operation(day, hour, minute, frequency, num_samples, operate_arduino_object, starting_well=0): click_object = CFlow.click(sample_counter=starting_well) click_object.set_measuring_times( day, hour, minute, frequency, num_samples ) # Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object = CFlow.read_fcs("C:\\Users\\rumarc\\Desktop\\Results", "ecoli") operate_arduino_object.operate_led(1, 256) #### operate_arduino_object.operate_led(2, 0 * 256) #### ##controller setup controller = CFlow.newMPC(10) LED_signal = 0 LED_signalTransformed = 0 ####Need to add something to subtract initial offset from data!!! ## cycle = 0 while click_object.set_waiting_time() == 0: time.sleep(click_object.waiting_time) logging.info("waiting time until next measurement is: %f", click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles( "C:\\Users\\rumarc\\Desktop", "C:\\Users\\rumarc\\Desktop\\Results" ) ###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM CONTTROL GFP_mean = read_fcs_object.get_last_data(click_object) logging.info("GFP mean is: %f", GFP_mean) print(GFP_mean) if cycle == 0: controller.initialGFPreading = GFP_mean reference = np.zeros(shape=(1, (num_samples + 6))) + 4 controller.kalmanFilter(LED_signalTransformed, GFP_mean / controller.initialGFPreading) LED_signalTransformed = controller.multiPrediction(reference[0][cycle : cycle + 5]) LED_signal = controller.ledOutputTransformation(LED_signalTransformed) if LED_signal > 1: LED_signal = 1 elif LED_signal < 0: LED_signal = 0 logging.info("LED signal is: %f", LED_signal) logging.info("reference is: %f", reference[0][cycle]) print(LED_signal) operate_arduino_object.operate_led(2, LED_signal * 256) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) cycle += 1 return
def led_operation(day,hour,minute,frequency,operate_arduino_object):#frequency is in seconds led=CFlow.led(operate_arduino_object) led.read_intensity_file(folder_path='C:\\Users\\rumarc\\Desktop\\Results',file_name='intensities.csv') ##ADD FOLDER led.scale_intensities() led.set_change_times(day,hour,minute,frequency) led.led_guide() return
def pumping_operation(day,hour,minute,frequency,num_samples,operate_arduino_object,starting_well=0): click_object=CFlow.click(sample_counter=starting_well) click_object.set_measuring_times(day,hour,minute,frequency,num_samples) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object=CFlow.read_fcs('C:\\Users\\rumarc\\Desktop\\Results','ecoli') operate_arduino_object.operate_led(1,256)#### operate_arduino_object.operate_led(2,0*256)#### ##controller setup controller=CFlow.newMPC(10) LED_signal=0 LED_signalTransformed=0 ####Need to add something to subtract initial offset from data!!! ## cycle=0 while click_object.set_waiting_time()==0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f',click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles('C:\\Users\\rumarc\\Desktop','C:\\Users\\rumarc\\Desktop\\Results')###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM CONTTROL GFP_mean=read_fcs_object.get_last_data(click_object) logging.info('GFP mean is: %f',GFP_mean) print(GFP_mean) if cycle==0: controller.initialGFPreading=GFP_mean reference=np.zeros(shape=(1,(num_samples+6)))+4 controller.kalmanFilter(LED_signalTransformed,GFP_mean/controller.initialGFPreading) LED_signalTransformed=controller.multiPrediction(reference[0][cycle:cycle+5]) LED_signal=controller.ledOutputTransformation(LED_signalTransformed) if LED_signal>1: LED_signal=1 elif LED_signal<0: LED_signal=0 logging.info('LED signal is: %f',LED_signal) logging.info('reference is: %f',reference[0][cycle]) print(LED_signal) operate_arduino_object.operate_led(2,LED_signal*256) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) cycle+=1 return
def pumping_operation(day,hour,minute,frequency,num_samples,operate_arduino_object,starting_well=0): click_object=CFlow.click(sample_counter=starting_well) click_object.set_measuring_times(day,hour,minute,frequency,num_samples) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object=CFlow.read_fcs('C:\\Users\\rumarc\\Desktop\\Results','ecoli') operate_arduino_object.operate_led(1,0*256)#### operate_arduino_object.operate_led(2,1*256)#### ##Feedback constants I=0 P=0 kp=0.8 ki=0.06 ref=0.66 ## while click_object.set_waiting_time()==0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f',click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles('C:\\Users\\rumarc\\Desktop','C:\\Users\\rumarc\\Desktop\\Results')###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM FEEDBACK GFP_mean=read_fcs_object.get_last_data(click_object) logging.info('GFP mean is: %f',GFP_mean) # print(GFP_mean) # I=ki*(ref-GFP_mean)+I # print(I) # logging.info('Integral parameter value is: %f',I) # P=kp*(ref-GFP_mean) # print(P) # logging.info('Proportional parameter value is: %f',P) # LED_signal=P+I # if LED_signal<0: # LED_signal=0 # elif LED_signal>1: # LED_signal=1 # logging.info('LED signal is: %f',LED_signal) # print(LED_signal) # LED_signal=LED_signal*256 # operate_arduino_object.operate_led(2,LED_signal) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(7) return
def pumping_operation(day, hour, minute, frequency_sampling, num_samples, operate_arduino_object, starting_well=0): samplingObject = CFlow.sampleHandling() click_object = CFlow.click(sample_counter=starting_well) click_object.set_measuring_times( day, hour, minute, frequency_sampling, num_samples ) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object = CFlow.read_fcs('C:\\Users\\localadmin\\Desktop\\Results', 'ecoli') while click_object.set_waiting_time() == 0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f', click_object.waiting_time) samplingObject.bring_sample( operate_arduino_object, sample=click_object.measuring_times[click_object.time_counter][1]) click_object.sample() click_object.run( click_object.measuring_times[click_object.time_counter][1]) click_object.export() time.sleep(1) click_object.moveFiles( 'C:\\Users\\localadmin\\Desktop', 'C:\\Users\\localadmin\\Desktop\\Results' ) ###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM FEEDBACK ## click_object.backflush() operate_arduino_object.push_to_cytometer(2) operate_arduino_object.cytometer_to_waste(2) operate_arduino_object.push_to_cytometer(2) operate_arduino_object.cytometer_to_waste(2) operate_arduino_object.push_to_cytometer(2) operate_arduino_object.cytometer_to_waste(2) return
def pumping_operation(day,hour,minute,frequency,num_samples,operate_arduino_object,starting_well=0): click_object=CFlow.click(sample_counter=starting_well) click_object.set_measuring_times(day,hour,minute,frequency,num_samples) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object=CFlow.read_fcs('C:\\Users\\rumarc\\Desktop\\Results','ecoli') operate_arduino_object.operate_led(1,256)#### operate_arduino_object.operate_led(2,0*256)#### ##controller setup controller=CFlow.MPC() reference=np.zeros(shape=(1,(num_samples+2)))+0.66 LED_signal=0 ####Need to add something to subtract initial offset from data!!! ## cycle=0 offset=0 #This is the offset that will be applied to both the GFP mean and the reference value. This is because the model fitting was done subtracting the initial timepoint from all the data. while click_object.set_waiting_time()==0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f',click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles('C:\\Users\\rumarc\\Desktop','C:\\Users\\rumarc\\Desktop\\Results')###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM CONTTROL GFP_mean=read_fcs_object.get_last_data(click_object) logging.info('GFP mean is: %f',GFP_mean) print(GFP_mean) if cycle==0: offset=GFP_mean controller.kalmanFilter(LED_signal,GFP_mean-offset) LED_signal=controller.multiPrediction(reference[0][cycle:cycle+5]-offset)####!!!! logging.info('LED signal is: %f',LED_signal) logging.info('reference is: %f',reference[0][cycle]) print(LED_signal) operate_arduino_object.operate_led(2,LED_signal*256) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) cycle+=1 return
import CFlow, time, threading, logging logging.basicConfig( filename='C:\\Users\\rumarc\\Desktop\\Results\\CFlow_execution.log', level=logging.INFO, filemode='w', format='%(asctime)s %(message)s', datefmt='%Y-%m-%d %H:%M') operate_arduino_object = CFlow.operate_arduino() day = 28 #starting day hour = 17 #starting hour minute = 37 #starting minute frequency_sampling = 10 #frequency of cytometer measurements, in minutes samples = 21 #number of cytometer measurements in total frequency_light = 3600 #frequency of led changes, in seconds start_sample_well = 0 #CFLOW STARTUP #PUMP CALIBRATION #PUMP STARTUP def bring_sample(operate_arduino_object): operate_arduino_object.sample_to_cytometer( 1.25) ##How much sample to take. 1.2 operate_arduino_object.air_to_cytometer(1) #2 operate_arduino_object.cytometer_to_waste(3) #3 operate_arduino_object.push_to_cytometer(2.5) #2 operate_arduino_object.cytometer_to_waste(3) #3 operate_arduino_object.push_to_cytometer(2.5) #2 operate_arduino_object.cytometer_to_waste(3) #3
import CFlow, time, threading, logging '''for multisampling''' logging.basicConfig( filename='C:\\Users\\localadmin\\Desktop\\Results\\CFlow_execution.log', level=logging.INFO, filemode='w', format='%(asctime)s %(message)s', datefmt='%Y-%m-%d %H:%M') operate_arduino_object = CFlow.multiOperate_arduino() day = 7 #starting day hour = 14 #starting hour minute = 49 #starting minute frequency_sampling = [6, 0, 6, 6] #frequency of cytometer measurements, in minutes num_samples = [2, 0, 2, 2] #number of cytometer measurements in total starting_well = 72 def pumping_operation(day, hour, minute, frequency_sampling, num_samples, operate_arduino_object, starting_well=0): samplingObject = CFlow.sampleHandling() click_object = CFlow.click(sample_counter=starting_well) click_object.set_measuring_times( day, hour, minute, frequency_sampling, num_samples
import CFlow,time,threading,logging '''for multisampling''' logging.basicConfig(filename='C:\\Users\\localadmin\\Desktop\\Results\\CFlow_execution.log', level=logging.INFO,filemode='w',format='%(asctime)s %(message)s',datefmt='%Y-%m-%d %H:%M') operate_arduino_object=CFlow.multiOperate_arduino() day=7#starting day hour=14#starting hour minute=49#starting minute frequency_sampling=[6,0,6,6]#frequency of cytometer measurements, in minutes num_samples=[2,0,2,2]#number of cytometer measurements in total starting_well=72 def pumping_operation(day,hour,minute,frequency_sampling,num_samples,operate_arduino_object,starting_well=0): samplingObject=CFlow.sampleHandling() click_object=CFlow.click(sample_counter=starting_well) click_object.set_measuring_times(day,hour,minute,frequency_sampling,num_samples) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object=CFlow.read_fcs('C:\\Users\\localadmin\\Desktop\\Results','ecoli') while click_object.set_waiting_time()==0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f',click_object.waiting_time) samplingObject.bring_sample(operate_arduino_object,sample=click_object.measuring_times[click_object.time_counter][1]) click_object.sample() click_object.run(click_object.measuring_times[click_object.time_counter][1]) click_object.export() time.sleep(1) click_object.moveFiles('C:\\Users\\localadmin\\Desktop','C:\\Users\\localadmin\\Desktop\\Results')###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM FEEDBACK
import CFlow,time,threading,logging logging.basicConfig(filename='C:\\Users\\rumarc\\Desktop\\Results\\CFlow_execution.log', level=logging.INFO,filemode='w',format='%(asctime)s %(message)s',datefmt='%Y-%m-%d %H:%M') operate_arduino_object=CFlow.operate_arduino() day=24#starting day hour=18#starting hour minute=10#starting minute frequency_sampling=10#frequency of cytometer measurements, in minutes samples=57#number of cytometer measurements in total frequency_light=3600#frequency of led changes, in seconds start_sample_well=0 #CFLOW STARTUP #PUMP CALIBRATION #PUMP STARTUP def bring_sample(operate_arduino_object): operate_arduino_object.sample_to_cytometer(1.25)##How much sample to take. 1.2 operate_arduino_object.air_to_cytometer(1)#2 operate_arduino_object.cytometer_to_waste(3)#3 operate_arduino_object.push_to_cytometer(2.5)#2 operate_arduino_object.cytometer_to_waste(3)#3 operate_arduino_object.push_to_cytometer(2.5)#2 operate_arduino_object.cytometer_to_waste(3)#3 operate_arduino_object.push_to_cytometer(2)#2 operate_arduino_object.cytometer_to_waste(3)#3 operate_arduino_object.push_to_cytometer(0.4)##Critical time step. 2 operate_arduino_object.push_to_cytometer(0)##0.3 operate_arduino_object.cytometer_to_waste(7)#7 operate_arduino_object.push_to_cytometer(1)##How much sample to introduce into cytometer. 1 operate_arduino_object.air_to_cytometer(1.5)#2.5
def pumping_operation(day,hour,minute,frequency,num_samples,operate_arduino_object,starting_well=0): click_object=CFlow.click(sample_counter=starting_well) click_object.set_measuring_times(day,hour,minute,frequency,num_samples) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object=CFlow.read_fcs('C:\\Users\\localadmin\\Desktop\\Results','ecoli') ##Initial light conditions LED_signal=0#initial green light LED_signalTransformed=0 operate_arduino_object.operate_led(1,256) operate_arduino_object.operate_led(2,LED_signal*256) ##Start up Matlab matlab = matlab_wrapper.MatlabSession() matlab.eval("parpool") matlab.eval("cd('C:\\Users\\localadmin\\Desktop\\Particle Filter')") ##Controller setup P=5000#number of particles MPChorizon=3#number of steps that the MPC looks ahead for the optimization reference=[4,]*(num_samples+MPChorizon) GFP_measurements=[1] LEDapplied=[0]#Needs to be from 0 to 4.5!! ##Dose-response Sigmoidal a=5.828 b=3.353 c=-0.05946 d=-1.3388 ## cycle=0 while click_object.set_waiting_time()==0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f',click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles('C:\\Users\\localadmin\\Desktop','C:\\Users\\localadmin\\Desktop\\Results')###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM CONTTROL GFP_mean=read_fcs_object.get_last_data(click_object) logging.info('GFP mean is: %f',GFP_mean) print(GFP_mean) if cycle==0: initialGFPreading=GFP_mean GFP_measurements.append(GFP_mean/initialGFPreading) matlabCommand="LED=MPC_loop(%i,%i,%i,%s,%s,%s)"%(P,frequency,MPChorizon,str(GFP_measurements),str(reference),str(LEDapplied))#!!!Don't apply on the first cycle. matlab.eval(matlabCommand) LED_signalTransformed=matlab.get('LED') LEDapplied.append(LED_signalTransformed) LED_signal=np.log(a/(b*(LED_signalTransformed-d))-1/b)/(c*100) if LED_signal>1: LED_signal=1 elif LED_signal<0: LED_signal=0 logging.info('LED signal is: %f',LED_signal) logging.info('reference is: %f',reference[cycle]) print(LED_signal) operate_arduino_object.operate_led(2,LED_signal*256) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) cycle+=1 return
def pumping_operation(day, hour, minute, frequency, num_samples, operate_arduino_object, starting_well=0): click_object = CFlow.click(sample_counter=starting_well) click_object.set_measuring_times( day, hour, minute, frequency, num_samples ) #Set input correctly. day,hour,minute,frequency,num_samples read_fcs_object = CFlow.read_fcs('C:\\Users\\localadmin\\Desktop\\Results', 'ecoli') ##Initial light conditions LED_signal = 0 #initial green light LED_signalTransformed = 0 operate_arduino_object.operate_led(1, 256) operate_arduino_object.operate_led(2, LED_signal * 256) ##Start up Matlab matlab = matlab_wrapper.MatlabSession() matlab.eval("parpool") matlab.eval("cd('C:\\Users\\localadmin\\Desktop\\Particle Filter')") ##Controller setup P = 5000 #number of particles MPChorizon = 3 #number of steps that the MPC looks ahead for the optimization reference = [ 4, ] * (num_samples + MPChorizon) GFP_measurements = [1] LEDapplied = [0] #Needs to be from 0 to 4.5!! ##Dose-response Sigmoidal a = 5.828 b = 3.353 c = -0.05946 d = -1.3388 ## cycle = 0 while click_object.set_waiting_time() == 0: time.sleep(click_object.waiting_time) logging.info('waiting time until next measurement is: %f', click_object.waiting_time) bring_sample(operate_arduino_object) click_object.sample() click_object.run() click_object.export() time.sleep(1) click_object.moveFiles( 'C:\\Users\\localadmin\\Desktop', 'C:\\Users\\localadmin\\Desktop\\Results' ) ###THIS CHANGES FROM COMPUTER TO COMPUTER. THE OUTPUT FOLDER MUST BE CREATED BEFOREHAND time.sleep(1) ##PERFORM CONTTROL GFP_mean = read_fcs_object.get_last_data(click_object) logging.info('GFP mean is: %f', GFP_mean) print(GFP_mean) if cycle == 0: initialGFPreading = GFP_mean GFP_measurements.append(GFP_mean / initialGFPreading) matlabCommand = "LED=MPC_loop(%i,%i,%i,%s,%s,%s)" % ( P, frequency, MPChorizon, str(GFP_measurements), str(reference), str(LEDapplied)) #!!!Don't apply on the first cycle. matlab.eval(matlabCommand) LED_signalTransformed = matlab.get('LED') LEDapplied.append(LED_signalTransformed) LED_signal = np.log(a / (b * (LED_signalTransformed - d)) - 1 / b) / (c * 100) if LED_signal > 1: LED_signal = 1 elif LED_signal < 0: LED_signal = 0 logging.info('LED signal is: %f', LED_signal) logging.info('reference is: %f', reference[cycle]) print(LED_signal) operate_arduino_object.operate_led(2, LED_signal * 256) ## click_object.backflush() operate_arduino_object.cytometer_to_waste(8) cycle += 1 return