Skip to content

Commit

Permalink
Fixed platform comments, use subclassing for uMp3-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kjy5 committed Dec 15, 2023
1 parent c8c0de8 commit 75eeb5b
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 318 deletions.
74 changes: 37 additions & 37 deletions src/ephys_link/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


def dprint(message: str) -> None:
"""Print message if debug is enabled
"""Print message if debug is enabled.
:param message: Message to print
:param message: Message to print.
:type message: str
:return: None
"""
Expand All @@ -26,13 +26,13 @@ def dprint(message: str) -> None:

# Input data formats
class GotoPositionInputDataFormat(TypedDict):
"""Data format for positional requests
"""Data format for positional requests.
:param manipulator_id: ID of the manipulator to move
:param manipulator_id: ID of the manipulator to move.
:type manipulator_id: str
:param pos: Position to move to in mm (X, Y, Z, W)
:param pos: Position to move to in mm (X, Y, Z, W).
:type pos: list[float]
:param speed: Speed to move at in mm/s
:param speed: Speed to move at in mm/s.
:type speed: float
"""

Expand All @@ -42,11 +42,11 @@ class GotoPositionInputDataFormat(TypedDict):


class InsideBrainInputDataFormat(TypedDict):
"""Data format for setting inside brain state
"""Data format for setting inside brain state.
:param manipulator_id: ID of the manipulator to move
:param manipulator_id: ID of the manipulator to move.
:type manipulator_id: str
:param inside: Whether the manipulator is inside the brain
:param inside: Whether the manipulator is inside the brain.
:type inside: bool
"""

Expand All @@ -55,13 +55,13 @@ class InsideBrainInputDataFormat(TypedDict):


class DriveToDepthInputDataFormat(TypedDict):
"""Data format for depth driving requests
"""Data format for depth driving requests.
:param manipulator_id: ID of the manipulator to move
:param manipulator_id: ID of the manipulator to move.
:type manipulator_id: str
:param depth: Depth to drive to in mm
:param depth: Depth to drive to in mm.
:type depth: float
:param speed: Speed to drive at in mm/s
:param speed: Speed to drive at in mm/s.
:type speed: float
"""

Expand All @@ -71,13 +71,13 @@ class DriveToDepthInputDataFormat(TypedDict):


class CanWriteInputDataFormat(TypedDict):
"""Data format for setting can write state
"""Data format for setting can write state.
:param manipulator_id: ID of the manipulator to move
:param manipulator_id: ID of the manipulator to move.
:type manipulator_id: str
:param can_write: Whether the manipulator can write
:param can_write: Whether the manipulator can write.
:type can_write: bool
:param hours: Number of hours the manipulator can write for
:param hours: Number of hours the manipulator can write for.
:type hours: float
"""

Expand All @@ -88,15 +88,15 @@ class CanWriteInputDataFormat(TypedDict):

# Output data dictionaries
class GetManipulatorsOutputData(dict):
"""Output format for (manipulators)
"""Output format for get manipulators request.
:param manipulators: List of manipulator IDs (as strings)
:param manipulators: List of manipulator IDs (as strings).
:type manipulators: list
:param num_axes: Number of axes this manipulator has
:param num_axes: Number of axes this manipulator has.
:type num_axes: int
:param dimensions: Size of the movement space in mm (first 3 axes)
:param dimensions: Size of the movement space in mm (first 3 axes).
:type dimensions: list
:param error: Error message
:param error: Error message.
:type error: str
:example: Example generated dictionary
Expand All @@ -118,11 +118,11 @@ def json(self) -> str:


class PositionalOutputData(dict):
"""Output format for (position, error)
"""Output format for positional requests.
:param position: Position in mm (as a list, can be empty) in X, Y, Z, W order
:param position: Position in mm (as a list, empty on error) in X, Y, Z, W order.
:type position: list
:param error: Error message
:param error: Error message.
:type error: str
:example: Example generated dictionary
Expand All @@ -139,11 +139,11 @@ def json(self) -> str:


class AngularOutputData(dict):
"""Output format for (angles, error)
"""Output format for manipulator angle requests.
:param angles: Angles in degrees (as a list, can be empty) in yaw, pitch, roll order
:param angles: Angles in degrees (as a list, can be empty) in yaw, pitch, roll order.
:type angles: list
:param error: Error message
:param error: Error message.
:type error: str
"""

Expand All @@ -157,11 +157,11 @@ def json(self) -> str:


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

Expand All @@ -175,11 +175,11 @@ def json(self) -> str:


class DriveToDepthOutputData(dict):
"""Output format for depth driving (depth, error)
"""Output format for depth driving.
:param depth: Depth in mm
:param depth: Depth in mm (0 on error).
:type depth: float
:param error: Error message
:param error: Error message.
:type error: str
:example: Example generated dictionary :code:`{"depth": 1.23, "error": ""}`
Expand All @@ -195,11 +195,11 @@ def json(self) -> str:


class StateOutputData(dict):
"""Output format for (state, error)
"""Output format for boolean state requests.
:param state: State of the event
:param state: State of the event.
:type state: bool
:param error: Error message
:param error: Error message.
:type error: str
:example: Example generated dictionary :code:`{"state": True, "error": ""}`
Expand Down
54 changes: 26 additions & 28 deletions src/ephys_link/platforms/new_scale_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ def query_all_axes(self):
axis.QueryPosStatus()

