Skip to content

Commit

Permalink
321 detect stopped movement from controller and stop all movements (#322
Browse files Browse the repository at this point in the history
)

* Detect in Sensapex ump4

* Report if New Scale and uMp-3 did not make it to target
  • Loading branch information
kjy5 authored Feb 7, 2024
1 parent 1e29860 commit b05bc1e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/ephys_link/platform_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData:
raise NotImplementedError

@abstractmethod
async def _goto_pos(self, manipulator_id: str, position: list[float], speed: int) -> com.PositionalOutputData:
async def _goto_pos(self, manipulator_id: str, position: list[float], speed: float) -> com.PositionalOutputData:
raise NotImplementedError

@abstractmethod
async def _drive_to_depth(self, manipulator_id: str, depth: float, speed: int) -> com.DriveToDepthOutputData:
async def _drive_to_depth(self, manipulator_id: str, depth: float, speed: float) -> com.DriveToDepthOutputData:
raise NotImplementedError

@abstractmethod
Expand Down
1 change: 1 addition & 0 deletions src/ephys_link/platform_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):
"""Initialize manipulator."""

self._id = None
self._movement_tolerance = 0.001
self._calibrated = False
self._inside_brain = False
self._can_write = False
Expand Down
17 changes: 17 additions & 0 deletions src/ephys_link/platforms/new_scale_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,18 @@ async def goto_pos(self, position: list[float], speed: float) -> com.PositionalO

# Return success unless write was disabled during movement (meaning a stop occurred)
if not self._can_write:
com.dprint(f"[ERROR]\t\t Manipulator {self._id} movement canceled")
return com.PositionalOutputData([], "Manipulator movement canceled")

# Return error if movement did not reach target.
if not all(
abs(manipulator_final_position[i] - position[i]) < self._movement_tolerance
for i in range(len(position))
):
com.dprint(f"[ERROR]\t\t Manipulator {self._id} did not reach target position")
return com.PositionalOutputData([], "Manipulator did not reach target position")

# Made it to the target.
com.dprint(f"[SUCCESS]\t Moved manipulator {self._id} to position" f" {manipulator_final_position}\n")
return com.PositionalOutputData(manipulator_final_position, "")
except Exception as e:
Expand Down Expand Up @@ -208,8 +218,15 @@ async def drive_to_depth(self, depth: float, speed: float) -> com.DriveToDepthOu

# Return success unless write was disabled during movement (meaning a stop occurred)
if not self._can_write:
com.dprint(f"[ERROR]\t\t Manipulator {self._id} movement canceled")
return com.DriveToDepthOutputData(0, "Manipulator movement canceled")

# Return error if movement did not reach target.
if not abs(manipulator_final_position[3] - depth) < self._movement_tolerance:
com.dprint(f"[ERROR]\t\t Manipulator {self._id} did not reach target depth")
return com.DriveToDepthOutputData(0, "Manipulator did not reach target depth")

# Made it to the target.
com.dprint(f"[SUCCESS]\t Moved manipulator {self._id} to position" f" {manipulator_final_position}\n")
return com.DriveToDepthOutputData(manipulator_final_position[3], "")
except Exception as e:
Expand Down
16 changes: 13 additions & 3 deletions src/ephys_link/platforms/sensapex_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,24 @@ async def goto_pos(self, position: list[float], speed: float) -> com.PositionalO
# Get position
manipulator_final_position = self.get_pos()["position"]

# Mark movement as finished
# Mark movement as finished.
self._is_moving = False

# Return success unless write was disabled during movement (meaning a stop occurred)
# Return success unless write was disabled during movement (meaning a stop occurred).
if not self._can_write:
com.dprint(f"[ERROR]\t\t Manipulator {self._id} movement canceled")
return com.PositionalOutputData([], "Manipulator movement canceled")

com.dprint(f"[SUCCESS]\t Moved manipulator {self._id} to position" f" {manipulator_final_position}\n")
# Return error if movement did not reach target.
if not all(
abs(manipulator_final_position[i] - position[i]) < self._movement_tolerance
for i in range(len(position))
):
com.dprint(f"[ERROR]\t\t Manipulator {self._id} did not reach target position")
return com.PositionalOutputData([], "Manipulator did not reach target position")

# Made it to the target.
com.dprint(f"[SUCCESS]\t Moved manipulator {self._id} to position {manipulator_final_position}\n")
return com.PositionalOutputData(manipulator_final_position, "")
except Exception as e:
print(f"[ERROR]\t\t Moving manipulator {self._id} to position" f" {position}")
Expand Down
10 changes: 10 additions & 0 deletions src/ephys_link/platforms/ump3_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ async def goto_pos(self, position: list[float], speed: float) -> com.PositionalO

# Return success unless write was disabled during movement (meaning a stop occurred)
if not self._can_write:
com.dprint(f"[ERROR]\t\t Manipulator {self._id} movement canceled")
return com.PositionalOutputData([], "Manipulator movement canceled")

# Return error if movement did not reach target.
if not all(
abs(manipulator_final_position[i] - position[i]) < self._movement_tolerance
for i in range(len(position))
):
com.dprint(f"[ERROR]\t\t Manipulator {self._id} did not reach target position")
return com.PositionalOutputData([], "Manipulator did not reach target position")

# Made it to the target.
com.dprint(f"[SUCCESS]\t Moved manipulator {self._id} to position" f" {manipulator_final_position}\n")
return com.PositionalOutputData(manipulator_final_position, "")
except Exception as e:
Expand Down

0 comments on commit b05bc1e

Please sign in to comment.