Skip to content

Commit

Permalink
linter stuff cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Jun 21, 2023
1 parent a959486 commit 15c5190
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 53 deletions.
3 changes: 0 additions & 3 deletions api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,10 @@ async def update_motor_status(self) -> None:
response = await get_motor_position(self._messenger, motor_nodes)
self._handle_motor_status_response(response)



async def gear_motor_position_estimation(self) -> Tuple[float, bool]:
response = await update_gear_motor_position_estimation(self._messenger)

return response
# self._position.update({OT3Axis.Q: response[0]})

async def update_motor_estimation(self, axes: Sequence[OT3Axis]) -> None:
"""Update motor position estimation for commanded nodes, and update cache of data."""
Expand Down
7 changes: 6 additions & 1 deletion api/src/opentrons/hardware_control/backends/ot3simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ async def update_motor_status(self) -> None:
(node, MotorStatus(True, True)) for node in self._present_nodes
)

@ensure_yield
async def gear_motor_position_estimation(self) -> None:
return None

@ensure_yield
async def update_motor_estimation(self, axes: Sequence[OT3Axis]) -> None:
"""Update motor position estimation for commanded nodes, and update cache of data."""
Expand Down Expand Up @@ -363,10 +367,11 @@ async def tip_action(
axes: Sequence[OT3Axis],
distance: float = 33,
speed: float = -5.5,
acceleration: float = 0,
tip_action: str = "drop",
) -> None:
_ = create_tip_action_group(
axes, distance, speed, cast(PipetteAction, tip_action)
axes, distance, speed, acceleration, cast(PipetteAction, tip_action)
)

