Skip to content

Commit

Permalink
365 stop individual manipulators (#366)
Browse files Browse the repository at this point in the history
* Add stop and stop all commands

* Define server event
  • Loading branch information
kjy5 authored Jul 9, 2024
1 parent 1d3f3a4 commit a30c4fa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
21 changes: 19 additions & 2 deletions src/ephys_link/back_end/platform_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,31 @@ async def set_inside_brain(self, request: SetInsideBrainRequest) -> BooleanState
else:
return BooleanStateResponse(state=request.inside)

async def stop(self) -> str:
async def stop(self, manipulator_id: str) -> str:
"""Stop a manipulator.
:param manipulator_id: Manipulator ID.
:type manipulator_id: str
:returns: Error message if any.
:rtype: str
"""
try:
await self._bindings.stop(manipulator_id)
except Exception as e:
self._console.exception_error_print("Stop", e)
return self._console.pretty_exception(e)
else:
return ""

async def stop_all(self) -> str:
"""Stop all manipulators.
:returns: Error message if any.
:rtype: str
"""
try:
await self._bindings.stop()
for manipulator_id in await self._bindings.get_manipulators():
await self._bindings.stop(manipulator_id)
except Exception as e:
self._console.exception_error_print("Stop", e)
return self._console.pretty_exception(e)
Expand Down
7 changes: 6 additions & 1 deletion src/ephys_link/back_end/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ async def platform_event_handler(self, event: str, *args: tuple[Any]) -> str:
self._platform_handler.set_inside_brain, SetInsideBrainRequest, event, args
)
case "stop":
return await self._platform_handler.stop()
request_data = args[1]
if request_data:
return await self._platform_handler.stop(str(request_data))
return self._malformed_request_response(event, request_data)
case "stop_all":
return await self._platform_handler.stop_all()
case _:
self._console.error_print(f"Unknown event: {event}.")
return dumps({"error": "Unknown event."})
2 changes: 1 addition & 1 deletion src/ephys_link/bindings/fake_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def set_position(self, manipulator_id: str, position: Vector4, _: float) -
self._positions[int(manipulator_id)] = position
return position

async def stop(self) -> None:
async def stop(self, _: str) -> None:
pass

def platform_space_to_unified_space(self, platform_space: Vector4) -> Vector4:
Expand Down
5 changes: 2 additions & 3 deletions src/ephys_link/bindings/ump_4_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ async def set_position(self, manipulator_id: str, position: Vector4, speed: floa

return um_to_mm(array_to_vector4(movement.last_pos))

async def stop(self) -> None:
for device_ids in await self.get_manipulators():
self._get_device(device_ids).stop()
async def stop(self, manipulator_id: str) -> None:
self._get_device(manipulator_id).stop()

def platform_space_to_unified_space(self, platform_space: Vector4) -> Vector4:
# unified <- platform
Expand Down
4 changes: 2 additions & 2 deletions src/ephys_link/util/base_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ async def set_position(self, manipulator_id: str, position: Vector4, speed: floa
"""

@abstractmethod
async def stop(self) -> None:
"""Stop all manipulators."""
async def stop(self, manipulator_id: str) -> None:
"""Stop a manipulator."""

@abstractmethod
def platform_space_to_unified_space(self, platform_space: Vector4) -> Vector4:
Expand Down

0 comments on commit a30c4fa

Please sign in to comment.