Change from axis direction set by ints to set by bools. Add a lot more tests.

This commit is contained in:
Julian Stirling 2025-08-01 17:48:04 +01:00
parent 58e3b5dcbd
commit dacf219ea1
4 changed files with 194 additions and 32 deletions

View file

@ -85,9 +85,9 @@ class BaseStage(lt.Thing):
)
"""Whether the stage is in motion."""
axis_direction = lt.ThingSetting(
initial_value={"x": 1, "y": 1, "z": 1},
model=Mapping[str, int],
axis_inverted = lt.ThingSetting(
initial_value={"x": False, "y": False, "z": False},
model=Mapping[str, bool],
readonly=True,
)
"""Used to convert coordinates between the program frame and the hardware frame."""
@ -97,14 +97,14 @@ class BaseStage(lt.Thing):
) -> list[int] | Mapping[str | int]:
if isinstance(position, (list, tuple)):
return [
pos * ax_dir
for pos, ax_dir in zip(position, self.axis_direction.values())
-pos if inverted else pos
for pos, inverted in zip(position, self.axis_inverted.values())
]
if isinstance(position, Mapping):
try:
return {
axis: position[axis] * self.axis_direction[axis]
for axis in position
ax: -position[ax] if self.axis_inverted[ax] else position[ax]
for ax in position
}
except KeyError as e:
raise KeyError(
@ -126,12 +126,12 @@ class BaseStage(lt.Thing):
:param axis: The axis name (x, y or z) to invert.
"""
# Not mutating in place so that setting is saved on change.
direction = self.axis_direction
direction = self.axis_inverted
try:
direction[axis] *= -1
direction[axis] = not direction[axis]
except KeyError as e:
raise KeyError(f"The axis {axis} is not defined.") from e
self.axis_direction = direction
self.axis_inverted = direction
@lt.thing_action
def move_relative(

View file

@ -36,9 +36,9 @@ class DummyStage(BaseStage):
def __exit__(self, _exc_type, _exc_value, _traceback):
"""Nothing to do when the Thing context manager is closed."""
axis_direction = lt.ThingSetting(
initial_value={"x": -1, "y": 1, "z": 1},
model=Mapping[str, int],
axis_inverted = lt.ThingSetting(
initial_value={"x": True, "y": False, "z": False},
model=Mapping[str, bool],
readonly=True,
)
"""Used to convert coordinates between the program frame and the hardware frame."""
@ -51,7 +51,6 @@ class DummyStage(BaseStage):
):
"""Make a relative move. Keyword arguments should be axis names."""
displacement = [kwargs.get(k, 0) for k in self.axis_names]
print(f"d {displacement}")
self.moving = True
try:
fraction_complete = 0.0
@ -80,7 +79,6 @@ class DummyStage(BaseStage):
ax: self._hardware_position[ax] + int(fraction_complete * disp)
for ax, disp in zip(self.axis_names, displacement)
}
print(self._hardware_position)
self.instantaneous_position = self._hardware_position
def _hardware_move_absolute(

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import logging
import threading
import time
from copy import copy
from typing import Iterator, Literal
from contextlib import contextmanager
from collections.abc import Mapping
@ -36,7 +37,7 @@ class SangaboardThing(BaseStage):
Sangaboard class
"""
self.sangaboard_kwargs = kwargs
self.sangaboard_kwargs = copy(kwargs)
self.sangaboard_kwargs["port"] = port
super().__init__(**kwargs)
@ -66,9 +67,9 @@ class SangaboardThing(BaseStage):
with self._sangaboard_lock:
yield self._sangaboard
axis_direction = lt.ThingSetting(
initial_value={"x": -1, "y": 1, "z": -1},
model=Mapping[str, int],
axis_inverted = lt.ThingSetting(
initial_value={"x": True, "y": False, "z": True},
model=Mapping[str, bool],
readonly=True,
)
"""Used to convert coordinates between the program frame and the hardware frame."""