def test__stackable__calibrate_upper_rack(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') r_below.getSavedSlotCenter = mock.MagicMock() r_below.getSavedSlotCenter.return_value = (200, 100, 600) # Initially defining slot for lower rack, but not for the upper one r_below.overwriteSlot(1, 4) # Parameters of a bottom rack r_below.updateCenter(x=200, y=100, z=600, x_btm_touch=100, y_btm_touch=50, z_btm_touch=550) #r_below.save() #r_below.getSavedSlotCenter = mock.MagicMock() #r_below.getSavedSlotCenter.return_value = (200, 100, 600) r_below.placeItemOnTop(r) # Parameters of the top rack that were inherited from the bottom rack; before top rack # calibration x_cal, y_cal, z_cal, opposite_x, orthogonal_y, raise_z = r.getSimpleCalibrationPoints( ) self.assertEqual(x_cal, 129) self.assertEqual(y_cal, 100) self.assertEqual(z_cal, 406)
def test__plate_gripper__test__plate_gripper__grabAndPlaceStackable_SameSpot( self): cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "mobile gripper" tools.llc.serial.Serial = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') gr = tools.mobile_gripper(robot=ar, com_port_number='COM3', tool_name='mobile_gripper') gr.operateGripper = mock.MagicMock() gr.getToRackCenter = mock.MagicMock() s1 = racks.stackable(rack_name='RackThatCannotBeNamed-1', rack_type='test_rack') s1.overwriteSlot(1, 3) s2 = racks.stackable(rack_name='RackThatCannotBeNamed-2', rack_type='test_rack') s1.rack_data['position'] = [400, 200, 500] s1.rack_data['pos_stalagmyte'] = [200, 100, 400] gr.setStalagmyteCoord(x=210, y=95, z=530) s2.max_height = 100 s2.setGrippingProperties(90, 80, 10, gripper=gr) s1.placeItemOnTop(s2) gr.grabRack(s2) gr.robot.move.assert_has_calls([mock.call(z=400 - 400 + 530 + 10)]) gr.placeRack(s1) gr.robot.move.assert_has_calls([mock.call(z=400 - 400 + 530 + 10)])
def test__stackable__getSimpleCalibrationPoints(self): """ Checks that function returns proper calibration points for stackables """ r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') # Initially defining slot for lower rack, but not for the upper one r_below.overwriteSlot(1, 4) # Parameters of a bottom rack r_below.getSavedSlotCenter = mock.MagicMock() r_below.getSavedSlotCenter.return_value = (200, 100, 600) # r_below.x_width = 150 # r_below.x_init_calibrat_dist_from_wall = 5 # r_below.z_height = 20 # r_below.xy_calibrat_height_dz = 5 # r_below.y_width = 90 # r_below.y_init_calibrat_dist_from_wall = 5 # r_below.max_height = 20 # r_below.dz_clearance = 10 # # # r.x_width = 150 # r.x_init_calibrat_dist_from_wall = 5 # r.z_height = 20 # r.xy_calibrat_height_dz = 5 # r.y_width = 90 # r.y_init_calibrat_dist_from_wall = 5 # r.max_height = 20 # r.dz_clearance = 10 r_below.placeItemOnTop(r) bx_cal, by_cal, bz_cal, b_opposite_x, b_orthogonal_y, b_raise_z = r_below.getSimpleCalibrationPoints( ) #self.assertEqual(bx_cal, 200 - 130/2 - 6) x_cal, y_cal, z_cal, opposite_x, orthogonal_y, raise_z = r.getSimpleCalibrationPoints( ) self.assertEqual(x_cal, 129) self.assertEqual(y_cal, 100) self.assertEqual(bz_cal, 506) self.assertEqual(z_cal, 406) self.assertEqual(r_below.z_height, 100) self.assertEqual(r.z_height, 200) self.assertEqual(opposite_x, 142) self.assertEqual(orthogonal_y, 46) self.assertGreater(raise_z, 6)
def test__stackable__getCalibratedRackCenter__upper_rack_calibrated(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') r_below.overwriteSlot(1, 4) # Placing rack without calibration r_below.placeItemOnTop(r) # Upper rack receives calibration r.updateCenter(200, 100, 400, 50, 70, 450) self.assertEqual(r_below.getCalibratedRackCenter(), (200, 100, 500)) self.assertEqual(r.getCalibratedRackCenter(), (200, 100, 400))
def test__stackable__getCalibratedRackCenter__re_calibration(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') r_below.overwriteSlot(1, 4) r_below.rack_data['position'] = [200, 100, 600] r_below.placeItemOnTop(r) self.assertEqual(r_below.getCalibratedRackCenter(), (200, 100, 600)) self.assertEqual(r.getCalibratedRackCenter(), (200, 100, 500)) # Simulating upper rack re-calibration r.updateCenter(210, 95, 502, 51, 72, 449) self.assertEqual(r_below.getCalibratedRackCenter(), (210, 95, 602)) self.assertEqual(r.getCalibratedRackCenter(), (210, 95, 502))
def test__getSampleCenter__WithCalibration2(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') s = samples.sample(sample_name='SampleThatCannotBeNamed', sample_type='test_sample') # Rack receives calibration r.updateCenter(200, 100, 400, 50, 70, 450) # Placing sample into the rack s.place(r, 0, 0) cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "Servo" tools.llc.serial.Serial = mock.MagicMock() tools.pipettor.home = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') p1000 = tools.pipettor.getTool(robot=ar, tool_name='p1000_tool') # Tool receives calibration p1000.setStalagmyteCoord(51, 69, 420) x, y = s.getSampleCenterXY(p1000) self.assertEqual(x, 201 - 51.75) self.assertEqual(y, 99 - 33.75)
def test__plate_gripper__grabRack__open_close_diameters(self): cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "mobile gripper" tools.llc.serial.Serial = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') gr = tools.mobile_gripper(robot=ar, com_port_number='COM3', tool_name='mobile_gripper') gr.operateGripper = mock.MagicMock() gr.getToRackCenter = mock.MagicMock() gr.setStalagmyteCoord(x=210, y=95, z=530) gr.toDiameter = mock.MagicMock() s1 = racks.stackable(rack_name='RackThatCannotBeNamed-1', rack_type='test_rack') s1.rack_data['position'] = [400, 200, 500] s1.rack_data['pos_stalagmyte'] = [200, 100, 400] s1.setGrippingProperties(90, 80, 10, gripper=gr) gr.grabRack(s1) gr.toDiameter.assert_has_calls([ mock.call(diameter=90, powerdown=False), mock.call(diameter=80, powerdown=False) ])
def test__stackable__getCalibratedRackCenter__lower_rack_calibrated(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') r_below.overwriteSlot(1, 4) #r_below.getSavedSlotCenter = mock.MagicMock() #r_below.getSavedSlotCenter.return_value = (200, 100, 600) r_below.rack_data['position'] = [200, 100, 600] r_below.placeItemOnTop(r) self.assertEqual(r_below.getCalibratedRackCenter(), (200, 100, 600)) self.assertEqual(r.getCalibratedRackCenter(), (200, 100, 500))
def test__calibrateRack__stackable(self): cartesian.arnie = mock.MagicMock() tools.mobile_touch_probe = mock.MagicMock() # Initializing robot with a tool (mocked) ar = cartesian.arnie('COM1', 'COM2') tp = tools.mobile_touch_probe('COM3') # Touch probe parameters tp.getStalagmyteCoord = mock.MagicMock() tp.getStalagmyteCoord.return_value = (66, 66, 500) # Initializing stack of racks r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') r_below.overwriteSlot(1, 4) # Parameters of a bottom rack r_below.getSavedSlotCenter = mock.MagicMock() r_below.getSavedSlotCenter.return_value = (200, 100, 600) # Forming a stack by placing top rack onto the bottom rack r_below.placeItemOnTop(r) # Mocking findCenterOuter function to give different outputs for 'x' and 'y' tp.findCenterOuter = mock.MagicMock(side_effect=[205, 95]) tp.findWall = mock.MagicMock() tp.findWall.return_value = 301 # Performing calibration x, y, z = calibration.calibrateRack(tp, r) # Evaluating outputs self.assertEqual(x, 205) self.assertEqual(y, 95) self.assertEqual(z, 301) # Evaluating robot movements based on provided parameters tp.robot.move.assert_has_calls([ mock.call(x=129, y=100, z=406, z_first=False), mock.call(x=205, y=54), mock.call(x=205, y=95), mock.call(z=400) ])
def test__stackable__calibrate_upper_rack__coords_save(self): # before-test cleanup try: os.remove('RackThatCannotBeNamed.json') except: pass try: os.remove('BottomRackThatCannotBeNamed.json') except: pass r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') # Initially defining slot for lower rack, but not for the upper one r_below.overwriteSlot(1, 4) # Parameters of a bottom rack r_below.rack_data['position'] = [200, 100, 600] # Placing rack r on top of the r_below r_below.placeItemOnTop(r) # Simulating upper rack re-calibration r.updateCenter(210, 95, 502, 51, 72, 449) # Saving re-calibration (part of any calibration routine) r.save() self.assertEqual(r_below.getCalibratedRackCenter(), (210, 95, 602)) self.assertEqual(r.getCalibratedRackCenter(), (210, 95, 502)) # Re-initializing bottom rack to see if it still has updated coordinates r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') self.assertEqual(r_below.getCalibratedRackCenter(), (210, 95, 602)) # after-test cleanup try: os.remove('RackThatCannotBeNamed.json') except: pass try: os.remove('BottomRackThatCannotBeNamed.json') except: pass
def test__mobile_gripper__grabRack(self, mock_serialdev, mock_readAll, mock_cartesian): # Same as above, but using a real rack object # Defining all mock values and parameters for gripper mock_readAll.return_value = "mobile gripper" ar = cartesian.arnie('COM1', 'COM2') gr = tools.mobile_gripper(robot=ar, com_port_number='COM3', tool_name='mobile_gripper') gr.operateGripper = mock.MagicMock() gr.getToRackCenter = mock.MagicMock() # Emulating tool calibration gr.setStalagmyteCoord(x=210, y=95, z=530) # Initializing a test rack r = racks.stackable(rack_name="p1000_1_test", rack_data={ 'n_x': 0, 'n_y': 2, 'type': 'p1000_tips' }) r.updateCenter(x=100, y=200, z=550, x_btm_touch=90, y_btm_touch=66, z_btm_touch=500) #r.z_working_height = 0 r.setGrippingProperties(open_diam=90, grip_diam=80, z_relative_to_top=10, gripper=gr) self.assertEqual(gr.getStalagmyteCoord()[2], 530) self.assertEqual(r.rack_data['pos_stalagmyte'][2], 500) self.assertEqual( r.calcRackCenterFullCalibration(gr)[2], 550 - 8 - 500 + 530) self.assertEqual(r.getGrippingHeight(gr), 550 - 8 - 500 + 530 + 10) # Calling function to see if errors appear param_dict = gr.grabRack(r, test=True) # Checking gripper instance parameters changed self.assertEqual(gr.sample, r) self.assertEqual(gr.gripper_has_something, True) self.assertEqual(gr.added_z_length, 86) # Testing correctness of the default settings self.assertEqual(r.rack_data['position'][2], 550) self.assertEqual(r.getCalibratedRackCenter()[2], 550) self.assertEqual(r.z_working_height, -8) self.assertEqual(gr.getStalagmyteCoord()[2], 530 - 86) self.assertEqual(param_dict['open_diam'], 90) self.assertEqual(param_dict['close_diam'], 80) self.assertEqual(param_dict['z_grab'], 582) self.assertEqual(param_dict['z_retract'], 582 - 86)
def test__stackableOnTop__ManualPlacement(self): """ User manually places a stack onto the robot. """ try: os.remove('RackThatCannotBeNamed.json') except: pass try: os.remove('BottomRackThatCannotBeNamed.json') except: pass # The case when a user manually places a stack onto the robot. r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack', x_slot=1, y_slot=4) r.max_height = 100 # User would initialize those racks manually. Both racks has no calibration at this point self.assertRaises(KeyError, lambda x: r_below.rack_data['position'], 1) self.assertRaises(KeyError, lambda x: r.rack_data['position'], 1) racks.logging.error = mock.MagicMock( ) # removing logging error message for not calibrated rack r_below.placeItemOnTop(r) self.assertEqual(r_below.getTopItem(), r) # Simulating calibration routine # This is a very simple simulation, need to test an actual calibration routine # Top rack is calibrated, as the bottom ones are impossible to calibrate r.updateCalibratedRackCenter(x=402, y=198, z=405) r.updateStalagmyteCalibration(x=200, y=100, z=400) # Checking whether upper rack received its calibration parameters self.assertEqual(r.getCalibratedRackCenter(), (402, 198, 405)) self.assertEqual(r.getStalagmyteCalibration(), (200, 100, 400)) # Removing top rack r_below.removeTopItem() # Checking whether the bottom rack received calibration data # And that the bottom rack height is correctly calculated self.assertEqual(r_below.getCalibratedRackCenter(), (402, 198, 505)) self.assertEqual(r.getStalagmyteCalibration(), (200, 100, 400))
def test__stackableOnTop(self): """ This one tests behaviour of a stackable rack on top of a stack """ r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r_below = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack', x_slot=1, y_slot=4) r.max_height = 100 self.assertEqual(r.top_item, None) self.assertEqual(r.getTopItem(), None) # Now simulating the bottom rack being calibrated, and then a new one # placed on top of the bottom rack. r_below.rack_data['position'] = [400, 200, 500] r_below.rack_data['pos_stalagmyte'] = [200, 100, 400] self.assertEqual(r_below.getCalibratedRackCenter(), (400, 200, 500)) r_below.placeItemOnTop(r) # Stackable rack has height 100 mm, so the new top will be 100 mm above calibrated value # X and Y values stays the same. self.assertEqual(r.getCalibratedRackCenter(), (400, 200, 500 - 100)) self.assertEqual(r_below.getTopItem(), r) # Now simulating removal of the top rack from the bottom rack r_below.removeTopItem() self.assertEqual(r_below.getTopItem(), None) # Coordinates should stay the same as before self.assertEqual(r_below.getCalibratedRackCenter(), (400, 200, 500)) # Now simulating the case when the neq rack was placed on top, calibrated, # received new calibration values and then removed. r_below.placeItemOnTop(r) r.updateCalibratedRackCenter( 402, 198, 405) # new values are slightly different then old ones. r_below.removeTopItem() self.assertEqual(r_below.getCalibratedRackCenter(), (402, 198, 505))
def test__mobile_gripper__placeRack(self): gripped_rack = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') dest_rack = racks.stackable(rack_name='BottomRackThatCannotBeNamed', rack_type='test_rack') dest_rack.updateCenter(600, 300, 550, 90, 66, 500) dest_rack.overwriteSlot(1, 3) cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "mobile gripper" tools.llc.serial.Serial = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') gr = tools.mobile_gripper(robot=ar, com_port_number='COM3', tool_name='mobile_gripper') gr.operateGripper = mock.MagicMock() gr.getToRackCenter = mock.MagicMock() gr.setStalagmyteCoord(x=210, y=95, z=430) gripped_rack.setGrippingProperties(90, 80, 10, gripper=gr) dest_rack.setGrippingProperties(90, 80, 10, gripper=gr) gr.sample = gripped_rack placed_rack_object, param_dict = gr.placeRack(dest_rack, test=True) self.assertEqual(gr.getStalagmyteCoord()[2], 430) self.assertEqual(dest_rack.calcRackCenterFullCalibration(tool=gr), (600 + 210 - 90, 300 + 95 - 66, 550 + 430 - 500)) self.assertEqual(gripped_rack, placed_rack_object) self.assertEqual(param_dict['destination_coord'][0], 600 + 210 - 90) self.assertEqual(param_dict['destination_coord'][1], 300 + 95 - 66) self.assertEqual(param_dict['destination_coord'][2], 550 + 430 - 500) self.assertEqual(param_dict['rack_heigth'], 100) self.assertEqual(param_dict['z_final_absolute'], 480) self.assertEqual(param_dict['open_diam'], 90)
def test_calcWorkingPosition2(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') # Rack receives calibration r.updateCenter(200, 100, 400, 50, 70, 450) cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "Servo" tools.llc.serial.Serial = mock.MagicMock() tools.pipettor.home = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') p1000 = tools.pipettor.getTool(robot=ar, tool_name='p1000_tool') # Tool receives calibration p1000.setStalagmyteCoord(51, 69, 420) x, y, z = r.calcWorkingPosition(well_col=0, well_row=0, tool=p1000) self.assertEqual(x, 201 - 51.75) self.assertEqual(y, 99 - 33.75) self.assertEqual(z, 370)
def test__plate_gripper__grabAndPlaceStackable(self): cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "mobile gripper" tools.llc.serial.Serial = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') gr = tools.mobile_gripper(robot=ar, com_port_number='COM3', tool_name='mobile_gripper') gr.operateGripper = mock.MagicMock() gr.getToRackCenter = mock.MagicMock() s1 = racks.stackable(rack_name='RackThatCannotBeNamed-1', rack_type='test_rack') s1.overwriteSlot(1, 3) s2 = racks.stackable(rack_name='RackThatCannotBeNamed-2', rack_type='test_rack') s3 = racks.stackable(rack_name='RackThatCannotBeNamed-3', rack_type='test_rack') s3.overwriteSlot(2, 4) s1.rack_data['position'] = [400, 200, 500] s1.rack_data['pos_stalagmyte'] = [200, 100, 400] s3.rack_data['position'] = [800, 330, 300] s3.rack_data['pos_stalagmyte'] = [200, 100, 400] gr.setStalagmyteCoord(x=210, y=95, z=530) s2.max_height = 100 s2.setGrippingProperties(90, 80, 10, gripper=gr) s1.placeItemOnTop(s2) self.assertEqual(s2.getCalibratedRackCenter(), (400, 200, 400)) self.assertEqual(s2.rack_data['pos_stalagmyte'], [200, 100, 400]) self.assertEqual(s2.getStalagmyteCalibration(), (200, 100, 400)) self.assertEqual(s2.rack_data['n_x'], 1) self.assertEqual(s2.rack_data['n_y'], 3) param_dict = gr.grabRack(s2, test=True) # Bottom rack shall now has no top rack: self.assertEqual(s1.getTopItem(), None) # Rack is in the gripper self.assertEqual(gr.sample, s2) self.assertEqual(gr.gripper_has_something, True) self.assertEqual(gr.added_z_length, 90) # Grabbing parameters self.assertEqual(param_dict['z_grab'], 400 - 0 - 400 + 530 + 10) # Placing to the new rack placed_rack_object, param_dict = gr.placeRack(s3, test=True) # Checking that gripper has nothing left self.assertEqual(gr.sample, None) self.assertEqual(gr.gripper_has_something, False) self.assertEqual(gr.added_z_length, 0) # Updated rack parameters: self.assertEqual(s2.getCalibratedRackCenter(), (800, 330, 200)) self.assertEqual(s2.getStalagmyteCalibration(), (200, 100, 400)) self.assertEqual(s3.getTopItem(), s2) self.assertEqual(s2.bottom_item, s3) self.assertEqual(s2.rack_data['n_x'], 2) self.assertEqual(s2.rack_data['n_y'], 4)
def test__getStalagmyteCalibration(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') # Simulating stalagmyte calibration data r.rack_data['pos_stalagmyte'] = [200, 100, 400] self.assertEqual(r.getStalagmyteCalibration(), (200, 100, 400))
def test__getCalibratedRackCenter(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') r.rack_data['position'] = [400, 200, 500] self.assertEqual(r.getCalibratedRackCenter(), (400, 200, 500))