def get_pos(self) -> com.PositionalOutputData:
"""Get the current position of the manipulator and convert it into mm
"""Get the current position of the manipulator and convert it into mm.
:return: Callback parameters (position in (x, y, z, 0) (or an empty array on
error) in mm, error message)
:return: Position of manipulator in (x, y, z, z) in mm (or an empty array on error) and error message (if any).
:rtype: :class:`ephys_link.common.PositionalOutputData`
"""
self.query_all_axes()
Expand All @@ -89,14 +88,14 @@ def get_pos(self) -> com.PositionalOutputData:
return com.PositionalOutputData([], "Error getting position")

async def goto_pos(self, position: list[float], speed: float) -> com.PositionalOutputData:
"""Move manipulator to position
"""Move manipulator to position.
:param position: The position to move to in mm
:param position: The position to move to in mm.
:type position: list[float]
:param speed: The speed to move at (in mm/s)
:param speed: The speed to move at (in mm/s).
:type speed: float
:return: Callback parameters (position in (x, y, z, w) (or an empty array on
error), error message)
:return: Resulting position of manipulator in (x, y, z, z) in mm (or an empty array on error)
and error message (if any).
:rtype: :class:`ephys_link.common.PositionalOutputData`
"""
# Check if able to write
Expand Down Expand Up @@ -159,14 +158,14 @@ async def goto_pos(self, position: list[float], speed: float) -> com.PositionalO
print(f"{e}\n")
return com.PositionalOutputData([], "Error moving manipulator")

async def drive_to_depth(self, depth: float, speed: int) -> com.DriveToDepthOutputData:
"""Drive the manipulator to a certain depth
async def drive_to_depth(self, depth: float, speed: float) -> com.DriveToDepthOutputData:
"""Drive the manipulator to a certain depth.
:param depth: The depth to drive to in mm
:param depth: The depth to drive to in mm.
:type depth: float
:param speed: The speed to drive at in mm/s
:type speed: int
:return: Callback parameters (depth (or 0 on error), error message)
:param speed: The speed to drive at in mm/s.
:type speed: float
:return: Resulting depth of manipulator in mm (or 0 on error) and error message (if any).
:rtype: :class:`ephys_link.common.DriveToDepthOutputData`
"""
# Check if able to write
Expand Down Expand Up @@ -220,7 +219,7 @@ async def drive_to_depth(self, depth: float, speed: int) -> com.DriveToDepthOutp
return com.DriveToDepthOutputData(0, "Error driving " "manipulator")

def calibrate(self) -> bool:
"""Calibrate the manipulator
"""Calibrate the manipulator.
:return: None
"""
Expand All @@ -229,7 +228,7 @@ def calibrate(self) -> bool:
def get_calibrated(self) -> bool:
"""Return the calibration state of the manipulator.
:return: True if the manipulator is calibrated, False otherwise
:return: True if the manipulator is calibrated, False otherwise.
:rtype: bool
"""
return self._calibrated
Expand All @@ -242,14 +241,13 @@ def set_calibrated(self) -> None:
self._calibrated = True

def set_can_write(self, can_write: bool, hours: float, sio: socketio.AsyncServer) -> None:
"""Set if the manipulator can move
"""Set if the manipulator can move.
:param can_write: True if the manipulator can move, False otherwise
:param can_write: True if the manipulator can move, False otherwise.
:type can_write: bool
:param hours: The number of hours to allow the manipulator to move (0 =
forever)
:param hours: The number of hours to allow the manipulator to move (0 = forever).
:type hours: float
:param sio: SocketIO object from server to emit reset event
:param sio: SocketIO object from server to emit reset event.
:type sio: :class:`socketio.AsyncServer`
:return: None
"""
Expand All @@ -262,34 +260,34 @@ def set_can_write(self, can_write: bool, hours: float, sio: socketio.AsyncServer
self._reset_timer.start()

def get_can_write(self) -> bool:
"""Return if the manipulator can move
"""Return if the manipulator can move.
:return: True if the manipulator can move, False otherwise
:return: True if the manipulator can move, False otherwise.
:rtype: bool
"""
return self._can_write

def reset_can_write(self, sio: socketio.AsyncServer) -> None:
"""Reset the :attr:`can_write` flag
"""Reset the :attr:`can_write` flag.
:param sio: SocketIO object from server to emit reset event
:param sio: SocketIO object from server to emit reset event.
:type sio: :class:`socketio.AsyncServer`
:return: None
"""
self._can_write = False
asyncio.run(sio.emit("write_disabled", self._id))

def set_inside_brain(self, inside: bool) -> None:
"""Set if the manipulator is inside the brain
"""Set if the manipulator is inside the brain.
:param inside: True if the manipulator is inside the brain, False otherwise
:param inside: True if the manipulator is inside the brain, False otherwise.
:type inside: bool
:return: None
"""
self._inside_brain = inside

def stop(self) -> None:
"""Stop all axes on manipulator
"""Stop all axes on manipulator.
:returns None
"""
Expand Down
Loading

0 comments on commit 75eeb5b

Please sign in to comment.