Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hardware): add acceleration to pick up tip for 96 channel #12944

Merged
merged 28 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
95d068b
add acceleration to tip_action
caila-marashaj Jun 15, 2023
b4d4bee
pick up tip move happens, but rumbly
caila-marashaj Jun 21, 2023
bdea049
linter stuff cleanup
caila-marashaj Jun 21, 2023
782a760
fixed position of acceleration in tipaction msg
caila-marashaj Jun 22, 2023
73d26bf
moving but delayed
caila-marashaj Jun 27, 2023
c3e044a
modify tip action, debugging code still in there
caila-marashaj Jun 28, 2023
a85074e
mostly working but returning position too early
caila-marashaj Jun 29, 2023
1952348
need to update tests
caila-marashaj Jul 6, 2023
fa194a3
updated unit test args for tip_action
caila-marashaj Jul 17, 2023
d2e7927
rebase
caila-marashaj Jul 17, 2023
2b20a20
rough final draft
caila-marashaj Jul 18, 2023
8cf3c15
cleanup
caila-marashaj Jul 18, 2023
7e5b7ef
format
caila-marashaj Jul 18, 2023
8ace0ef
remove redundant data check from gear motors
caila-marashaj Jul 18, 2023
155738b
hardware controller changes
caila-marashaj Jul 19, 2023
0aede03
increase backward distances
caila-marashaj Jul 20, 2023
97e12e9
changed helpers_ot3 function
caila-marashaj Jul 21, 2023
1550c9a
format
caila-marashaj Jul 21, 2023
735ebe7
helpers_ot3 function change
caila-marashaj Jul 21, 2023
af1eefa
got rid of copysign call
caila-marashaj Jul 21, 2023
e2280aa
check if speed exists
caila-marashaj Jul 21, 2023
5be4492
add deafult value to axis convert call
caila-marashaj Jul 24, 2023
93ef4ca
update gear motor position handling after move
caila-marashaj Jul 25, 2023
f1a42d1
test fix
caila-marashaj Jul 25, 2023
2b71f07
moved comments
caila-marashaj Jul 26, 2023
57bb955
remove updategearmotorpositionestimation msg
caila-marashaj Jul 26, 2023
e201a43
removed more unneeded code
caila-marashaj Jul 26, 2023
6eb76e6
address change reqs
caila-marashaj Jul 27, 2023
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
Prev Previous commit
Next Next commit
need to update tests
  • Loading branch information
caila-marashaj committed Jul 26, 2023
commit 19523480611e739a3beddccb9a1c3de0147de330
24 changes: 18 additions & 6 deletions api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
create_gripper_jaw_hold_group,
create_tip_action_group,
PipetteAction,
create_gear_motor_home_group,
motor_nodes,
LIMIT_SWITCH_OVERTRAVEL_DISTANCE,
map_pipette_type_to_sensor_id,
Expand Down Expand Up @@ -259,7 +260,7 @@ def __init__(
self._estop_detector: Optional[EstopDetector] = None
self._estop_state_machine = EstopStateMachine(detector=None)
self._position = self._get_home_position()
self._gear_motor_position = None
self._gear_motor_position: float
caila-marashaj marked this conversation as resolved.
Show resolved Hide resolved
self._encoder_position = self._get_home_position()
self._motor_status = {}
self._check_updates = check_updates
Expand Down Expand Up @@ -622,20 +623,31 @@ def _filter_move_group(self, move_group: MoveGroup) -> MoveGroup:
)
return new_group

async def home_gear_motors(
self,
distance: float,
velocity: float,
) -> None:
caila-marashaj marked this conversation as resolved.
Show resolved Hide resolved
move_group = create_gear_motor_home_group(distance, velocity)
runner = MoveGroupRunner(
move_groups=[move_group],
ignore_stalls=True if not ff.stall_detection_enabled() else False,
)
positions = await runner.run(can_messenger=self._messenger)
if NodeId.pipette_left in positions:
self._gear_motor_position = positions[NodeId.pipette_left][0]

