def move_robot(event, x, y, flags, param): global deck_ref_points, img_points if event == cv2.EVENT_LBUTTONUP: rx = transform(x, 0) ry = transform(y,1) print("Robot: {}, {}".format(rx, ry)) robot.move_head(x=rx, y=ry)
def btest(n, photoary): petri1 = [89, 125] petri2 = [181, 125] petri3 = [272, 125] petri = [petri1, petri2, petri3] for i in range(n): count = 0 pipette.pick_up_tip(tiprack.wells(i)) for num in range(336): x = 0 y = 0 while y < 640: while x < 480: color = photoary[i][y,x] print(color) x+= 20 if color == 255 : pipette.aspirate(100, water[i]) robot.move_head(x=(petri[i][0] + (x/10)), y= (petri[i][1] +(y/10)), z=100) robot.move_head(x=(petri[i][0] + (x/10)), y= (petri[i][1] +(y/10)), z=-40) pipette.aspirate(100) pipette.dispense(200, pcr[i].wells(count).bottom()) count += 1 if count == 96: return y+= 20 count += 1
def mouse_callback(event): status_str.set("clicked at " + str(event.x) + " " + str(event.y)) pos = c.coords(marker) # cant use move_marker bc mouse y coords are not flipped like the robot coords are x1 = pos[0] y1 = pos[1] x2 = event.x y2 = event.y dx = x2 - x1 dy = y2 - y1 print("x1:",x1,"y1:",y1,"x2:",x2,"y2:",y2,"dx:",dx,"dy:",dy) x = x2 y = Y_MAX - y2 z = get_coords().z print("MPUSE x:", x,"y:",y,"z",z) if in_bounds(x,y,z): c.move(marker, dx, dy) robot.move_head(x=x, y=y, z=z) print("moving robot to: x= ",x," y= ",y, " z= ",z, sep='') pos_str.set("x: " + str(x) + "\ny: " + str(y) + "\nz: " + str(z)) print(status_str.get())
def test_move_head(virtual_smoothie_env): robot.reset() robot.move_head(x=100, y=0) assert isclose( pose_tracker.absolute( robot.poses, robot.gantry)[:2], (100, 0, 0)[:2] ).all()
def samplepick(x1, y1, z1): robot.move_head(x=x1, y=y1, z=100) robot.move_head(x=x1, y=y1, z=z1) #wiggle robot.move_head(x=x1+.5, y=y1+.5, z=z1) robot.move_head(x=x1-1, y=y1-1, z=z1) pipette.aspirate(100) robot.move_head(x=x1, y=y1, z=10)
def move_to(x, y, z): try: old_x = get_coords().x old_y = get_coords().y move_marker(old_x, old_y, x, y) robot.move_head(x=x, y=y, z=z) print("moving robot to: x= ",x," y= ",y, " z= ",z, sep='') pos_str.set("x: " + str(x) + "\ny: " + str(y) + "\nz: " + str(z)) except RuntimeWarning: print("about to crash pls move in the opposite direction") except RuntimeError: print("rip")
def aspirate_from_current_position(): axis = request.json.get("axis") try: # this action mimics 1.2 app experience # but should be re-thought to take advantage of API features instrument = robot._instruments[axis.upper()] robot.move_head(z=20, mode='relative') instrument.motor.move(instrument.positions['blow_out']) instrument.motor.move(instrument.positions['bottom']) robot.move_head(z=-20, mode='relative') instrument.motor.move(instrument.positions['top']) except Exception as e: emit_notifications([str(e)], 'danger') return flask.jsonify({'status': 'error', 'data': str(e)}) return flask.jsonify({'status': 'success', 'data': ''})
def aspirate_from_current_position(): axis = request.json.get("axis") try: _, _, robot_max_z = robot._driver.get_dimensions() current_z = robot._driver.get_position()['current']['z'] jog_up_distance = min(robot_max_z - current_z, 20) robot.move_head(z=jog_up_distance, mode='relative') instrument = robot._instruments[axis.upper()] instrument.motor.move(instrument.positions['blow_out']) instrument.motor.move(instrument.positions['bottom']) robot.move_head(z=-jog_up_distance, mode='relative') instrument.motor.move(instrument.positions['top']) except Exception as e: emit_notifications([str(e)], 'danger') return flask.jsonify({'status': 'error', 'data': str(e)}) return flask.jsonify({'status': 'success', 'data': ''})
def measure(pipette, scale): # dispense onto scale pipette.blow_out(scale.wells(0)) time.sleep(2) # get scale coords use deltas tpo get screen coords = get_coords() new_x = coords[0] + 10 new_y = coords[1] - 90 new_z = coords[2] - 5 robot.move_head(x=new_x, y=new_y, z=new_z) # take a picture of the scale cap = cv2.VideoCapture(2) ret, frame = cap.read() # feed pic into code val = read_scale(frame) # return results return val
def pipscale(pipette, scale, tiprack, trough, trash): # calibrates pipette calibrate_plunger(pipette) # pick up tip pipette.pick_up_tip(tiprack[0]) last_reading = 0 readings = [] for j in range(3): pipette.aspirate(200, trough.wells(0)) pipette.blow_out(scale.wells(0)) time.sleep(2) # get scale coords use deltas tpo get screen coords = get_coords() # pipette.move_to(scale_screen) new_x = coords[0] + 10 new_y = coords[1] - 90 new_z = coords[2] - 5 robot.move_head(x=new_x, y=new_y, z=new_z) scale_reading = read_scale(debug='on') while scale_reading == -1: scale_reading = read_scale(debug='on') amount = to_vol_measurement(scale_reading) tared = amount - last_reading print(amount, tared) readings.append(tared) last_reading = amount total = 0 for val in readings: total += val ave = float(total / len(readings)) print("average out of 3:", ave) pipette.max_volume = ave print(pipette.max_volume) pipette.update_calibrations()
def move_to_slot(): robot = Robot.get_instance() status = 'success' result = '' try: slot = request.json.get("slot") slot = robot._deck[slot] slot_x, slot_y, _ = slot.from_center(x=-1, y=0, z=0, reference=robot._deck) _, _, robot_max_z = robot._driver.get_dimensions() robot.move_head(z=robot_max_z) robot.move_head(x=slot_x, y=slot_y) except Exception as e: result = str(e) status = 'error' emit_notifications([result], 'danger') return flask.jsonify({'status': status, 'data': result})
def jog(): robot = Robot.get_instance() coords = request.json status = 'success' result = '' try: if coords.get("a") or coords.get("b"): result = robot._driver.move_plunger(mode="relative", **coords) else: result = robot.move_head(mode="relative", **coords) except Exception as e: result = str(e) status = 'error' emit_notifications([result], 'danger') return flask.jsonify({'status': status, 'data': result})
def move_to_container(): robot = Robot.get_instance() slot = request.json.get("slot") name = request.json.get("label") axis = request.json.get("axis") try: instrument = robot._instruments[axis.upper()] container = robot._deck[slot].get_child_by_name(name) well_x, well_y, well_z = tuple( instrument.calibrator.convert(container[0], container[0].bottom()[1])) _, _, robot_max_z = robot._driver.get_dimensions() # move to max Z to avoid collisions while calibrating robot.move_head(z=robot_max_z) robot.move_head(x=well_x, y=well_y) robot.move_head(z=well_z) except Exception as e: emit_notifications([str(e)], 'danger') return flask.jsonify({'status': 'error', 'data': str(e)}) return flask.jsonify({'status': 'success', 'data': ''})
def goto1(): robot.move_head(x=89, y=125, z=100)
def goto3(): robot.move_head(x=272, y=125, z=100)
def goto2(): robot.move_head(x=181, y=125, z=100)
def goto2(): robot.move_head(x=175, y=108, z=100)
def goto1(): robot.move_head(x=83, y=108, z=100)
def goto3(): robot.move_head(x=269, y=108, z=100)
def main(stdscr): currentlyCalibrating=placeableNames[0] currentPipette=pipetteNames[0] movementAmount=1 position=list(robot._driver.get_head_position()["current"]) position[0]=0 def chooseWhatToCalibrate(): nonlocal currentlyCalibrating stdscr.clear() stdscr.addstr("What should we calibrate?\n") for i,value in enumerate(placeableNames): stdscr.addstr(str(i+1)+" - " + value+"\n") curses.echo() # Enable echoing of characters s = stdscr.getstr(15,0, 15) stdscr.addstr(s) currentlyCalibrating=placeableNames[int(s)-1] curses.noecho() def chooseWhatPipetteToCalibrate(): nonlocal currentPipette stdscr.clear() stdscr.addstr("What pipette should we calibrate?\n") for i,value in enumerate(pipetteNames): stdscr.addstr(str(i+1)+" - " + value+"\n") curses.echo() # Enable echoing of characters s = stdscr.getstr(10,0, 15) stdscr.addstr(s) currentPipette=pipetteNames[int(s)-1] curses.noecho() # This raises ZeroDivisionError when i == 10. def calibratePlunger(): plungerPos=0 plungerTarget="top" plungerInc=1 while 1: stdscr.clear() stdscr.addstr("PLASMOTRON CALIBRATION MODE - PLUNGER MODE\n\n") stdscr.addstr("Keyboard shortcuts:\n\n") stdscr.addstr("T - start calibrating the 'top' position\n") stdscr.addstr("B - start calibrating the 'bottom' position\n") stdscr.addstr("O - start calibrating the 'blowout' position\n") stdscr.addstr("E - start calibrating the 'eject' position\n\n") stdscr.addstr("Numbers 1-8 - choose how far to move\n") stdscr.addstr("Arrow keys - move plunger up/down\n") stdscr.addstr("S - save this position\n") stdscr.addstr("M - move to this position\n") stdscr.addstr("\n\n") stdscr.addstr("V - switch back to container mode\n\n") stdscr.addstr("Currently calibrating plunger position: ") stdscr.addstr( str(plungerTarget)+"\n",curses.A_STANDOUT) stdscr.addstr("with pipette: ") stdscr.addstr(str(currentPipette)+"\n",curses.A_STANDOUT) stdscr.addstr("Movement increment: ") stdscr.addstr(str(plungerInc)+" mm\n",curses.A_STANDOUT) stdscr.addstr("Current position - X: ") stdscr.addstr(str(plungerPos),curses.A_STANDOUT) key=stdscr.getkey() curses.flushinp() if key=="t": plungerTarget="top" if key=="b": plungerTarget="bottom" if key=="o": plungerTarget="blow_out" if key=="e": plungerTarget="drop_tip" if key=="s": equipment[currentPipette].calibrate(plungerTarget) stdscr.clear() stdscr.addstr("plunger position saved") stdscr.refresh() time.sleep(1) if key=="m": equipment[currentPipette].motor.move(equipment[currentPipette]._get_plunger_position(plungerTarget)) plungerPos=equipment[currentPipette]._get_plunger_position(plungerTarget) if key=="h": equipment[currentPipette].home() plungerPos=0 if key=="v": return() try: if int(key) in movementamounts: plungerInc= movementamounts[int(key)] except ValueError: pass if key == "KEY_UP": plungerPos=plungerPos-plungerInc if key == "KEY_DOWN": plungerPos=plungerPos+plungerInc #stdscr.addstr("Key"+key) equipment[currentPipette].motor.move(plungerPos) stdscr.refresh() while 1: stdscr.clear() stdscr.addstr("PLASMOTRON CALIBRATION MODE\n\n") stdscr.addstr("Keyboard shortcuts:\n") stdscr.addstr("Control+C - exit\n") stdscr.addstr("P - choose what pipette to calibrate with\n") stdscr.addstr("C - choose what container to calibrate\n") stdscr.addstr("S - save this position\n") stdscr.addstr("H - home\n") stdscr.addstr("M - move to the currently saved position\n\n") stdscr.addstr("Numbers 1-8 - choose how far to move\n") stdscr.addstr("Arrow keys - move forwards/back/left/right\n") stdscr.addstr("Control + arrow keys or a and z keys - move up/down\n\n") stdscr.addstr("V - switch to calibrate this pipettes plunger/volume\n\n") stdscr.addstr("Currently pipette: ") stdscr.addstr(str(currentPipette)+"\n",curses.A_STANDOUT) stdscr.addstr("going to: ") stdscr.addstr(str(currentlyCalibrating)+"\n",curses.A_STANDOUT) stdscr.addstr("Movement increment: ") stdscr.addstr( str(movementAmount)+" mm\n",curses.A_STANDOUT) stdscr.addstr("Current position - ") stdscr.addstr("X:"+ str(position[0])+",Y:"+ str(position[1])+",Z:"+ str(position[2]),curses.A_STANDOUT) key=stdscr.getkey() curses.flushinp() if key=="c": chooseWhatToCalibrate() if key=="v": calibratePlunger() if key=="p": chooseWhatPipetteToCalibrate() if key=="s": well = equipment[currentlyCalibrating][0] pos = well.from_center(x=0, y=0, z=-1, reference=equipment[currentlyCalibrating]) location = (equipment[currentlyCalibrating], pos) equipment[currentPipette].calibrate_position(location) stdscr.clear() stdscr.addstr("position saved") stdscr.refresh() time.sleep(1) if key=="m": well = equipment[currentlyCalibrating][0] pos = well.from_center(x=0, y=0, z=-1, reference=equipment[currentlyCalibrating]) location = (equipment[currentlyCalibrating], pos) equipment[currentPipette].move_to(location) position=list(robot._driver.get_head_position()["current"]) if key=="h": robot.home() position=list(robot._driver.get_head_position()["current"]) try: if int(key) in movementamounts: movementAmount= movementamounts[int(key)] except ValueError: pass if key == "kUP5" or key =="a": position[2]=position[2]+movementAmount if key == "kDN5" or key =="z": position[2]=position[2]-movementAmount if key == "KEY_LEFT": position[0]=position[0]-movementAmount if key == "KEY_RIGHT": position[0]=position[0]+movementAmount if key == "KEY_UP": position[1]=position[1]+movementAmount if key == "KEY_DOWN": position[1]=position[1]-movementAmount #stdscr.addstr("Key"+key) robot.move_head(x=position[0],y=position[1],z=position[2]) stdscr.refresh()
p200.pick_up_tip(tiprack[0]) # p200.pick_up_tip(water[0]) # p200.pick_up_tip(scale[0]) # p200.pick_up_tip(scale_screen[0]) last_reading = 0 readings = [] print('beginning image collection') for j in range(100): for i in range(150, 200, 5): p200.aspirate(i, water.wells(0)) p200.blow_out(scale.wells(0)) time.sleep(2) p200.move_to(scale_screen) take_pic(2, 0, img_dir) # random xyz variations print('adding random xyz variations') coords = get_coords() for j in range(3): take_pic(2, 0, img_dir) # coords = get_coords() new_x = coords[0] + random.uniform(-30, 30) new_y = coords[1] + random.uniform(-30, 30) new_z = coords[2] + random.uniform(-30, 30) robot.move_head(x=new_x, y=new_y, z=coords[2]) take_pic(2, 0, img_dir) robot.disconnect()