Skip to content

Commit

Permalink
mostly working but returning position too early
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Jul 6, 2023
1 parent 6067348 commit 92b2674
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 185 deletions.
10 changes: 5 additions & 5 deletions api/src/opentrons/config/defaults_ot3.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@

DEFAULT_ACCELERATIONS: Final[ByGantryLoad[Dict[OT3AxisKind, float]]] = ByGantryLoad(
high_throughput={
OT3AxisKind.X: 600,
OT3AxisKind.Y: 600,
OT3AxisKind.Z: 120,
OT3AxisKind.X: 800,
OT3AxisKind.Y: 500,
OT3AxisKind.Z: 150,
OT3AxisKind.P: 30,
OT3AxisKind.Z_G: 150,
OT3AxisKind.Q: 10,
},
low_throughput={
OT3AxisKind.X: 600,
OT3AxisKind.X: 800,
OT3AxisKind.Y: 600,
OT3AxisKind.Z: 300,
OT3AxisKind.Z: 150,
OT3AxisKind.P: 100,
OT3AxisKind.Z_G: 150,
},
Expand Down
32 changes: 1 addition & 31 deletions api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from contextlib import asynccontextmanager
from functools import wraps
import logging
import time
from copy import deepcopy
from typing import (
Any,
Expand Down Expand Up @@ -63,7 +62,6 @@
from opentrons_hardware.hardware_control.motion_planning import (
Move,
Coordinates,
Block,
)

from opentrons_hardware.hardware_control.motor_enable_disable import (
Expand Down Expand Up @@ -582,14 +580,6 @@ async def home(
if runner
]
positions = await asyncio.gather(*coros)
if OT3Axis.Q in checked_axes:
await self.tip_action(
[OT3Axis.Q],
self.axis_bounds[OT3Axis.Q][1] - self.axis_bounds[OT3Axis.Q][0],
self._configuration.motion_settings.max_speed_discontinuity.high_throughput[
OT3Axis.to_kind(OT3Axis.Q)
],
)
for position in positions:
self._handle_motor_status_response(position)
return axis_convert(self._position, 0.0)
Expand Down Expand Up @@ -619,29 +609,9 @@ async def tip_action(
ignore_stalls=True if not ff.stall_detection_enabled() else False,
)
positions = await runner.run(can_messenger=self._messenger)
# print(f"done w move group runner: {positions} at {time.time()}")
print(f"positions returned = {positions}")
if NodeId.pipette_left in positions:
self._gear_motor_position = positions[NodeId.pipette_left][0]
print(f"gear position is now {self._gear_motor_position}")

# async def tip_action(
# self,
# axes: Sequence[OT3Axis],
# distance: float,
# speed: float,
# acceleration: float = 0,
# tip_action: str = "home",
# ) -> None:
# if tip_action == "home":
# speed = speed * -1
# move_group = create_tip_action_group(
# axes, distance, speed, acceleration, cast(PipetteAction, tip_action)
# )
# # print(f"about to create runner at {time.time()}")
# runner = MoveGroupRunner(move_groups=[move_group])
# positions = await runner.run(can_messenger=self._messenger)
# print(f"positions returned {positions}, at {time.time()}")
# await update_gear_motor_position_estimation(self._messenger)

@requires_update
async def gripper_grip_jaw(
Expand Down
13 changes: 4 additions & 9 deletions api/src/opentrons/hardware_control/backends/ot3simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,13 @@ async def get_tip_present(self, mount: OT3Mount, tip_state: TipStateType) -> Non
"""Get the state of the tip ejector flag for a given mount."""
pass

@ensure_yield
async def tip_action(
self,
axes: Sequence[OT3Axis],
distance: float = 33,
speed: float = -5.5,
acceleration: float = 0,
tip_action: str = "drop",
moves: List[Move],
tip_action: str = "home",
accelerate_during_move: bool = True,
) -> None:
_ = create_tip_action_group(
axes, distance, speed, acceleration, cast(PipetteAction, tip_action)
)
pass

def _attached_to_mount(
self, mount: OT3Mount, expected_instr: Optional[PipetteName]
Expand Down
20 changes: 1 addition & 19 deletions api/src/opentrons/hardware_control/backends/ot3utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def create_move_group(
origin: Coordinates[OT3Axis, CoordinateValue],
moves: List[Move[OT3Axis]],
present_nodes: Iterable[NodeId],
stop_condition: MoveStopCondition,
stop_condition: MoveStopCondition = MoveStopCondition.none,
) -> Tuple[MoveGroup, Dict[NodeId, float]]:
pos = _convert_to_node_id_dict(origin)
move_group: MoveGroup = []
Expand Down Expand Up @@ -395,24 +395,6 @@ def create_tip_action_group(
return move_group


# def create_tip_action_group(
# axes: Sequence[OT3Axis],
# distance: float,
# velocity: float,
# acceleration: float,
# action: PipetteAction,
# ) -> MoveGroup:
# current_nodes = [axis_to_node(ax) for ax in axes]
# step = create_tip_action_step(
# velocity={node_id: np.float64(velocity) for node_id in current_nodes},
# distance={node_id: np.float64(distance) for node_id in current_nodes},
# acceleration={node_id: np.float64(acceleration) for node_id in current_nodes},
# present_nodes=current_nodes,
# action=PipetteTipActionType[action],
# )
# return [step]


def create_gripper_jaw_grip_group(
duty_cycle: float,
stop_condition: MoveStopCondition = MoveStopCondition.none,
Expand Down
108 changes: 42 additions & 66 deletions api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import contextlib
import time
from functools import partial, lru_cache
from dataclasses import replace
import logging
Expand Down Expand Up @@ -698,6 +697,22 @@ async def home_z(
axes = list(OT3Axis.mount_axes())
await self.home(axes)

async def home_gear_motors(self, accelerate_during_move: bool = False) -> None:
if accelerate_during_move:
current_pos = await self._backend.gear_motor_position_estimation()
if current_pos == 0:
return
current_pos_dict = {OT3Axis.Q: current_pos[0]}
else:
# start at the axis boundary, and move without acceleration
# to avoid crashing if the gear motors' positions are not available
axis_bound = self._backend.axis_bounds[OT3Axis.Q][1]
current_pos_dict = {OT3Axis.Q: axis_bound}

home_target = {OT3Axis.Q: 0}
home_moves = self._build_moves(current_pos_dict, home_target)
await self._backend.tip_action(home_moves[0], "home", accelerate_during_move)

async def home_gripper_jaw(self) -> None:
"""
Home the jaw of the gripper.
Expand Down Expand Up @@ -1223,7 +1238,8 @@ async def _home(self, axes: Sequence[OT3Axis]) -> None:
if axis == OT3Axis.G:
await self.home_gripper_jaw()
elif axis == OT3Axis.Q:
await self._backend.home([axis], self.gantry_load)
await self.home_gear_motors()
# add homing with acceleration when position is known also
else:
await self._home_axis(axis)
except ZeroLengthMoveError:
Expand All @@ -1237,22 +1253,6 @@ async def _home(self, axes: Sequence[OT3Axis]) -> None:
await self._cache_current_position()
await self._cache_encoder_position()

async def home_gear_motors(self, accelerate_during_move: bool = False) -> None:
if accelerate_during_move:
current_pos = await self._backend.gear_motor_position_estimation()
if current_pos == 0:
return
print(f"got current gear position = {current_pos}")
current_pos_dict = {OT3Axis.Q: current_pos[0]}
# current_pos_dict = {OT3Axis.Q: 5}
# breakpoint()
else:
current_pos_dict = {OT3Axis.Q: 50}
home_target = {OT3Axis.Q: 0}
home_moves = self._build_moves(current_pos_dict, home_target)
await self._backend.tip_action(home_moves[0], "home", accelerate_during_move)


@ExecutionManagerProvider.wait_for_running
async def home(
self, axes: Optional[Union[List[Axis], List[OT3Axis]]] = None
Expand All @@ -1269,8 +1269,7 @@ async def home(
else:
checked_axes = [ax for ax in OT3Axis if ax != OT3Axis.Q]
if self.gantry_load == GantryLoad.HIGH_THROUGHPUT:
# checked_axes.append(OT3Axis.Q)
await self.home_gear_motors()
checked_axes.append(OT3Axis.Q)
self._log.info(f"Homing {axes}")

home_seq = [
Expand Down Expand Up @@ -1644,7 +1643,7 @@ async def _force_pick_up_tip(
await self._move(target_up)

async def _motor_pick_up_tip(
self, mount: OT3Mount, pipette_spec: TipMotorPickUpTipSpec, accelerate_during_pickup: bool = False,
self, mount: OT3Mount, pipette_spec: TipMotorPickUpTipSpec
) -> None:
async with self._backend.restore_current():
await self._backend.set_active_current(
Expand All @@ -1659,42 +1658,20 @@ async def _motor_pick_up_tip(
await self._move(target_down)
# perform pick up tip

# if accelerate_during_pickup:
# gear_motor_origin = await self._backend.gear_motor_position_estimation()
# gear_origin_dict = {OT3Axis.Q: gear_motor_origin[0]}
gear_origin_dict = {OT3Axis.Q: 0}
gear_motor_target = pipette_spec.pick_up_distance
gear_target_dict = {OT3Axis.Q: gear_motor_target}
gear_motor_origin = await self._backend.gear_motor_position_estimation()
gear_origin_dict = {OT3Axis.Q: gear_motor_origin[0]}
clamp_move_target = pipette_spec.pick_up_distance
gear_target_dict = {OT3Axis.Q: clamp_move_target}
clamp_moves = self._build_moves(gear_origin_dict, gear_target_dict)

await self._backend.tip_action(clamp_moves[0], "clamp")

# else:
# await self._backend.tip_action(
# [OT3Axis.of_main_tool_actuator(mount)],
# float(pipette_spec.pick_up_distance),
# float(pipette_spec.speed),
# float(0),
# "clamp",
# )

# adjust move group for home so that only third tip action request
# expects to hit the limit switch
gear_motor_position = {OT3Axis.Q: self._backend.gear_motor_position}
print(f"gear motor pos = {gear_motor_position}")
home_target = {OT3Axis.Q: 0}
# print(f"passing in gear motor position = {gear_motor_position}")
home_moves = self._build_moves(gear_motor_position, home_target)
# print(f"home moves = {home_moves[0]}")
await self._backend.tip_action(home_moves[0], "home")
# print(f"done almost homing at {time.time()}")

# await self._backend.tip_action(
# [OT3Axis.of_main_tool_actuator(mount)],
# # float(pipette_spec.pick_up_distance + pipette_spec.home_buffer),
# float(5.5),
# float(pipette_spec.speed - 1),
# float(0),
# "home",
# )

async def pick_up_tip(
self,
Expand All @@ -1703,7 +1680,6 @@ async def pick_up_tip(
presses: Optional[int] = None,
increment: Optional[float] = None,
prep_after: bool = True,
accelerate_during_pickup: bool = True,
) -> None:
"""Pick up tip from current location."""
realmount = OT3Mount.from_mount(mount)
Expand All @@ -1713,7 +1689,7 @@ async def pick_up_tip(

await self._move_to_plunger_bottom(realmount, rate=1.0)
if spec.pick_up_motor_actions:
await self._motor_pick_up_tip(realmount, spec.pick_up_motor_actions, accelerate_during_pickup)
await self._motor_pick_up_tip(realmount, spec.pick_up_motor_actions)
else:
await self._force_pick_up_tip(realmount, spec)

Expand Down Expand Up @@ -1754,7 +1730,6 @@ def set_working_volume(
)
instrument.working_volume = tip_volume


async def drop_tip(
self, mount: Union[top_types.Mount, OT3Mount], home_after: bool = False
) -> None:
Expand All @@ -1773,20 +1748,21 @@ async def drop_tip(
if move.is_ht_tip_action and move.speed:
# The speed check is needed because speed can sometimes be None.
# Not sure why
await self._backend.tip_action(
[OT3Axis.of_main_tool_actuator(mount)],
move.target_position,
move.speed,
0,
"clamp",
)
await self._backend.tip_action(
[OT3Axis.of_main_tool_actuator(mount)],
move.target_position + move.home_buffer,
move.speed,
0,
"home",
)

gear_start_position = await self._backend.gear_motor_position_estimation()
gear_start_pos_dict = {OT3Axis.Q: gear_start_position[0]}
drop_target_dict = {OT3Axis.Q: move.target_position}
drop_moves = self._build_moves(gear_start_pos_dict, drop_target_dict)

await self._backend.tip_action(drop_moves[0], "clamp")

current_gear_pos = await self._backend.gear_motor_position_estimation()
gear_pos_dict = {OT3Axis.Q: current_gear_pos[0]}
home_target_dict = {OT3Axis.Q: 0}
home_moves = self._build_moves(gear_pos_dict, home_target_dict)

await self._backend.tip_action(home_moves[0], "home")

else:
target_pos = target_position_from_plunger(
realmount, move.target_position, self._current_position
Expand Down
2 changes: 0 additions & 2 deletions hardware/opentrons_hardware/drivers/can_bus/can_messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ async def send_and_verify_recieved(self) -> ErrorCode:
max(1.0, self._timeout),
)
except asyncio.TimeoutError:
print(f"\n\n no ack received\n\n")
log.error(
f"Message did not receive ack for message index {self._message.payload.message_index}"
)
Expand Down Expand Up @@ -278,7 +277,6 @@ async def _ensure_send(
exclusive: bool = False,
) -> ErrorCode:
if len(expected_nodes) == 0:
print(f"no expected nodes")
log.warning("Expected Nodes should have been specified")
if node_id == NodeId.broadcast:
expected_nodes = _Basic_Nodes.copy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,9 @@ def serialize(self) -> bytes:
"""
string = self._get_format_string()
vals = [x.value for x in astuple(self)]
# breakpoint()
try:
return struct.pack(string, *vals)
except struct.error as e:
# breakpoint()
raise SerializationException(str(e))

@classmethod
Expand Down
1 change: 1 addition & 0 deletions hardware/opentrons_hardware/hardware_control/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def create_tip_action_step(
present_nodes: Iterable[NodeId],
action: PipetteTipActionType,
) -> MoveGroupStep:
"""Creates a step for tip handling actions that require motor movement."""
if action == PipetteTipActionType.home:
stop_condition = MoveStopCondition.limit_switch
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ def targets_to_moves(
for target in targets:
position = {k: np.float64(target.position.get(k, 0)) for k in all_axes}
unit_vector, distance = get_unit_vector(initial_checked, position)
# print(f"using unit vector = {unit_vector}")
# print(f"using max speed = {target.max_speed}")
speed = limit_max_speed(unit_vector, target.max_speed, constraints)
third_distance = np.float64(distance / 3)
m = Move(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def _parser_update_motor_position_response(
node = NodeId(arb_id.parts.originating_node_id)
if node == expected:
return (
float(response.payload.current_position.value / 1000.0),
float(response.payload.current_position.value),
float(response.payload.encoder_position.value) / 1000.0,
bool(
response.payload.position_flags.value
Expand Down
Loading

0 comments on commit 92b2674

Please sign in to comment.