async def tip_action(
caila-marashaj marked this conversation as resolved.
Show resolved Hide resolved
self,
moves: List[Move],
moves: List[Move[OT3Axis]],
tip_action: str = "home",
accelerate_during_move: bool = True,
) -> None:
group = create_tip_action_group(moves, [NodeId.pipette_left], tip_action, accelerate_during_move)
move_group = group
move_group = create_tip_action_group(moves, [NodeId.pipette_left], tip_action)
runner = MoveGroupRunner(
move_groups=[move_group],
ignore_stalls=True if not ff.stall_detection_enabled() else False,
)
positions = await runner.run(can_messenger=self._messenger)
print(f"positions returned = {positions}")
if NodeId.pipette_left in positions:
caila-marashaj marked this conversation as resolved.
Show resolved Hide resolved
self._gear_motor_position = positions[NodeId.pipette_left][0]
print(f"gear position is now {self._gear_motor_position}")
Expand Down
8 changes: 6 additions & 2 deletions api/src/opentrons/hardware_control/backends/ot3simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __init__(
self._initialized = False
self._lights = {"button": False, "rails": False}
self._estop_state_machine = EstopStateMachine(detector=None)
self._gear_motor_position = 0

def _sanitize_attached_instrument(
mount: OT3Mount, passed_ai: Optional[Dict[str, Optional[str]]] = None
Expand Down Expand Up @@ -203,6 +204,10 @@ def initialized(self, value: bool) -> None:
def eeprom_data(self) -> EEPROMData:
return EEPROMData()

@property
def gear_motor_position(self) -> Optional[float]:
return self._gear_motor_position

@property
def board_revision(self) -> BoardRevision:
"""Get the board revision"""
Expand Down Expand Up @@ -374,9 +379,8 @@ async def get_tip_present(self, mount: OT3Mount, tip_state: TipStateType) -> Non

async def tip_action(
self,
moves: List[Move],
moves: List[Move[OT3Axis]],
tip_action: str = "home",
accelerate_during_move: bool = True,
) -> None:
pass

Expand Down
22 changes: 16 additions & 6 deletions api/src/opentrons/hardware_control/backends/ot3utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,18 +401,14 @@ def create_tip_action_home_group(
def create_tip_action_group(
moves: List[Move[OT3Axis]],
present_nodes: Iterable[NodeId],
action: PipetteTipActionType,
accelerate_during_move: bool = True,
action: str,
) -> MoveGroup:
move_group: MoveGroup = []
for move in moves:
unit_vector = move.unit_vector
for block in move.blocks:
velocities = unit_vector_multiplication(unit_vector, block.initial_speed)
if accelerate_during_move:
accelerations = unit_vector_multiplication(unit_vector, block.acceleration)
else:
accelerations = {OT3Axis.Q: 0}
accelerations = unit_vector_multiplication(unit_vector, block.acceleration)
step = create_tip_action_step(
velocity=_convert_to_node_id_dict(velocities),
acceleration=_convert_to_node_id_dict(accelerations),
Expand All @@ -424,6 +420,20 @@ def create_tip_action_group(
return move_group


def create_gear_motor_home_group(
distance: float,
velocity: float,
) -> MoveGroup:
step = create_tip_action_step(
velocity={NodeId.pipette_left: np.float64(velocity)},
acceleration={NodeId.pipette_left: np.float64(0)},
duration=np.float64(distance / velocity),
present_nodes=[NodeId.pipette_left],
action=PipetteTipActionType.home,
)
return [step]


def create_gripper_jaw_grip_group(
duty_cycle: float,
stop_condition: MoveStopCondition = MoveStopCondition.none,
Expand Down
50 changes: 27 additions & 23 deletions api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,21 +730,29 @@ async def home_z(
axes = list(Axis.ot3_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:
async def home_gear_motors(self) -> None:
caila-marashaj marked this conversation as resolved.
Show resolved Hide resolved
gear_motor_axis_bound = self._backend.axis_bounds[OT3Axis.Q][1]
position_estimation = self._backend.gear_motor_position
velocity = self._config.motion_settings.default_max_speed[
GantryLoad.HIGH_THROUGHPUT
][OT3AxisKind.Q]
if position_estimation is not None:
position_valid = abs(position_estimation) < gear_motor_axis_bound
if position_valid:
position_dict = {OT3Axis.Q: position_estimation}
safe_home_target = {OT3Axis.Q: self._config.safe_home_distance}
moves = self._build_moves(position_dict, safe_home_target)

await self._backend.tip_action(moves[0], "clamp")
distance = self._backend.gear_motor_position

await self._backend.home_gear_motors(distance, velocity)
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)
# if gear motor position is not known:
# 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]
await self._backend.home_gear_motors(axis_bound, velocity)

async def home_gripper_jaw(self) -> None:
"""
Expand Down Expand Up @@ -1704,12 +1712,7 @@ async def _motor_pick_up_tip(

await self._backend.tip_action(clamp_moves[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}
home_target = {OT3Axis.Q: 0}
home_moves = self._build_moves(gear_motor_position, home_target)
await self._backend.tip_action(home_moves[0], "home")
await self.home_gear_motors()
caila-marashaj marked this conversation as resolved.
Show resolved Hide resolved

async def pick_up_tip(
self,
Expand Down Expand Up @@ -1782,7 +1785,9 @@ async def drop_tip(
# The speed check is needed because speed can sometimes be None.
# Not sure why

gear_start_position = await self._backend.gear_motor_position_estimation()
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)
Expand All @@ -1791,7 +1796,7 @@ async def drop_tip(

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_target_dict = {OT3Axis.Q: 0.0}
home_moves = self._build_moves(gear_pos_dict, home_target_dict)

await self._backend.tip_action(home_moves[0], "home")
Expand Down Expand Up @@ -1822,7 +1827,6 @@ async def drop_tip(

_remove()


async def clean_up(self) -> None:
"""Get the API ready to stop cleanly."""
await self._backend.clean_up()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ async def _parser_update_gear_motor_position_response(
reader: WaitableCallback, expected: NodeId
) -> Tuple[float, bool]:
async for response, arb_id in reader:
if isinstance(response, UpdateGearMotorPositionEstimationResponse): # or isinstance(response, TipActionResponse):
if isinstance(
response, UpdateGearMotorPositionEstimationResponse
): # or isinstance(response, TipActionResponse):
node = NodeId(arb_id.parts.originating_node_id)
if node == expected:
return (
Expand Down
22 changes: 2 additions & 20 deletions hardware/opentrons_hardware/hardware_control/move_group_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,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 @@ -169,30 +168,12 @@ async def run(

@staticmethod
def _accumulate_move_completions(
self,
completions: _Completions,
) -> NodeDict[Tuple[float, float, bool, bool]]:
position: NodeDict[
List[Tuple[Tuple[int, int], float, float, bool, bool]]
] = defaultdict(list)
for arbid, completion in completions:
if isinstance(completion, TipActionResponse):
caila-marashaj marked this conversation as resolved.
Show resolved Hide resolved
# assuming the two gear motors finish at the same time in the case of
# the 96 channel, return their position
for move in self._expected_tip_action_motors:
if not any(self._expected_tip_action_motors):
# if the nested list is empty, we are done with all 3
# tip action moves and should return the current position

return {
arbid.parts.originating_node_id:
(
completion.payload.current_position_um.value / 1000.0,
completion.payload.encoder_position_um.value / 1000.0,
True,
True,
)
}
position[NodeId(arbid.parts.originating_node_id)].append(
(
(
Expand Down Expand Up @@ -518,6 +499,7 @@ def __call__(
elif isinstance(message, TipActionResponse):
if self._handle_tip_action_motors(message):
self._remove_move_group(message, arbitration_id)
self._handle_move_completed(message, arbitration_id)
elif isinstance(message, ErrorMessage):
self._handle_error(message, arbitration_id)

Expand Down