Remove dependencies from stages
This commit is contained in:
parent
4b845fcf18
commit
426178ba31
3 changed files with 11 additions and 38 deletions
|
|
@ -133,24 +133,15 @@ class BaseStage(lt.Thing):
|
||||||
self.axis_inverted = direction
|
self.axis_inverted = direction
|
||||||
|
|
||||||
@lt.action
|
@lt.action
|
||||||
def move_relative(
|
def move_relative(self, block_cancellation: bool = False, **kwargs: int) -> None:
|
||||||
self,
|
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
|
||||||
**kwargs: int,
|
|
||||||
) -> None:
|
|
||||||
"""Make a relative move. Keyword arguments should be axis names."""
|
"""Make a relative move. Keyword arguments should be axis names."""
|
||||||
self._hardware_move_relative(
|
self._hardware_move_relative(
|
||||||
cancel=cancel,
|
|
||||||
block_cancellation=block_cancellation,
|
block_cancellation=block_cancellation,
|
||||||
**self._apply_axis_direction(kwargs),
|
**self._apply_axis_direction(kwargs),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _hardware_move_relative(
|
def _hardware_move_relative(
|
||||||
self,
|
self, block_cancellation: bool = False, **kwargs: int
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
|
||||||
**kwargs: int,
|
|
||||||
) -> Never:
|
) -> Never:
|
||||||
"""Make a relative move in the coordinate system used by the physical hardware.
|
"""Make a relative move in the coordinate system used by the physical hardware.
|
||||||
|
|
||||||
|
|
@ -161,22 +152,15 @@ class BaseStage(lt.Thing):
|
||||||
)
|
)
|
||||||
|
|
||||||
@lt.action
|
@lt.action
|
||||||
def move_absolute(
|
def move_absolute(self, block_cancellation: bool = False, **kwargs: int) -> None:
|
||||||
self,
|
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
|
||||||
**kwargs: int,
|
|
||||||
) -> None:
|
|
||||||
"""Make an absolute move. Keyword arguments should be axis names."""
|
"""Make an absolute move. Keyword arguments should be axis names."""
|
||||||
self._hardware_move_absolute(
|
self._hardware_move_absolute(
|
||||||
cancel=cancel,
|
|
||||||
block_cancellation=block_cancellation,
|
block_cancellation=block_cancellation,
|
||||||
**self._apply_axis_direction(kwargs),
|
**self._apply_axis_direction(kwargs),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _hardware_move_absolute(
|
def _hardware_move_absolute(
|
||||||
self,
|
self,
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
block_cancellation: bool = False,
|
||||||
**kwargs: int,
|
**kwargs: int,
|
||||||
) -> Never:
|
) -> Never:
|
||||||
|
|
@ -212,20 +196,16 @@ class BaseStage(lt.Thing):
|
||||||
return (position_dict["x"], position_dict["y"], position_dict["z"])
|
return (position_dict["x"], position_dict["y"], position_dict["z"])
|
||||||
|
|
||||||
@lt.action
|
@lt.action
|
||||||
def move_to_xyz_position(
|
def move_to_xyz_position(self, xyz_pos: tuple[int, int, int]) -> None:
|
||||||
self, cancel: lt.deps.CancelHook, xyz_pos: tuple[int, int, int]
|
|
||||||
) -> None:
|
|
||||||
"""Move to the location specified by an (x, y, z) tuple.
|
"""Move to the location specified by an (x, y, z) tuple.
|
||||||
|
|
||||||
:param cancel: A cancel hook for cancelling the move. This dependency should be
|
|
||||||
injected automatically by LabThings-FastAPI
|
|
||||||
:param xyz_pos: The (x, y, z) position to move to.
|
:param xyz_pos: The (x, y, z) position to move to.
|
||||||
|
|
||||||
:raises KeyError: if this stage does not have axes named "x", "y", and "z".
|
:raises KeyError: if this stage does not have axes named "x", "y", and "z".
|
||||||
|
|
||||||
This method provides the interface expected by the camera_stage_mapping.
|
This method provides the interface expected by the camera_stage_mapping.
|
||||||
"""
|
"""
|
||||||
self.move_absolute(cancel=cancel, x=xyz_pos[0], y=xyz_pos[1], z=xyz_pos[2])
|
self.move_absolute(x=xyz_pos[0], y=xyz_pos[1], z=xyz_pos[2])
|
||||||
|
|
||||||
|
|
||||||
StageDependency = lt.deps.direct_thing_client_dependency(BaseStage, "stage")
|
StageDependency = lt.deps.direct_thing_client_dependency(BaseStage, "stage")
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ class DummyStage(BaseStage):
|
||||||
|
|
||||||
def _hardware_move_relative(
|
def _hardware_move_relative(
|
||||||
self,
|
self,
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
block_cancellation: bool = False,
|
||||||
**kwargs: int,
|
**kwargs: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
@ -71,7 +70,7 @@ class DummyStage(BaseStage):
|
||||||
if block_cancellation:
|
if block_cancellation:
|
||||||
time.sleep(dt)
|
time.sleep(dt)
|
||||||
else:
|
else:
|
||||||
cancel.sleep(dt)
|
lt.cancellable_sleep(dt)
|
||||||
fraction_complete = (time.time() - start_time) / (dt * max_displacement)
|
fraction_complete = (time.time() - start_time) / (dt * max_displacement)
|
||||||
self.instantaneous_position = {
|
self.instantaneous_position = {
|
||||||
ax: self._hardware_position[ax] + int(fraction_complete * disp)
|
ax: self._hardware_position[ax] + int(fraction_complete * disp)
|
||||||
|
|
@ -93,7 +92,6 @@ class DummyStage(BaseStage):
|
||||||
|
|
||||||
def _hardware_move_absolute(
|
def _hardware_move_absolute(
|
||||||
self,
|
self,
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
block_cancellation: bool = False,
|
||||||
**kwargs: int,
|
**kwargs: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
@ -104,7 +102,7 @@ class DummyStage(BaseStage):
|
||||||
if axis in self.axis_names
|
if axis in self.axis_names
|
||||||
}
|
}
|
||||||
self._hardware_move_relative(
|
self._hardware_move_relative(
|
||||||
cancel, block_cancellation=block_cancellation, **displacement
|
block_cancellation=block_cancellation, **displacement
|
||||||
)
|
)
|
||||||
|
|
||||||
@lt.action
|
@lt.action
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
|
@ -18,8 +17,6 @@ import sangaboard
|
||||||
|
|
||||||
from . import BaseStage
|
from . import BaseStage
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
REQUIRED_VERSION = semver.Version.parse("1.0.0")
|
REQUIRED_VERSION = semver.Version.parse("1.0.0")
|
||||||
RECOMMENDED_VERSION = semver.Version.parse("1.0.4")
|
RECOMMENDED_VERSION = semver.Version.parse("1.0.4")
|
||||||
|
|
||||||
|
|
@ -117,14 +114,13 @@ class SangaboardThing(BaseStage):
|
||||||
|
|
||||||
# Warn if version is below recommended
|
# Warn if version is below recommended
|
||||||
if version < RECOMMENDED_VERSION:
|
if version < RECOMMENDED_VERSION:
|
||||||
LOGGER.warning(
|
self.logger.warning(
|
||||||
f"Sangaboard firmware version {version} is below the recommended "
|
f"Sangaboard firmware version {version} is below the recommended "
|
||||||
f"{RECOMMENDED_VERSION}."
|
f"{RECOMMENDED_VERSION}."
|
||||||
)
|
)
|
||||||
|
|
||||||
def _hardware_move_relative(
|
def _hardware_move_relative(
|
||||||
self,
|
self,
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
block_cancellation: bool = False,
|
||||||
**kwargs: int,
|
**kwargs: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
@ -138,7 +134,7 @@ class SangaboardThing(BaseStage):
|
||||||
sb.query("notify_on_stop")
|
sb.query("notify_on_stop")
|
||||||
else:
|
else:
|
||||||
while sb.query("moving?") == "true":
|
while sb.query("moving?") == "true":
|
||||||
cancel.sleep(0.1)
|
lt.cancellable_sleep(0.1)
|
||||||
except lt.exceptions.InvocationCancelledError as e:
|
except lt.exceptions.InvocationCancelledError as e:
|
||||||
# If the move has been cancelled, stop it but don't handle the exception.
|
# If the move has been cancelled, stop it but don't handle the exception.
|
||||||
# We need the exception to propagate in order to stop any calling tasks,
|
# We need the exception to propagate in order to stop any calling tasks,
|
||||||
|
|
@ -151,7 +147,6 @@ class SangaboardThing(BaseStage):
|
||||||
|
|
||||||
def _hardware_move_absolute(
|
def _hardware_move_absolute(
|
||||||
self,
|
self,
|
||||||
cancel: lt.deps.CancelHook,
|
|
||||||
block_cancellation: bool = False,
|
block_cancellation: bool = False,
|
||||||
**kwargs: int,
|
**kwargs: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
@ -164,7 +159,7 @@ class SangaboardThing(BaseStage):
|
||||||
if axis in self.axis_names
|
if axis in self.axis_names
|
||||||
}
|
}
|
||||||
self._hardware_move_relative(
|
self._hardware_move_relative(
|
||||||
cancel, block_cancellation=block_cancellation, **displacement
|
block_cancellation=block_cancellation, **displacement
|
||||||
)
|
)
|
||||||
|
|
||||||
@lt.action
|
@lt.action
|
||||||
|
|
@ -203,7 +198,7 @@ class SangaboardThing(BaseStage):
|
||||||
# cannot be used.
|
# cannot be used.
|
||||||
intended_brightness = float(return_value[7:])
|
intended_brightness = float(return_value[7:])
|
||||||
on_brightness = 0.32
|
on_brightness = 0.32
|
||||||
LOGGER.warning(
|
self.logger.warning(
|
||||||
"Brightness control is not yet implemented. Desired brightness: "
|
"Brightness control is not yet implemented. Desired brightness: "
|
||||||
f"{intended_brightness}. Set brightness: {on_brightness}"
|
f"{intended_brightness}. Set brightness: {on_brightness}"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue