mirror of
https://github.com/nqrduck/nqrduck-autotm.git
synced 2024-11-09 11:40:02 +00:00
Backlash correction for tuner.
This commit is contained in:
parent
5933046d83
commit
850cf9e034
3 changed files with 53 additions and 0 deletions
|
@ -619,6 +619,7 @@ class AutoTMController(ModuleController):
|
||||||
"""
|
"""
|
||||||
logger.debug("Homing")
|
logger.debug("Homing")
|
||||||
self.send_command("h")
|
self.send_command("h")
|
||||||
|
self.module.model.tuning_stepper.last_direction = 1
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def on_stepper_changed(self, stepper: str) -> None:
|
def on_stepper_changed(self, stepper: str) -> None:
|
||||||
|
@ -654,6 +655,18 @@ class AutoTMController(ModuleController):
|
||||||
|
|
||||||
def send_stepper_command(self, steps: int, stepper : Stepper) -> None:
|
def send_stepper_command(self, steps: int, stepper : Stepper) -> None:
|
||||||
"""Send a command to the stepper motor based on the number of steps."""
|
"""Send a command to the stepper motor based on the number of steps."""
|
||||||
|
# Here we handle backlash of the tuner
|
||||||
|
# Determine the direction of the current steps
|
||||||
|
current_direction = np.sign(steps) # This will be -1,or 1
|
||||||
|
if stepper.TYPE == "Tuning":
|
||||||
|
logger.debug("Stepper last direction: %s", stepper.last_direction)
|
||||||
|
logger.debug("Current direction: %s", current_direction)
|
||||||
|
if stepper.last_direction != current_direction:
|
||||||
|
steps = (abs(steps) + stepper.BACKLASH_STEPS) * current_direction
|
||||||
|
|
||||||
|
stepper.last_direction = current_direction
|
||||||
|
logger.debug("Stepper last direction: %s", stepper.last_direction)
|
||||||
|
|
||||||
motor_identifier = stepper.TYPE.lower()[0]
|
motor_identifier = stepper.TYPE.lower()[0]
|
||||||
command = f"m{motor_identifier}{steps}"
|
command = f"m{motor_identifier}{steps}"
|
||||||
confirmation = self.send_command(command)
|
confirmation = self.send_command(command)
|
||||||
|
@ -738,5 +751,22 @@ class AutoTMController(ModuleController):
|
||||||
logger.debug("Deleting position: %s", position)
|
logger.debug("Deleting position: %s", position)
|
||||||
self.module.model.delete_saved_position(position)
|
self.module.model.delete_saved_position(position)
|
||||||
|
|
||||||
|
def generate_mech_lut(self, start_frequency: str, stop_frequency: str, frequency_step: str) -> None:
|
||||||
|
"""Generate a lookup table for the specified frequency range and voltage resolution.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
start_frequency (str): The start frequency in Hz.
|
||||||
|
stop_frequency (str): The stop frequency in Hz.
|
||||||
|
frequency_step (str): The frequency step in Hz.
|
||||||
|
"""
|
||||||
|
logger.debug("Generating mech LUT")
|
||||||
|
|
||||||
|
# We create the lookup table
|
||||||
|
LUT = MechanicalLookupTable(
|
||||||
|
start_frequency, stop_frequency, frequency_step
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -240,6 +240,12 @@ class SavedPosition():
|
||||||
class TuningStepper(Stepper):
|
class TuningStepper(Stepper):
|
||||||
TYPE = "Tuning"
|
TYPE = "Tuning"
|
||||||
MAX_STEPS = 1e6
|
MAX_STEPS = 1e6
|
||||||
|
BACKLASH_STEPS = 45
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__()
|
||||||
|
# Backlash stepper
|
||||||
|
self.last_direction = None
|
||||||
|
|
||||||
class MatchingStepper(Stepper):
|
class MatchingStepper(Stepper):
|
||||||
TYPE = "Matching"
|
TYPE = "Matching"
|
||||||
|
@ -285,6 +291,7 @@ class MechanicalLookupTable(LookupTable):
|
||||||
TYPE = "Mechanical"
|
TYPE = "Mechanical"
|
||||||
pass
|
pass
|
||||||
class AutoTMModel(ModuleModel):
|
class AutoTMModel(ModuleModel):
|
||||||
|
|
||||||
available_devices_changed = pyqtSignal(list)
|
available_devices_changed = pyqtSignal(list)
|
||||||
serial_changed = pyqtSignal(QSerialPort)
|
serial_changed = pyqtSignal(QSerialPort)
|
||||||
data_points_changed = pyqtSignal(list)
|
data_points_changed = pyqtSignal(list)
|
||||||
|
@ -309,6 +316,9 @@ class AutoTMModel(ModuleModel):
|
||||||
|
|
||||||
self.saved_positions = []
|
self.saved_positions = []
|
||||||
|
|
||||||
|
self.el_lut = None
|
||||||
|
self.mech_lut = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available_devices(self):
|
def available_devices(self):
|
||||||
return self._available_devices
|
return self._available_devices
|
||||||
|
|
|
@ -73,6 +73,15 @@ class AutoTMView(ModuleView):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# On clicking of the generateLUTButton call the generate_lut method
|
||||||
|
self._ui_form.generateLUTButton.clicked.connect(
|
||||||
|
lambda: self.module.controller.generate_mech_lut(
|
||||||
|
self._ui_form.startfrequencyBox.text(),
|
||||||
|
self._ui_form.stopfrequencyBox.text(),
|
||||||
|
self._ui_form.frequencystepBox.text(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# On clicking of the viewLUTButton call the view_lut method
|
# On clicking of the viewLUTButton call the view_lut method
|
||||||
self._ui_form.viewelLUTButton.clicked.connect(self.view_el_lut)
|
self._ui_form.viewelLUTButton.clicked.connect(self.view_el_lut)
|
||||||
|
|
||||||
|
@ -351,6 +360,10 @@ class AutoTMView(ModuleView):
|
||||||
def view_el_lut(self) -> None:
|
def view_el_lut(self) -> None:
|
||||||
"""Creates a new Dialog that shows the currently active electrical LUT."""
|
"""Creates a new Dialog that shows the currently active electrical LUT."""
|
||||||
logger.debug("View LUT")
|
logger.debug("View LUT")
|
||||||
|
if self.module.model.el_lut is None:
|
||||||
|
logger.debug("No LUT available")
|
||||||
|
self.add_error_text("No LUT available")
|
||||||
|
return
|
||||||
self.lut_window = self.LutWindow(self.module)
|
self.lut_window = self.LutWindow(self.module)
|
||||||
self.lut_window.show()
|
self.lut_window.show()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue