From b0b79c924d2ca78f95e7c9c2da4e13a0a0d279cc Mon Sep 17 00:00:00 2001 From: Kenneth Yang <82800265+kjy5@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:28:35 -0700 Subject: [PATCH] Aquarium model renaming (#360) --- pyproject.toml | 2 +- scripts/move_tester.py | 4 ++-- scripts/server_tester.py | 6 +++--- src/ephys_link/back_end/platform_handler.py | 18 ++++++++--------- src/ephys_link/back_end/server.py | 22 ++++++++++----------- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 38894e4..1609354 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dependencies = [ "pythonnet==3.0.3", "requests==2.32.3", "sensapex==1.400.0", - "vbl-aquarium==0.0.18" + "vbl-aquarium==0.0.19" ] [project.urls] diff --git a/scripts/move_tester.py b/scripts/move_tester.py index 1fd720a..2c1ad9f 100644 --- a/scripts/move_tester.py +++ b/scripts/move_tester.py @@ -1,6 +1,6 @@ from asyncio import run -from vbl_aquarium.models.ephys_link import GotoPositionRequest +from vbl_aquarium.models.ephys_link import SetPositionRequest from vbl_aquarium.models.unity import Vector4 from ephys_link.back_end.platform_handler import PlatformHandler @@ -11,5 +11,5 @@ target = Vector4() # target = Vector4(x=10, y=10, z=10, w=10) -print(run(p.set_position(GotoPositionRequest(manipulator_id="6", position=target, speed=5))).to_string()) +print(run(p.set_position(SetPositionRequest(manipulator_id="6", position=target, speed=5))).to_json_string()) print("Done!") diff --git a/scripts/server_tester.py b/scripts/server_tester.py index 2fca50e..44f402b 100644 --- a/scripts/server_tester.py +++ b/scripts/server_tester.py @@ -1,20 +1,20 @@ from time import sleep from socketio import SimpleClient -from vbl_aquarium.models.ephys_link import DriveToDepthRequest, InsideBrainRequest +from vbl_aquarium.models.ephys_link import SetDepthRequest, SetInsideBrainRequest from vbl_aquarium.models.unity import Vector4 with SimpleClient() as sio: sio.connect("http://localhost:3000") - print(sio.call("set_inside_brain", InsideBrainRequest(manipulator_id="6", inside=True).to_string())) + print(sio.call("set_inside_brain", SetInsideBrainRequest(manipulator_id="6", inside=True).to_json_string())) target = Vector4() # target = Vector4(x=10, y=10, z=10, w=10) sio.emit( "set_depth", - DriveToDepthRequest(manipulator_id="6", depth=10, speed=3).to_string(), + SetDepthRequest(manipulator_id="6", depth=10, speed=3).to_json_string(), ) sleep(1) print(sio.call("stop")) diff --git a/src/ephys_link/back_end/platform_handler.py b/src/ephys_link/back_end/platform_handler.py index 766c9a7..a702d0f 100644 --- a/src/ephys_link/back_end/platform_handler.py +++ b/src/ephys_link/back_end/platform_handler.py @@ -12,12 +12,12 @@ from vbl_aquarium.models.ephys_link import ( AngularResponse, BooleanStateResponse, - DriveToDepthRequest, - DriveToDepthResponse, GetManipulatorsResponse, - GotoPositionRequest, - InsideBrainRequest, PositionalResponse, + SetDepthRequest, + SetDepthResponse, + SetInsideBrainRequest, + SetPositionRequest, ShankCountResponse, ) from vbl_aquarium.models.proxy import PinpointIdResponse @@ -173,7 +173,7 @@ async def get_shank_count(self, manipulator_id: str) -> ShankCountResponse: else: return ShankCountResponse(shank_count=shank_count) - async def set_position(self, request: GotoPositionRequest) -> PositionalResponse: + async def set_position(self, request: SetPositionRequest) -> PositionalResponse: """Move a manipulator to a specified translation position in unified coordinates (mm). :param request: Request to move a manipulator to a specified position. @@ -217,7 +217,7 @@ async def set_position(self, request: GotoPositionRequest) -> PositionalResponse else: return PositionalResponse(position=final_unified_position) - async def set_depth(self, request: DriveToDepthRequest) -> DriveToDepthResponse: + async def set_depth(self, request: SetDepthRequest) -> SetDepthResponse: """Move a manipulator's depth translation stage to a specific value (mm). :param request: Request to move a manipulator to a specified depth. @@ -241,11 +241,11 @@ async def set_depth(self, request: DriveToDepthRequest) -> DriveToDepthResponse: final_unified_position = self._bindings.platform_space_to_unified_space(final_platform_position) except Exception as e: self._console.exception_error_print("Set Depth", e) - return DriveToDepthResponse(error=self._console.pretty_exception(e)) + return SetDepthResponse(error=self._console.pretty_exception(e)) else: - return DriveToDepthResponse(depth=final_unified_position.w) + return SetDepthResponse(depth=final_unified_position.w) - async def set_inside_brain(self, request: InsideBrainRequest) -> BooleanStateResponse: + async def set_inside_brain(self, request: SetInsideBrainRequest) -> BooleanStateResponse: """Mark a manipulator as inside the brain or not. This should restrict the manipulator's movement to just the depth axis. diff --git a/src/ephys_link/back_end/server.py b/src/ephys_link/back_end/server.py index ecb254d..4698482 100644 --- a/src/ephys_link/back_end/server.py +++ b/src/ephys_link/back_end/server.py @@ -7,10 +7,10 @@ from pydantic import ValidationError from socketio import AsyncClient, AsyncServer from vbl_aquarium.models.ephys_link import ( - DriveToDepthRequest, EphysLinkOptions, - GotoPositionRequest, - InsideBrainRequest, + SetDepthRequest, + SetInsideBrainRequest, + SetPositionRequest, ) from vbl_aquarium.models.generic import VBLBaseModel @@ -84,7 +84,7 @@ async def _run_if_data_available( """Run a function if data is available.""" request_data = data[1] if request_data: - return str((await function(str(request_data))).to_string()) + return str((await function(str(request_data))).to_json_string()) return self._malformed_request_response(event, request_data) async def _run_if_data_parses( @@ -105,7 +105,7 @@ async def _run_if_data_parses( self._console.exception_error_print(event, e) return self._malformed_request_response(event, request_data) else: - return str((await function(parsed_data)).to_string()) + return str((await function(parsed_data)).to_json_string()) return self._malformed_request_response(event, request_data) # Event Handlers. @@ -165,13 +165,13 @@ async def platform_event_handler(self, event: str, *args: tuple[Any]) -> str: case "get_version": return self._platform_handler.get_version() case "get_pinpoint_id": - return str(self._platform_handler.get_pinpoint_id().to_string()) + return str(self._platform_handler.get_pinpoint_id().to_json_string()) case "get_platform_type": return self._platform_handler.get_platform_type() # Manipulator commands. case "get_manipulators": - return str((await self._platform_handler.get_manipulators()).to_string()) + return str((await self._platform_handler.get_manipulators()).to_json_string()) case "get_position": return await self._run_if_data_available(self._platform_handler.get_position, event, args) case "get_angles": @@ -180,15 +180,13 @@ async def platform_event_handler(self, event: str, *args: tuple[Any]) -> str: return await self._run_if_data_available(self._platform_handler.get_shank_count, event, args) case "set_position": return await self._run_if_data_parses( - self._platform_handler.set_position, GotoPositionRequest, event, args + self._platform_handler.set_position, SetPositionRequest, event, args ) case "set_depth": - return await self._run_if_data_parses( - self._platform_handler.set_depth, DriveToDepthRequest, event, args - ) + return await self._run_if_data_parses(self._platform_handler.set_depth, SetDepthRequest, event, args) case "set_inside_brain": return await self._run_if_data_parses( - self._platform_handler.set_inside_brain, InsideBrainRequest, event, args + self._platform_handler.set_inside_brain, SetInsideBrainRequest, event, args ) case "stop": return await self._platform_handler.stop()