Implemented relative stepper movement.

This commit is contained in:
jupfi 2023-12-08 08:17:44 +01:00
parent 67b21d27b7
commit 487f7ce0c7
3 changed files with 42 additions and 2 deletions

View file

@ -635,5 +635,33 @@ class AutoTMController(ModuleController):
elif stepper == "matching":
self.module.model.active_stepper = self.module.model.matching_stepper
def on_relative_move(self, steps : str) -> None:
"""This method is called when the relative move button is pressed.
Args:
steps (str): The number of steps to move the stepper.
"""
# First char is the stepper identifier, m for matching and t for tuning
motor_identifier = self.module.model.active_stepper.TYPE.lower()[0]
# We check if the steps are valid
stepper_current_position = self.module.model.active_stepper.position
future_position = stepper_current_position + int(steps)
if future_position < 0:
error = "Could not move stepper. Stepper position cannot be negative"
self.module.view.add_info_text(error)
return
if future_position > self.module.model.active_stepper.MAX_STEPS:
error = f"Could not move stepper. Stepper position cannot be larger than {self.module.model.active_stepper.MAX_STEPS}"
self.module.view.add_info_text(error)
return
# We send the command to the atm system, the first m identifies this is a move command
command = f"m{motor_identifier}{steps}"
self.send_command(command)

View file

@ -223,6 +223,14 @@ class Stepper:
self.homed = False
self.position = 0
class TuningStepper(Stepper):
TYPE = "Tuning"
MAX_STEPS = 1e6
class MatchingStepper(Stepper):
TYPE = "Matching"
MAX_STEPS = 1e6
class ElectricalLookupTable(LookupTable):
TYPE = "Electrical"
@ -280,8 +288,8 @@ class AutoTMModel(ModuleModel):
self.calibration = None
self.serial = None
self.tuning_stepper = Stepper()
self.matching_stepper = Stepper()
self.tuning_stepper = TuningStepper()
self.matching_stepper = MatchingStepper()
self.active_stepper = self.tuning_stepper
@property

View file

@ -116,6 +116,10 @@ class AutoTMView(ModuleView):
# Stepper selection
self._ui_form.stepperselectBox.currentIndexChanged.connect(lambda: self.module.controller.on_stepper_changed(self._ui_form.stepperselectBox.currentText()))
self._ui_form.increaseButton.clicked.connect(lambda: self.module.controller.on_relative_move(self._ui_form.stepsizeBox.text()))
self._ui_form.decreaseButton.clicked.connect(lambda: self.module.controller.on_relative_move("-" + self._ui_form.stepsizeBox.text()))
self._ui_form.absoluteGoButton.clicked.connect(lambda: self.module.controller.on_absolute_move(self._ui_form.absoluteposBox.text()))
# Active stepper changed
self.module.model.active_stepper_changed.connect(self.on_active_stepper_changed)