|
47 | 47 | from opentrons.protocol_engine.types import (
|
48 | 48 | ModuleModel as ProtocolEngineModuleModel,
|
49 | 49 | OFF_DECK_LOCATION,
|
| 50 | + SYSTEM_LOCATION, |
50 | 51 | LabwareLocation,
|
51 | 52 | NonStackedLocation,
|
52 | 53 | )
|
|
77 | 78 | )
|
78 | 79 | from .exceptions import InvalidModuleLocationError
|
79 | 80 | from . import load_labware_params, deck_conflict, overlap_versions
|
| 81 | +from opentrons.protocol_engine.resources import labware_validation |
80 | 82 |
|
81 | 83 | if TYPE_CHECKING:
|
82 | 84 | from ...labware import Labware
|
@@ -442,6 +444,203 @@ def move_labware(
|
442 | 444 | existing_module_ids=list(self._module_cores_by_id.keys()),
|
443 | 445 | )
|
444 | 446 |
|
| 447 | + def move_lid( # noqa: C901 |
| 448 | + self, |
| 449 | + source_location: Union[DeckSlotName, StagingSlotName, LabwareCore], |
| 450 | + new_location: Union[ |
| 451 | + DeckSlotName, |
| 452 | + StagingSlotName, |
| 453 | + LabwareCore, |
| 454 | + OffDeckType, |
| 455 | + WasteChute, |
| 456 | + TrashBin, |
| 457 | + ], |
| 458 | + use_gripper: bool, |
| 459 | + pause_for_manual_move: bool, |
| 460 | + pick_up_offset: Optional[Tuple[float, float, float]], |
| 461 | + drop_offset: Optional[Tuple[float, float, float]], |
| 462 | + ) -> LabwareCore | None: |
| 463 | + """Move the given lid to a new location.""" |
| 464 | + if use_gripper: |
| 465 | + strategy = LabwareMovementStrategy.USING_GRIPPER |
| 466 | + elif pause_for_manual_move: |
| 467 | + strategy = LabwareMovementStrategy.MANUAL_MOVE_WITH_PAUSE |
| 468 | + else: |
| 469 | + strategy = LabwareMovementStrategy.MANUAL_MOVE_WITHOUT_PAUSE |
| 470 | + |
| 471 | + if isinstance(source_location, DeckSlotName) or isinstance( |
| 472 | + source_location, StagingSlotName |
| 473 | + ): |
| 474 | + # Find the source labware at the provided deck slot |
| 475 | + labware_in_slot = self._engine_client.state.labware.get_by_slot( |
| 476 | + source_location |
| 477 | + ) |
| 478 | + if labware_in_slot is None: |
| 479 | + raise LabwareNotLoadedOnLabwareError( |
| 480 | + "Lid cannot be loaded on non-labware position." |
| 481 | + ) |
| 482 | + else: |
| 483 | + labware = LabwareCore(labware_in_slot.id, self._engine_client) |
| 484 | + else: |
| 485 | + labware = source_location |
| 486 | + |
| 487 | + # if this is a labware stack, we need to find the labware at the top of the stack |
| 488 | + if labware_validation.is_lid_stack(labware.load_name): |
| 489 | + lid_id = self._engine_client.state.labware.get_highest_child_labware( |
| 490 | + labware.labware_id |
| 491 | + ) |
| 492 | + # if this is a labware with a lid, we just need to find its lid_id |
| 493 | + else: |
| 494 | + lid = self._engine_client.state.labware.get_lid_by_labware_id( |
| 495 | + labware.labware_id |
| 496 | + ) |
| 497 | + if lid is not None: |
| 498 | + lid_id = lid.id |
| 499 | + else: |
| 500 | + raise ValueError("Cannot move a lid off of a labware with no lid.") |
| 501 | + |
| 502 | + _pick_up_offset = ( |
| 503 | + LabwareOffsetVector( |
| 504 | + x=pick_up_offset[0], y=pick_up_offset[1], z=pick_up_offset[2] |
| 505 | + ) |
| 506 | + if pick_up_offset |
| 507 | + else None |
| 508 | + ) |
| 509 | + _drop_offset = ( |
| 510 | + LabwareOffsetVector(x=drop_offset[0], y=drop_offset[1], z=drop_offset[2]) |
| 511 | + if drop_offset |
| 512 | + else None |
| 513 | + ) |
| 514 | + |
| 515 | + create_new_lid_stack = False |
| 516 | + |
| 517 | + if isinstance(new_location, DeckSlotName) or isinstance( |
| 518 | + new_location, StagingSlotName |
| 519 | + ): |
| 520 | + # Find the destination labware at the provided deck slot |
| 521 | + destination_labware_in_slot = self._engine_client.state.labware.get_by_slot( |
| 522 | + new_location |
| 523 | + ) |
| 524 | + if destination_labware_in_slot is None: |
| 525 | + to_location = self._convert_labware_location(location=new_location) |
| 526 | + # absolutely must make a new lid stack |
| 527 | + create_new_lid_stack = True |
| 528 | + else: |
| 529 | + highest_child_location = ( |
| 530 | + self._engine_client.state.labware.get_highest_child_labware( |
| 531 | + destination_labware_in_slot.id |
| 532 | + ) |
| 533 | + ) |
| 534 | + if labware_validation.validate_definition_is_adapter( |
| 535 | + self._engine_client.state.labware.get_definition( |
| 536 | + highest_child_location |
| 537 | + ) |
| 538 | + ): |
| 539 | + # absolutely must make a new lid stack |
| 540 | + create_new_lid_stack = True |
| 541 | + |
| 542 | + to_location = self._convert_labware_location( |
| 543 | + location=LabwareCore(highest_child_location, self._engine_client) |
| 544 | + ) |
| 545 | + elif isinstance(new_location, LabwareCore): |
| 546 | + highest_child_location = ( |
| 547 | + self._engine_client.state.labware.get_highest_child_labware( |
| 548 | + new_location.labware_id |
| 549 | + ) |
| 550 | + ) |
| 551 | + if labware_validation.validate_definition_is_adapter( |
| 552 | + self._engine_client.state.labware.get_definition(highest_child_location) |
| 553 | + ): |
| 554 | + # absolutely must make a new lid stack |
| 555 | + create_new_lid_stack = True |
| 556 | + to_location = self._convert_labware_location( |
| 557 | + location=LabwareCore(highest_child_location, self._engine_client) |
| 558 | + ) |
| 559 | + else: |
| 560 | + to_location = self._convert_labware_location(location=new_location) |
| 561 | + |
| 562 | + output_result = None |
| 563 | + if create_new_lid_stack: |
| 564 | + # Make a new lid stack object that is empty |
| 565 | + result = self._engine_client.execute_command_without_recovery( |
| 566 | + cmd.LoadLidStackParams( |
| 567 | + location=SYSTEM_LOCATION, |
| 568 | + loadName="empty", |
| 569 | + version=1, |
| 570 | + namespace="empty", |
| 571 | + quantity=0, |
| 572 | + ) |
| 573 | + ) |
| 574 | + |
| 575 | + # Move the lid stack object from the SYSTEM_LOCATION space to the desired deck location |
| 576 | + self._engine_client.execute_command( |
| 577 | + cmd.MoveLabwareParams( |
| 578 | + labwareId=result.stackLabwareId, |
| 579 | + newLocation=to_location, |
| 580 | + strategy=LabwareMovementStrategy.MANUAL_MOVE_WITHOUT_PAUSE, |
| 581 | + pickUpOffset=None, |
| 582 | + dropOffset=None, |
| 583 | + ) |
| 584 | + ) |
| 585 | + |
| 586 | + output_result = LabwareCore( |
| 587 | + labware_id=result.stackLabwareId, engine_client=self._engine_client |
| 588 | + ) |
| 589 | + destination = self._convert_labware_location(location=output_result) |
| 590 | + else: |
| 591 | + destination = to_location |
| 592 | + |
| 593 | + self._engine_client.execute_command( |
| 594 | + cmd.MoveLabwareParams( |
| 595 | + labwareId=lid_id, |
| 596 | + newLocation=destination, |
| 597 | + strategy=strategy, |
| 598 | + pickUpOffset=_pick_up_offset, |
| 599 | + dropOffset=_drop_offset, |
| 600 | + ) |
| 601 | + ) |
| 602 | + |
| 603 | + # Handle leftover empty lid stack if there is one |
| 604 | + if ( |
| 605 | + labware_validation.is_lid_stack(labware.load_name) |
| 606 | + and self._engine_client.state.labware.get_highest_child_labware( |
| 607 | + labware_id=labware.labware_id |
| 608 | + ) |
| 609 | + == labware.labware_id |
| 610 | + ): |
| 611 | + # The originating lid stack is now empty, so we need to move it to the SYSTEM_LOCATION |
| 612 | + self._engine_client.execute_command( |
| 613 | + cmd.MoveLabwareParams( |
| 614 | + labwareId=labware.labware_id, |
| 615 | + newLocation=SYSTEM_LOCATION, |
| 616 | + strategy=LabwareMovementStrategy.MANUAL_MOVE_WITHOUT_PAUSE, |
| 617 | + pickUpOffset=None, |
| 618 | + dropOffset=None, |
| 619 | + ) |
| 620 | + ) |
| 621 | + |
| 622 | + if strategy == LabwareMovementStrategy.USING_GRIPPER: |
| 623 | + # Clear out last location since it is not relevant to pipetting |
| 624 | + # and we only use last location for in-place pipetting commands |
| 625 | + self.set_last_location(location=None, mount=Mount.EXTENSION) |
| 626 | + |
| 627 | + # FIXME(jbl, 2024-01-04) deck conflict after execution logic issue, read notes in load_labware for more info: |
| 628 | + deck_conflict.check( |
| 629 | + engine_state=self._engine_client.state, |
| 630 | + new_labware_id=lid_id, |
| 631 | + existing_disposal_locations=self._disposal_locations, |
| 632 | + # TODO: We can now fetch these IDs from engine too. |
| 633 | + # See comment in self.load_labware(). |
| 634 | + existing_labware_ids=[ |
| 635 | + labware_id |
| 636 | + for labware_id in self._labware_cores_by_id |
| 637 | + if labware_id != labware_id |
| 638 | + ], |
| 639 | + existing_module_ids=list(self._module_cores_by_id.keys()), |
| 640 | + ) |
| 641 | + |
| 642 | + return output_result |
| 643 | + |
445 | 644 | def _resolve_module_hardware(
|
446 | 645 | self, serial_number: str, model: ModuleModel
|
447 | 646 | ) -> AbstractModule:
|
@@ -734,6 +933,7 @@ def load_lid_stack(
|
734 | 933 | )
|
735 | 934 |
|
736 | 935 | # FIXME(CHB, 2024-12-04) just like load labware and load adapter we have a validating after loading the object issue
|
| 936 | + assert load_result.definition is not None |
737 | 937 | validation.ensure_definition_is_lid(load_result.definition)
|
738 | 938 |
|
739 | 939 | deck_conflict.check(
|
|
0 commit comments