Skip to content

Commit

Permalink
266 support pathfinder 4 shank probe (#270)
Browse files Browse the repository at this point in the history
* Add Shank Count event

* change to shank_count

* Search for shank count before registration
  • Loading branch information
kjy5 authored Dec 11, 2023
1 parent 6183ef4 commit d06884b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/ruff.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/ephys_link/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ def __init__(self, angles: list, error: str) -> None:
super(AngularOutputData, self).__init__(angles=angles, error=error)


class ShankCountOutputData(dict):
"""Output format for (num_shanks, error)
:param shank_count: Number of shanks on the probe
:type shank_count: int
:param error: Error message
:type error: str
"""

def __init__(self, shank_count: int, error: str) -> None:
"""Constructor"""
super(ShankCountOutputData, self).__init__(shank_count=shank_count, error=error)


class DriveToDepthOutputData(dict):
"""Output format for depth driving (depth, error)
Expand Down
22 changes: 20 additions & 2 deletions src/ephys_link/platform_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def get_angles(self, manipulator_id: str) -> com.AngularOutputData:
:param manipulator_id: The ID of the manipulator to get the position of.
:type manipulator_id: str
:return: Callback parameters (manipulator ID, angles in (yaw, pitch, roll) (or an
empty array on error) in degrees, error message)
:return: Callback parameters (angles in (yaw, pitch, roll) or an
empty array on error in degrees, error message)
:rtype: :class:`ephys_link.common.AngularOutputData`
"""
try:
Expand All @@ -197,6 +197,15 @@ def get_angles(self, manipulator_id: str) -> com.AngularOutputData:
print(f"[ERROR]\t\t Manipulator not registered: {manipulator_id}")
return com.AngularOutputData([], "Manipulator not registered")

def get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData:
"""Get the number of shanks on the probe
:param manipulator_id: The ID of the manipulator to get the number of shanks of.
:type manipulator_id: str
:return: Callback parameters (number of shanks or -1 on error, error message)
"""
return self._get_shank_count(manipulator_id)

async def goto_pos(
self, manipulator_id: str, position: list[float], speed: int
) -> com.PositionalOutputData:
Expand Down Expand Up @@ -453,6 +462,15 @@ def _get_angles(self, manipulator_id: str) -> com.AngularOutputData:
:rtype: :class:`ephys_link.common.AngularOutputData`
"""

@abstractmethod
def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData:
"""Get the number of shanks on the probe
:param manipulator_id: The ID of the manipulator to get the number of shanks of.
:type manipulator_id: str
:return: Callback parameters (number of shanks or -1 on error, error message)
"""

@abstractmethod
async def _goto_pos(
self, manipulator_id: str, position: list[float], speed: int
Expand Down
3 changes: 3 additions & 0 deletions src/ephys_link/platforms/new_scale_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def _get_pos(self, manipulator_id: str) -> com.PositionalOutputData:
def _get_angles(self, manipulator_id: str) -> com.AngularOutputData:
raise NotImplementedError

def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData:
raise NotImplementedError

async def _goto_pos(
self, manipulator_id: str, position: list[float], speed: int
) -> com.PositionalOutputData:
Expand Down
12 changes: 12 additions & 0 deletions src/ephys_link/platforms/new_scale_pathfinder_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ def _get_angles(self, manipulator_id: str) -> com.AngularOutputData:
"",
)

def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData:
"""Get the number of shanks on the probe
:param manipulator_id: manipulator ID
:return: Callback parameters (number of shanks (or -1 on error), error message)
"""
for probe in self.query_data()["ProbeArray"]:
if probe["Id"] == manipulator_id:
return com.ShankCountOutputData(probe["ShankCount"], "")

return com.ShankCountOutputData(-1, "Unable to find manipulator")

async def _goto_pos(
self, manipulator_id: str, position: list[float], speed: int
) -> com.PositionalOutputData:
Expand Down
3 changes: 3 additions & 0 deletions src/ephys_link/platforms/sensapex_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def _get_pos(self, manipulator_id: str) -> com.PositionalOutputData:
def _get_angles(self, manipulator_id: str) -> com.AngularOutputData:
raise NotImplementedError

def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData:
raise NotImplementedError

async def _goto_pos(
self, manipulator_id: str, position: list[float], speed: int
) -> com.PositionalOutputData:
Expand Down
3 changes: 3 additions & 0 deletions src/ephys_link/platforms/ump3_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def _get_pos(self, manipulator_id: str) -> com.PositionalOutputData:
def _get_angles(self, manipulator_id: str) -> com.AngularOutputData:
raise NotImplementedError

def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData:
raise NotImplementedError

async def _goto_pos(
self, manipulator_id: str, position: list[float], speed: int
) -> com.PositionalOutputData:
Expand Down
16 changes: 16 additions & 0 deletions src/ephys_link/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ async def get_angles(_, manipulator_id: str) -> com.AngularOutputData:
return platform.get_angles(manipulator_id)


@sio.event
async def get_shank_count(_, manipulator_id: str) -> com.ShankCountOutputData:
"""Number of shanks of manipulator request
:param _: Socket session ID (unused)
:type _: str
:param manipulator_id: ID of manipulator to pull number of shanks from
:type manipulator_id: str
:return: Callback parameters (manipulator ID, number of shanks (or -1 on error), error
message)
:rtype: :class:`ephys_link.common.ShankCountOutputData`
"""

return platform.get_shank_count(manipulator_id)


@sio.event
async def goto_pos(
_, data: com.GotoPositionInputDataFormat
Expand Down

0 comments on commit d06884b

Please sign in to comment.