Skip to content

Commit 2a951a6

Browse files
authored
Add static method decorators for movement tolerance, fixed unchanged (#451)
* Add static method decorators for movement tolerance, fixed unchanged * Hatch static analysis * Refactor get_movement_tolerance method to remove self parameter
1 parent 9cfdf2b commit 2a951a6

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

src/ephys_link/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.1"
1+
__version__ = "2.0.2"

src/ephys_link/bindings/fake_binding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ async def get_angles(self, manipulator_id: str) -> Vector3:
5757
async def get_shank_count(self, manipulator_id: str) -> int:
5858
return 1
5959

60+
@staticmethod
6061
@override
61-
def get_movement_tolerance(self) -> float:
62+
def get_movement_tolerance() -> float:
6263
return 0.001
6364

6465
@override

src/ephys_link/bindings/mpm_binding.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ async def get_position(self, manipulator_id: str) -> Vector4:
113113
manipulator_data: dict[str, float] = await self._manipulator_data(manipulator_id)
114114
stage_z: float = manipulator_data["Stage_Z"]
115115

116-
await sleep(self.POLL_INTERVAL) # Wait for the stage to stabilize.
116+
# Wait for the stage to stabilize.
117+
await sleep(self.POLL_INTERVAL)
117118

118119
return Vector4(
119120
x=manipulator_data["Stage_X"],
@@ -139,8 +140,9 @@ async def get_angles(self, manipulator_id: str) -> Vector3:
139140
async def get_shank_count(self, manipulator_id: str) -> int:
140141
return int((await self._manipulator_data(manipulator_id))["ShankCount"]) # pyright: ignore [reportAny]
141142

143+
@staticmethod
142144
@override
143-
def get_movement_tolerance(self) -> float:
145+
def get_movement_tolerance() -> float:
144146
return 0.01
145147

146148
@override
@@ -219,7 +221,11 @@ async def set_depth(self, manipulator_id: str, depth: float, speed: float) -> fl
219221
)
220222

221223
# Wait for the manipulator to reach the target depth or be stopped or get stuck.
222-
while not self._movement_stopped and not abs(current_depth - depth) <= self.get_movement_tolerance():
224+
while (
225+
not self._movement_stopped
226+
and not abs(current_depth - depth) <= self.get_movement_tolerance()
227+
and unchanged_counter < self.UNCHANGED_COUNTER_LIMIT
228+
):
223229
# Wait for a short time before checking again.
224230
await sleep(self.POLL_INTERVAL)
225231

@@ -281,6 +287,7 @@ def unified_space_to_platform_space(self, unified_space: Vector4) -> Vector4:
281287
)
282288

283289
# Helper functions.
290+
284291
async def _query_data(self) -> dict[str, Any]: # pyright: ignore [reportExplicitAny]
285292
try:
286293
# Update cache if it's expired.

src/ephys_link/bindings/ump_4_binding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ async def get_shank_count(self, manipulator_id: str) -> NoReturn:
7777
error_message = "UMP-4 does not support getting shank count"
7878
raise AttributeError(error_message)
7979

80+
@staticmethod
8081
@override
81-
def get_movement_tolerance(self) -> float:
82+
def get_movement_tolerance() -> float:
8283
return 0.001
8384

8485
@override

src/ephys_link/utils/base_binding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ async def get_shank_count(self, manipulator_id: str) -> int:
9999
Number of shanks on the manipulator.
100100
"""
101101

102+
@staticmethod
102103
@abstractmethod
103-
def get_movement_tolerance(self) -> float:
104+
def get_movement_tolerance() -> float:
104105
"""Get the tolerance for how close the final position must be to the target position in a movement (mm).
105106
106107
Returns:

0 commit comments

Comments
 (0)