Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aquarium model renaming #360

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions scripts/move_tester.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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!")
6 changes: 3 additions & 3 deletions scripts/server_tester.py
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
18 changes: 9 additions & 9 deletions src/ephys_link/back_end/platform_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
22 changes: 10 additions & 12 deletions src/ephys_link/back_end/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -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":
Expand All @@ -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()
Expand Down