Skip to content

Commit

Permalink
fix(api): dont emit 0-duration moves (#13121)
Browse files Browse the repository at this point in the history
They really stress the microcontrollers and they do absolutely nothing,
so let's not put them on the bus.
  • Loading branch information
sfoster1 authored Jul 18, 2023
1 parent 60df992 commit 9275a85
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/src/opentrons/hardware_control/backends/ot3utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Shared utilities for ot3 hardware control."""
from typing import Dict, Iterable, List, Set, Tuple, TypeVar, Sequence
from typing_extensions import Literal
from logging import getLogger
from opentrons.config.defaults_ot3 import DEFAULT_CALIBRATION_AXIS_MAX_SPEED
from opentrons.config.types import OT3MotionSettings, OT3CurrentSettings, GantryLoad
from opentrons.hardware_control.types import (
Expand Down Expand Up @@ -52,6 +53,7 @@
create_gripper_jaw_step,
create_tip_action_step,
)
from opentrons_hardware.hardware_control.constants import interrupts_per_sec

GRIPPER_JAW_HOME_TIME: float = 10
GRIPPER_JAW_GRIP_TIME: float = 10
Expand Down Expand Up @@ -83,6 +85,8 @@

USB_SUBSYSTEM = {target: subsystem for subsystem, target in SUBSYSTEM_USB.items()}

LOG = getLogger(__name__)


def axis_nodes() -> List["NodeId"]:
return [
Expand Down Expand Up @@ -331,6 +335,11 @@ def create_move_group(
for move in moves:
unit_vector = move.unit_vector
for block in move.blocks:
if block.time < (3.0 / interrupts_per_sec):
LOG.info(
f"Skipping move block with time {block.time} (<{3.0/interrupts_per_sec})"
)
continue
distances = unit_vector_multiplication(unit_vector, block.distance)
node_id_distances = _convert_to_node_id_dict(distances)
velocities = unit_vector_multiplication(unit_vector, block.initial_speed)
Expand Down
36 changes: 36 additions & 0 deletions api/tests/opentrons/hardware_control/backends/test_ot3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from opentrons.hardware_control.backends import ot3utils
from opentrons_hardware.firmware_bindings.constants import NodeId
from opentrons.hardware_control.types import OT3Axis
from numpy import float64 as f64


def test_create_step() -> None:
Expand All @@ -16,6 +17,12 @@ def test_create_step() -> None:
moves = [
Move.build_dummy([OT3Axis.X, OT3Axis.Y, OT3Axis.Z_L, OT3Axis.Z_R, OT3Axis.P_L])
]
for block in moves[0].blocks:
block.distance = f64(25.0)
block.time = f64(1.0)
block.initial_speed = f64(25.0)
block.acceleration = f64(0.0)
block.final_speed = f64(25.0)
present_nodes = [NodeId.gantry_x, NodeId.gantry_y, NodeId.head_l]
move_group, final_pos = ot3utils.create_move_group(
origin=origin,
Expand All @@ -27,6 +34,35 @@ def test_create_step() -> None:
assert set(present_nodes) == set(step.keys())


def test_filter_zero_duration_step() -> None:
origin = {
OT3Axis.X: 0,
OT3Axis.Y: 0,
OT3Axis.Z_L: 0,
OT3Axis.Z_R: 0,
OT3Axis.P_L: 0,
OT3Axis.P_R: 0,
}
moves = [
Move.build_dummy([OT3Axis.X, OT3Axis.Y, OT3Axis.Z_L, OT3Axis.Z_R, OT3Axis.P_L])
]
for block in (moves[0].blocks[0], moves[0].blocks[1]):
block.distance = f64(25.0)
block.time = f64(1.0)
block.initial_speed = f64(25.0)
block.acceleration = f64(0.0)
block.final_speed = f64(25.0)
present_nodes = [NodeId.gantry_x, NodeId.gantry_y, NodeId.head_l]
move_group, final_pos = ot3utils.create_move_group(
origin=origin,
moves=moves,
present_nodes=present_nodes,
)
assert len(move_group) == 2
for step in move_group:
assert set(present_nodes) == set(step.keys())


def test_nodeid_replace_head() -> None:
assert ot3utils.replace_head_node(set([NodeId.head, NodeId.gantry_x])) == set(
[NodeId.head_l, NodeId.head_r, NodeId.gantry_x]
Expand Down

0 comments on commit 9275a85

Please sign in to comment.