Add a base stage method for update_position, splitting out hardware specifics
This commit is contained in:
parent
e443b1ac5b
commit
6f3cf00b36
3 changed files with 24 additions and 11 deletions
|
|
@ -133,9 +133,16 @@ class BaseStage(lt.Thing):
|
||||||
"""Used to convert coordinates between the program frame and the hardware frame."""
|
"""Used to convert coordinates between the program frame and the hardware frame."""
|
||||||
|
|
||||||
def update_position(self) -> None:
|
def update_position(self) -> None:
|
||||||
"""Read position from the stage and set the corresponding property."""
|
"""Update the position property from the stage."""
|
||||||
|
self._hardware_update_position()
|
||||||
|
|
||||||
|
def _hardware_update_position(self) -> None:
|
||||||
|
"""Read position from the stage and set internal attribute _hardware_position.
|
||||||
|
|
||||||
|
_hardware_position should only be set in this function.
|
||||||
|
"""
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"StageThings must define their own update_position method"
|
"StageThings must define their own _hardware_update_position method"
|
||||||
)
|
)
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,12 @@ class DummyStage(BaseStage):
|
||||||
)
|
)
|
||||||
"""Used to convert coordinates between the program frame and the hardware frame."""
|
"""Used to convert coordinates between the program frame and the hardware frame."""
|
||||||
|
|
||||||
def update_position(self) -> None:
|
def _hardware_update_position(self) -> None:
|
||||||
"""Read position from the stage and set the corresponding property."""
|
"""Read position from the stage and set internal attribute _hardware_position.
|
||||||
pass
|
|
||||||
|
_hardware_position should only be set in this function.
|
||||||
|
"""
|
||||||
|
self._hardware_position = self.instantaneous_position
|
||||||
|
|
||||||
def _set_pos_during_move(
|
def _set_pos_during_move(
|
||||||
self, displacement: Sequence[int], fraction_complete: float
|
self, displacement: Sequence[int], fraction_complete: float
|
||||||
|
|
@ -109,7 +112,7 @@ class DummyStage(BaseStage):
|
||||||
# If there is a new movement.
|
# If there is a new movement.
|
||||||
if movement_request is not None:
|
if movement_request is not None:
|
||||||
# Set the hardware position from instantaneous before continuing.
|
# Set the hardware position from instantaneous before continuing.
|
||||||
self._hardware_position = self.instantaneous_position
|
self.update_position()
|
||||||
|
|
||||||
if movement_request.displacement is None:
|
if movement_request.displacement is None:
|
||||||
# If it is a stop command, stop moving
|
# If it is a stop command, stop moving
|
||||||
|
|
@ -138,7 +141,7 @@ class DummyStage(BaseStage):
|
||||||
# move is complete
|
# move is complete
|
||||||
fraction_complete = 1.0
|
fraction_complete = 1.0
|
||||||
self._set_pos_during_move(displacement, fraction_complete)
|
self._set_pos_during_move(displacement, fraction_complete)
|
||||||
self._hardware_position = self.instantaneous_position
|
self.update_position()
|
||||||
self._movement_ongoing = False
|
self._movement_ongoing = False
|
||||||
|
|
||||||
def _check_for_new_move_request(self) -> Optional[DummyStageMovement]:
|
def _check_for_new_move_request(self) -> Optional[DummyStageMovement]:
|
||||||
|
|
@ -233,5 +236,5 @@ class DummyStage(BaseStage):
|
||||||
stage.
|
stage.
|
||||||
"""
|
"""
|
||||||
with self._hardware_lock:
|
with self._hardware_lock:
|
||||||
self._hardware_position = dict.fromkeys(self.axis_names, 0)
|
self.instantaneous_position = dict.fromkeys(self.axis_names, 0)
|
||||||
self.instantaneous_position = self._hardware_position
|
self.update_position()
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,11 @@ class SangaboardThing(BaseStage):
|
||||||
)
|
)
|
||||||
"""Used to convert coordinates between the program frame and the hardware frame."""
|
"""Used to convert coordinates between the program frame and the hardware frame."""
|
||||||
|
|
||||||
def update_position(self) -> None:
|
def _hardware_update_position(self) -> None:
|
||||||
"""Read position from the stage and set the corresponding property."""
|
"""Read position from the stage and set internal attribute _hardware_position.
|
||||||
|
|
||||||
|
_hardware_position should only be set in this function.
|
||||||
|
"""
|
||||||
with self._hardware_lock:
|
with self._hardware_lock:
|
||||||
self._hardware_position = dict(
|
self._hardware_position = dict(
|
||||||
zip(self.axis_names, self._sangaboard.position, strict=True)
|
zip(self.axis_names, self._sangaboard.position, strict=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue