Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions api/src/opentrons/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ class Point(NamedTuple):
y: float = 0.0
z: float = 0.0

def __eq__(self, other: Any) -> bool:
if not isinstance(other, Point):
return False
pairs = ((self.x, other.x), (self.y, other.y), (self.z, other.z))
return all(isclose(s, o, rel_tol=1e-05, abs_tol=1e-08) for s, o in pairs)

def __add__(self, other: Any) -> Point:
if not isinstance(other, Point):
return NotImplemented
Expand Down Expand Up @@ -75,6 +69,12 @@ def magnitude_to(self, other: Any) -> float:
z_diff = self.z - other.z
return sqrt(x_diff**2 + y_diff**2 + z_diff**2)

def elementwise_isclose(
self, other: Point, *, rel_tol: float = 1e-05, abs_tol: float = 1e-08
) -> bool:
pairs = ((self.x, other.x), (self.y, other.y), (self.z, other.z))
return all(isclose(s, o, rel_tol=rel_tol, abs_tol=abs_tol) for s, o in pairs)


LocationLabware = Union[
"Labware",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import inspect
import pytest
from datetime import datetime
from decoy import Decoy
from decoy import Decoy, matchers
from typing import TYPE_CHECKING

from opentrons.hardware_control import ot3_calibration
Expand Down Expand Up @@ -93,18 +93,21 @@ async def test_calibrate_gripper_saves_calibration(
status=CalibrationStatus(markedBad=False),
last_modified=datetime(year=3000, month=1, day=1),
)
saved_delta_captor = matchers.Captor()
decoy.when(
await ot3_calibration.calibrate_gripper_jaw(
ot3_hardware_api, probe=GripperProbe.REAR
)
).then_return(Point(1.1, 2.2, 3.3))
decoy.when(
await ot3_hardware_api.save_instrument_offset(
mount=OT3Mount.GRIPPER, delta=Point(x=2.75, y=3.85, z=4.95)
mount=OT3Mount.GRIPPER, delta=saved_delta_captor
)
).then_return(expected_calibration_data)
result = await subject.execute(params)
saved_delta: Point = saved_delta_captor.value
assert result.public.jawOffset == Vec3f(x=1.1, y=2.2, z=3.3)
assert saved_delta.elementwise_isclose(Point(x=2.75, y=3.85, z=4.95))
assert result.public.savedCalibration == expected_calibration_data


Expand Down
30 changes: 18 additions & 12 deletions api/tests/opentrons/protocol_engine/state/test_geometry_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,10 +1390,12 @@ def test_get_well_position(

result = subject.get_well_position("labware-id", "B2")

assert result == Point(
x=slot_pos[0] + 1 + well_def.x,
y=slot_pos[1] - 2 + well_def.y,
z=slot_pos[2] + 3 + well_def.z + well_def.depth,
assert result.elementwise_isclose(
Point(
x=slot_pos[0] + 1 + well_def.x,
y=slot_pos[1] - 2 + well_def.y,
z=slot_pos[2] + 3 + well_def.z + well_def.depth,
)
)


Expand Down Expand Up @@ -1473,10 +1475,12 @@ def test_get_module_labware_well_position(
).then_return(OverlapOffset(x=0, y=0, z=0))

result = subject.get_well_position("labware-id", "B2")
assert result == Point(
x=slot_pos[0] + 1 + well_def.x + 4,
y=slot_pos[1] - 2 + well_def.y + 5,
z=slot_pos[2] + 3 + well_def.z + well_def.depth + 6,
assert result.elementwise_isclose(
Point(
x=slot_pos[0] + 1 + well_def.x + 4,
y=slot_pos[1] - 2 + well_def.y + 5,
z=slot_pos[2] + 3 + well_def.z + well_def.depth + 6,
)
)


Expand Down Expand Up @@ -1522,10 +1526,12 @@ def test_get_well_position_with_top_offset(
),
)

assert result == Point(
x=slot_pos[0] + 1 + well_def.x + 1,
y=slot_pos[1] - 2 + well_def.y + 2,
z=slot_pos[2] + 3 + well_def.z + well_def.depth + 3,
assert result.elementwise_isclose(
Point(
x=slot_pos[0] + 1 + well_def.x + 1,
y=slot_pos[1] - 2 + well_def.y + 2,
z=slot_pos[2] + 3 + well_def.z + well_def.depth + 3,
)
)


Expand Down