def makeLysate(self): global intBITS, intFLAG if self.homeComplete: if self.vFinal == 0: print('Set Lysate Volume') if self.cFinal == 0: print('Set Cycle Number') else: GPIO.setmode(GPIO.BCM) GPIO.setup( 22, GPIO.IN, pull_up_down=GPIO.PUD_UP) #set up GPIO 22 as an input GPIO.add_event_detect( 22, GPIO.FALLING, callback=self.moveDone) # detect interrupts MOTOR.enablestepSTOPint(0, 'a') MOTOR.enablestepSTOPint(0, 'b') MOTOR.intEnable(0) self.disableAllbutHome() self.homeButton["state"] = "disabled" print 'Making', self.vFinal, 'mL of lysate in', self.cFinal, 'cycles' self.sync_config(self.direction, 120, 0) self.start = time.time() time.clock() self.remainSeconds = int(self.cFinal * ((3500 * self.vFinal) - 1400) / 60) root.after(1, self.oneCycle) else: print('Remove syringes and home motors')
def __init__(self,master,r,c): self.master=master self.initialization=False self.sm=Frame(self.master,padx=4,pady=4,bd=2,relief='sunken') self.sm.grid(row=r,column=c, sticky=N+S+W+E) ##Create Fonts self.title=tkFont.Font(family='Helvetica', size=25, weight='bold') self.heading=tkFont.Font(family='Helvetica', size=18, weight='bold') self.content=tkFont.Font(family='Helvetica', size=12, weight='bold') self.dir_dict = {0:'cw', 1:'ccw'} self.direction=1 self.cycleCount=1 self.bigStart=Button(self.sm,text="go",height=108,width=125,command=self.makeLysate) self.bigStart.grid(row=2,column=0,rowspan=2,padx=30,pady=4) self.intBITS=MOTOR.getINTflag0(0) self.intFLAG=1 GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(22, GPIO.FALLING, callback=self.moveDone) #allow interrupts when a motor stops MOTOR.enablestepSTOPint(0,'a') MOTOR.enablestepSTOPint(0,'b') MOTOR.intEnable(0)
def move_smart_step(self, speed, command, motors_position): current_position = self.hypoteni_to_euclid(motors_position) x_diff = command[0] y_diff = command[1] end_position = [ current_position[0] + x_diff, current_position[1] + y_diff ] motors_position_end = self.euclid_to_hypoteni(end_position) steps = [ motors_position_end[0] - motors_position[0], motors_position_end[1] - motors_position[1] ] distance = (x_diff**2 + y_diff**2)**0.5 total_time = distance / (speed * self.config.meters_per_step) current_position_mirror = [ self.config.x_total - current_position[0], current_position[1] ] end_position_mirror = [ self.config.x_total - end_position[0], end_position[1] ] motor1_velocity = self.motor_velocity_at_time(current_position, end_position, total_time / 2, total_time) motor2_velocity = self.motor_velocity_at_time(current_position_mirror, end_position_mirror, total_time / 2, total_time) #print('in smart step with command', command, 'steps', steps,'and velocities', motor1_velocity, motor2_velocity) MOTOR.enablestepSTOPint(0, 'A') #set up to interrupt when motor a stops MOTOR.enablestepSTOPint(0, 'B') if (steps[0] == 0 and steps[1] == 0): return motors_position motor1_direction = 'ccw' motor2_direction = 'cw' if (motor1_velocity < 0): motor1_direction = 'cw' if (motor2_velocity < 0): motor2_direction = 'ccw' MOTOR.stepperCONFIG(0, 'A', motor1_direction, 'H', abs(motor1_velocity), 0) MOTOR.stepperCONFIG(0, 'B', motor2_direction, 'H', abs(motor2_velocity), 0) if (steps[0] != 0): MOTOR.stepperMOVE(0, 'A', abs(steps[0])) if (steps[1] != 0): MOTOR.stepperMOVE(0, 'B', abs(steps[1])) flag_a = 1 #Initialize flag to true flag_b = 1 if (steps[0] == 0): flag_a = 0 if (steps[1] == 0): flag_b = 0 while (flag_a or flag_b): #start loop #time.sleep(0.05) #check every 100msec stat = MOTOR.getINTflag0(0) #read interrupt flags if (stat & (2**4)): flag_b = 0 if (stat & (2**5)): flag_a = 0 return [motors_position[0] + steps[0], motors_position[1] + steps[1]]
def makeLysate(self): global intBITS, intFLAG GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) #set up GPIO 22 as an input GPIO.add_event_detect(22, GPIO.FALLING, callback=self.moveDone) # detect interrupts MOTOR.enablestepSTOPint(0, 'a') MOTOR.enablestepSTOPint(0, 'b') MOTOR.intEnable(0) print "Lysing" print self.cycleCount self.sync_config(self.direction, 120, 0) root.after(1, self.movement)
def configmotors(self, speed, first=False): if (first): GPIO.setmode(GPIO.BCM) MOTOR.intEnable(0) #enable interrupts on Pi-Plate MOTOR.enablestepSTOPint( 0, 'A') #set up to interrupt when motor a stops MOTOR.enablestepSTOPint( 0, 'B') #set up to interrupt when motor a stops MOTOR.stepperCONFIG(0, 'A', 'cw', 'H', speed, 0) MOTOR.stepperCONFIG(0, 'B', 'cw', 'H', speed, 0) pwm = [None, None, time.perf_counter()] GPIO.setup(4, GPIO.OUT) GPIO.setup(5, GPIO.OUT) pwm[0] = GPIO.PWM(4, 50) pwm[0].start(0) pwm[1] = GPIO.PWM(5, 50) pwm[1].start(0) return pwm
def makeLysate(self): global intBITS, intFLAG if self.homeComplete: if self.vFinal == 0: print('Set Lysate Volume') if self.cFinal == 0: print('Set Cycle Number') else: GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) #set up GPIO 22 as an input GPIO.add_event_detect(22, GPIO.FALLING, callback=self.moveDone) # detect interrupts MOTOR.enablestepSTOPint(0,'a') MOTOR.enablestepSTOPint(0,'b') MOTOR.intEnable(0) print 'Making', self.vFinal, 'mL of lysate in', self.cFinal, 'cycles' self.sync_config(self.direction,120,0) root.after(1,self.oneCycle) else: print('Remove syringes and home motors')
class PopupWindowVolume(object): def __init__(self,master): top=self.top=Toplevel(master) self.l=Label(top,text='Remove syringe for motors to move to set volume',font=tkFont.Font(family='Helvetica', size=24),padx=4,pady=4) self.l.pack() self.b=Button(top,text='Move Motors!',height=4,width=12,padx=4,pady=4,font=tkFont.Font(family='Helvetica', size=12),command=self.cleanup) self.b.pack() def cleanup(self): self.top.destroy() #Reset motors MOTOR.RESET(0) MOTOR.enablestepSTOPint(0,'a') MOTOR.enablestepSTOPint(0,'b') MOTOR.intEnable(0) #Initialize Tkinter GUI root = Tk() root.config(bg="black") root.attributes("-fullscreen", TRUE) swidth=root.winfo_screenwidth() sheight=root.winfo_screenheight() #print tkFont.families() container=Frame(root,bg="white") container.place(relx=0.5, rely=0.5, anchor=CENTER) title = headerBLOCK(container,0,0) control = controlGUI(container,1,0)
def wait(flag): MOTOR.enablestepSTOPint(config.ADDR, config.MOTOR) while flag: stat = MOTOR.getINTflag0(config.ADDR) if stat & 0x20: flag = 0
def __init__(self, master, r, c): self.master = master self.initialization = False self.sm = Frame(self.master, padx=4, pady=4, bd=2, relief='sunken') self.sm.grid(row=r, column=c, sticky=N + S + W + E) ##Create Fonts self.title = tkFont.Font(family='Helvetica', size=25, weight='bold') self.heading = tkFont.Font(family='Helvetica', size=18, weight='bold') self.content = tkFont.Font(family='Helvetica', size=12, weight='bold') ##Home Button self.homeButton = Button(self.sm, text="HOME", fg="black", bg="blue", height=6, width=16, command=self.jogHome) self.homeButton.grid(row=0, column=0, rowspan=2, padx=30, pady=4) self.homeComplete = 0 ##Start/Stop Controls self.StartPushSmall = Image.open("StartPushSmall.png").convert("RGB") self.StartPushSmall = self.StartPushSmall.resize((125, 108), Image.ANTIALIAS) self.StartPushSmallDisplay = ImageTk.PhotoImage(self.StartPushSmall) self.bigStart = Button(self.sm, image=self.StartPushSmallDisplay, height=108, width=125, command=self.makeLysate) self.bigStart.image = self.StartPushSmallDisplay self.bigStart.grid(row=2, column=0, rowspan=2, padx=30, pady=4) #self.bigStart.pack self.StopPushSmall = Image.open("StopPushSmall.png").convert("RGB") self.StopPushSmall = self.StopPushSmall.resize((125, 108), Image.ANTIALIAS) self.StopPushSmallDisplay = ImageTk.PhotoImage(self.StopPushSmall) self.bigStop = Button(self.sm, image=self.StopPushSmallDisplay, height=108, width=125, command=self.stopAll) self.bigStop.grid(row=4, column=0, rowspan=2, padx=30, pady=4) ##Volume Control self.labelv = Label(self.sm, text="Volume Control", padx=4, pady=4, font=self.heading, anchor="center") self.labelv.grid(row=0, column=1, columnspan=4, sticky=S) self.vStart = 1.5 self.vLower = Button(self.sm, text="<", fg="black", bg="gray", height=2, width=7, command=self.vdecrease) self.vLower.grid(row=1, column=1) self.labelvStart = Label(self.sm, text=self.vStart, padx=4, pady=4, font=self.content, anchor="center") self.labelvStart.grid(row=1, column=2, columnspan=2, sticky=N + E + S + W) self.vUpper = Button(self.sm, text=">", fg="black", bg="gray", height=2, width=7, command=self.vincrease) self.vUpper.grid(row=1, column=4) self.vSet = Button(self.sm, text="Set Total Volume", height=2, width=14, command=self.vset) self.vSet.grid(row=2, column=1, columnspan=2, sticky=W) self.vReset = Button(self.sm, text="Reset to Default", height=2, width=14, command=self.vdefault) self.vReset.grid(row=2, column=3, columnspan=2, sticky=E) ##Cycle Control self.labelc = Label(self.sm, text="Cycles Control", padx=4, pady=2, font=self.heading, anchor="center") self.labelc.grid(row=3, column=1, columnspan=4, sticky=S) self.cStart = 20 self.cLower = Button(self.sm, text="<", fg="black", bg="gray", height=2, width=7, command=self.cdecrease) self.cLower.grid(row=4, column=1) self.labelcStart = Label(self.sm, text=self.cStart, padx=4, pady=4, width=14, font=self.content, anchor="center") self.labelcStart.grid(row=4, column=2, columnspan=2, sticky=N + E + W + S) self.cUpper = Button(self.sm, text=">", fg="black", bg="gray", height=2, width=7, command=self.cincrease) self.cUpper.grid(row=4, column=4, sticky=E) self.cSet = Button(self.sm, text="Set Cycle Number", height=2, width=14, command=self.cset) self.cSet.grid(row=5, column=1, columnspan=2, sticky=W) self.cReset = Button(self.sm, text="Reset to Default", height=2, width=14, command=self.cdefault) self.cReset.grid(row=5, column=3, columnspan=2, sticky=E) #Output Information self.statusLabel = Label(self.sm, text="Status Overview", padx=4, pady=4, font=self.heading, anchor="center") self.statusLabel.grid(row=0, column=5, columnspan=2, sticky=E + S + W) self.cycleCount = 0 self.cCounterLabel = Label(self.sm, text="Current Cycle", padx=4, pady=4, width=31, font=self.content, anchor="center") self.cCounterLabel.grid(row=0, column=5, columnspan=2, sticky=E + S + W) self.cycleCountLabel = Label(self.sm, text=self.cycleCount, padx=4, pady=4, width=31, font=self.content, anchor="center") self.cycleCountLabel.grid(row=1, column=5, columnspan=2, sticky=N + E + W) self.now = "00:00:00" self.timeElapsedLabel = Label(self.sm, text="Time Elapsed", padx=4, pady=4, font=self.content, anchor="center") self.timeElapsedLabel.grid(row=2, column=5, sticky=S + E + W) self.timeUp = Label(self.sm, text=self.now, padx=4, pady=4, font=self.content, anchor="center") self.timeUp.grid(row=3, column=5, sticky=N + E + W) self.remain = "00:00:00" self.timeRemainLabel = Label(self.sm, text="Time Remaining", padx=4, pady=4, font=self.content, anchor="center") self.timeRemainLabel.grid(row=2, column=6, sticky=S + E + W) self.timeDown = Label(self.sm, text=self.remain, padx=4, pady=4, font=self.content, anchor="center") self.timeDown.grid(row=3, column=6, sticky=N + E + W) #Output text widget self.text_box = Text(self.sm, padx=4, pady=4, height=6, width=34, state=DISABLED) self.text_box.grid(row=4, column=5, columnspan=2, rowspan=2) self.scrollb = Scrollbar(self.sm, command=self.text_box.yview) self.scrollb.grid(row=4, column=6, rowspan=2, sticky=N + S + E) self.text_box['yscrollcommand'] = self.scrollb.set sys.stdout = StdRedirector(self.text_box) sys.stderr = StdRedirector(self.text_box) #Parameters stat = MOTOR.getSENSORS(0) self.homeComplete = 0 self.lysing = 0 self.vFinal = 0 self.vCurrent = 0 self.cFinal = 0 self.direction = 0 self.dir_dict = {0: 'cw', 1: 'ccw'} GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) #set up GPIO 22 as an input MOTOR.enablestepSTOPint(0, 'a') MOTOR.enablestepSTOPint(0, 'b') MOTOR.intEnable(0)