def _attached_to_mount(
Expand Down
7 changes: 3 additions & 4 deletions api/src/opentrons/hardware_control/backends/ot3utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ def get_system_constraints(
) -> "SystemConstraints[OT3Axis]":
conf_by_pip = config.by_gantry_load(gantry_load)
constraints = {}
axis_kind = [
axis_kind_list = [
OT3AxisKind.P,
OT3AxisKind.X,
OT3AxisKind.Y,
OT3AxisKind.Z,
OT3AxisKind.Z_G,
]
if gantry_load == GantryLoad.HIGH_THROUGHPUT:
axis_kind.append(OT3AxisKind.Q)
for axis_kind in axis_kind:
axis_kind_list.append(OT3AxisKind.Q)
for axis_kind in axis_kind_list:
for axis in OT3Axis.of_kind(axis_kind):
constraints[axis] = AxisConstraints.build(
conf_by_pip["acceleration"][axis_kind],
Expand All @@ -236,7 +236,6 @@ def get_system_constraints(
conf_by_pip["default_max_speed"][axis_kind],
)


return constraints


Expand Down
37 changes: 12 additions & 25 deletions api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,9 +1600,6 @@ async def _force_pick_up_tip(
)
await self._move(target_up)

async def get_gear_position(self):
return await self._backend.gear_motor_position_estimation()

async def _motor_pick_up_tip(
self, mount: OT3Mount, pipette_spec: TipMotorPickUpTipSpec
) -> None:
Expand All @@ -1619,33 +1616,27 @@ async def _motor_pick_up_tip(
await self._move(target_down)
# perform pick up tip

# gear_origin_dict = {OT3Axis.Q: 0}
gear_motor_origin = await self._backend.gear_motor_position_estimation()
gear_origin_dict = {
OT3Axis.Q: gear_motor_origin[0]
}
gear_origin_dict = {OT3Axis.Q: gear_motor_origin[0]}
gear_motor_target = pipette_spec.pick_up_distance + pipette_spec.home_buffer
gear_target_dict = {OT3Axis.Q: gear_motor_target}
moves = self._build_moves(gear_origin_dict, gear_target_dict)
blocks = moves[0][0].blocks

for block in blocks:
print(f"block speed = {block.initial_speed}")
print(f"block acceleration = {block.acceleration}")
await self._backend.tip_action(
[OT3Axis.of_main_tool_actuator(mount)],
block.distance,
block.initial_speed,
block.acceleration,
"clamp",
[OT3Axis.of_main_tool_actuator(mount)],
float(block.distance),
float(block.initial_speed),
float(block.acceleration),
"clamp",
)
# back clamps off the adapter posts
print(f"pipette spec speed = {pipette_spec.speed}")
await self._backend.tip_action(
[OT3Axis.of_main_tool_actuator(mount)],
pipette_spec.pick_up_distance + pipette_spec.home_buffer,
(pipette_spec.speed - 1),
0,
float(pipette_spec.pick_up_distance + pipette_spec.home_buffer),
float(pipette_spec.speed),
float(0),
"home",
)

Expand Down Expand Up @@ -1700,7 +1691,7 @@ def set_working_volume(
instrument.working_volume = tip_volume

async def drop_tip(
self, mount: Union[top_types.Mount, OT3Mount], home_after: bool = True
self, mount: Union[top_types.Mount, OT3Mount], home_after: bool = False
) -> None:
"""Drop tip at the current location."""
realmount = OT3Mount.from_mount(mount)
Expand Down Expand Up @@ -1739,15 +1730,11 @@ async def drop_tip(
speed=move.speed,
home_flagged_axes=False,
)
if move.home_after:
await self._home([OT3Axis.from_axis(ax) for ax in move.home_axes])
if move.home_after:
await self._home([OT3Axis.from_axis(ax) for ax in move.home_axes])

for shake in spec.shake_moves:
await self.move_rel(mount, shake[0], speed=shake[1])

# home mount axis
if home_after:
await self._home([OT3Axis.by_mount(mount)])

await self._backend.set_active_current(
{
Expand Down
7 changes: 3 additions & 4 deletions api/src/opentrons/hardware_control/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class OT3AxisKind(enum.Enum):
#: Plunger axis (of the left and right pipettes)
Z_G = 4
#: Gripper Z axis
Q = 5
Q = 6
#: High-throughput tip grabbing axis
OTHER = 5
#: The internal axes of high throughput pipettes, for instance
Expand Down Expand Up @@ -222,7 +222,7 @@ def to_kind(cls, axis: "OT3Axis") -> OT3AxisKind:
cls.Z_L: OT3AxisKind.Z,
cls.Z_R: OT3AxisKind.Z,
cls.Z_G: OT3AxisKind.Z_G,
cls.Q: OT3AxisKind.OTHER,
cls.Q: OT3AxisKind.Q,
cls.G: OT3AxisKind.OTHER,
}
return kind_map[axis]
Expand All @@ -236,8 +236,7 @@ def of_kind(cls, kind: OT3AxisKind) -> List["OT3Axis"]:
OT3AxisKind.Z: [cls.Z_L, cls.Z_R],
OT3AxisKind.Z_G: [cls.Z_G],
OT3AxisKind.Q: [cls.Q],
OT3AxisKind.OTHER: [cls.Q],
# OT3AxisKind.OTHER: [cls.G],
OT3AxisKind.OTHER: [cls.Q, cls.G],
}
return kind_map[kind]

Expand Down
1 change: 0 additions & 1 deletion api/tests/opentrons/hardware_control/test_ot3_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,6 @@ async def test_save_instrument_offset(
)



async def test_pick_up_tip_full_tiprack(
ot3_hardware: ThreadManager[OT3API],
mock_instrument_handlers: Tuple[Mock],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,18 @@ class UpdateMotorPositionEstimationResponse(BaseMessage): # noqa: D101


@dataclass
class UpdateGearMotorPositionEstimationRequest(EmptyPayloadMessage): # noqa D101
class UpdateGearMotorPositionEstimationRequest(EmptyPayloadMessage): # noqa: D101
message_id: Literal[
MessageId.update_gear_motor_position_estimation_request
] = MessageId.update_gear_motor_position_estimation_request


@dataclass
class UpdateGearMotorPositionEstimationResponse(BaseMessage): # noqa D101
class UpdateGearMotorPositionEstimationResponse(BaseMessage): # noqa: D101
payload: payloads.GearMotorPositionResponse
payload_type: Type[payloads.GearMotorPositionResponse] = payloads.GearMotorPositionResponse
payload_type: Type[
payloads.GearMotorPositionResponse
] = payloads.GearMotorPositionResponse
message_id: Literal[
MessageId.update_gear_motor_position_estimation_response
] = MessageId.update_gear_motor_position_estimation_response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ class MoveCompletedPayload(MoveGroupResponsePayload):

@dataclass(eq=False)
class GearMotorPositionResponse(EmptyPayload):
"""Read Gear Motor Position Estimation."""

current_position: utils.UInt32Field



@dataclass(eq=False)
class MotorPositionResponse(EmptyPayload):
"""Read Encoder Position."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,20 @@ async def update_gear_motor_position_estimation(
"""

def _listener_filter(arbitration_id: ArbitrationId) -> bool:
return (NodeId(arbitration_id.parts.originating_node_id) in {NodeId.pipette_left}) and (
return (

Check warning on line 160 in hardware/opentrons_hardware/hardware_control/motor_position_status.py

View check run for this annotation

Codecov / codecov/patch

hardware/opentrons_hardware/hardware_control/motor_position_status.py#L159-L160

Added lines #L159 - L160 were not covered by tests
NodeId(arbitration_id.parts.originating_node_id) in {NodeId.pipette_left}
) and (
MessageId(arbitration_id.parts.message_id)
== UpdateGearMotorPositionEstimationResponse.message_id
)

data = []

Check warning on line 167 in hardware/opentrons_hardware/hardware_control/motor_position_status.py

View check run for this annotation

Codecov / codecov/patch

hardware/opentrons_hardware/hardware_control/motor_position_status.py#L167

Added line #L167 was not covered by tests

# for node in nodes:
with WaitableCallback(can_messenger, _listener_filter) as reader:
await can_messenger.send(

Check warning on line 170 in hardware/opentrons_hardware/hardware_control/motor_position_status.py

View check run for this annotation

Codecov / codecov/patch

hardware/opentrons_hardware/hardware_control/motor_position_status.py#L169-L170

Added lines #L169 - L170 were not covered by tests
node_id=NodeId.pipette_left,
message=UpdateGearMotorPositionEstimationRequest(),
)
print(f"SENT GEAR MOTOR ESTIMATION REQUEST")
try:
for i in range(2):
response = await asyncio.wait_for(

Check warning on line 176 in hardware/opentrons_hardware/hardware_control/motor_position_status.py

View check run for this annotation

Codecov / codecov/patch

hardware/opentrons_hardware/hardware_control/motor_position_status.py#L174-L176

Added lines #L174 - L176 were not covered by tests
Expand Down Expand Up @@ -199,7 +199,6 @@ async def _parser_update_gear_motor_position_response(
reader: WaitableCallback, expected: NodeId
) -> Tuple[float, bool]:
async for response, arb_id in reader:
print(f"\nGOT RESPONSE {response}\n")
assert isinstance(response, UpdateGearMotorPositionEstimationResponse)
node = NodeId(arb_id.parts.originating_node_id)
if node == expected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def __init__(
"""
self._move_groups = move_groups
self._start_at_index = start_at_index
# self._ignore_stalls = ignore_stalls
self._ignore_stalls = True
self._ignore_stalls = ignore_stalls
self._is_prepped: bool = False

@staticmethod
Expand Down Expand Up @@ -311,12 +310,12 @@ def _get_tip_action_motor_message(
acceleration=Int32Field(
int(
(
step.acceleration_mm_sec_sq
* 1000.0
/ interrupts_per_sec
/ interrupts_per_sec
step.acceleration_mm_sec_sq
* 1000.0
/ interrupts_per_sec
/ interrupts_per_sec
)
* (2 ** 31)
* (2**31)
)
),
action=PipetteTipActionTypeField(step.action),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async def run_gear_motors(args: argparse.Namespace) -> None:
{
pipette_node: MoveGroupTipActionStep(
velocity_mm_sec=float64(5.5),
acceleration_mm_sec_sq=float64(0),
duration_sec=float64(2.5),
stop_condition=MoveStopCondition.none,
action=PipetteTipActionType.clamp,
Expand All @@ -140,6 +141,7 @@ async def run_gear_motors(args: argparse.Namespace) -> None:
{
pipette_node: MoveGroupTipActionStep(
velocity_mm_sec=float64(-5.0),
acceleration_mm_sec_sq=float64(0),
duration_sec=float64(6),
stop_condition=MoveStopCondition.limit_switch,
action=PipetteTipActionType.home,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async def run(args: argparse.Namespace) -> None:
{
pipette_node: MoveGroupTipActionStep(
velocity_mm_sec=float64(5.5),
acceleration_mm_sec_sq=float64(0),
duration_sec=float64(2.5),
stop_condition=MoveStopCondition.none,
action=PipetteTipActionType.clamp,
Expand All @@ -86,6 +87,7 @@ async def run(args: argparse.Namespace) -> None:
{
pipette_node: MoveGroupTipActionStep(
velocity_mm_sec=float64(-5.5),
acceleration_mm_sec_sq=float64(0),
duration_sec=float64(6),
stop_condition=MoveStopCondition.limit_switch,
action=PipetteTipActionType.home,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def move_group_tip_action() -> MoveGroups:
{
NodeId.pipette_left: MoveGroupTipActionStep(
velocity_mm_sec=float64(2),
acceleration_mm_sec_sq=float64(0),
duration_sec=float64(1),
action=PipetteTipActionType.clamp,
stop_condition=MoveStopCondition.none,
Expand Down

0 comments on commit 15c5190

Please sign in to comment.