wip(digital_twin)
This commit is contained in:
1 parent
8c28ff248d
commit
7bb9f6300c
4 files changed
+32
-11
No files matched your search
@@ -47,6 +47,8 @@ class MotionWorker:
|
||||
self.on_finished = on_finished
|
||||
self.last_exception: Exception | None = None
|
||||
|
||||
logger.info(f"motion worker init for motor {motor}")
|
||||
|
||||
def _emit_position_changed(self, pos: float):
|
||||
if self.on_position_changed is not None:
|
||||
self.on_position_changed(pos)
|
||||
@@ -65,6 +67,7 @@ class MotionWorker:
|
||||
|
||||
def run(self):
|
||||
"""Prepares the movement based on the axis (motor)"""
|
||||
logger.info(f"Run motor {self.motor}")
|
||||
match self.motor:
|
||||
case (
|
||||
"sldi_gapx"
|
||||
|
||||
@@ -324,9 +324,9 @@ class DigitalTwin(BECWidget, QWidget):
|
||||
self.calc_cm_crit_pitch()
|
||||
self.calc_cm_reflectivity()
|
||||
self.update_fm_mode()
|
||||
self.calc_fm_ideal_pitch()
|
||||
self.calc_fm_reflectivity()
|
||||
self.calc_cm_fm_harm_suppr()
|
||||
self.calc_fm_ideal_pitch()
|
||||
self.calc_mo1_energy_resolution()
|
||||
self.update_mo1_azm_angle()
|
||||
case "energy":
|
||||
@@ -367,9 +367,9 @@ class DigitalTwin(BECWidget, QWidget):
|
||||
self.calc_fm_reflectivity()
|
||||
self.calc_cm_fm_harm_suppr()
|
||||
case "fm_stripe":
|
||||
self.calc_fm_ideal_pitch()
|
||||
self.calc_fm_reflectivity()
|
||||
self.calc_cm_fm_harm_suppr()
|
||||
self.calc_fm_ideal_pitch()
|
||||
case "ot_es1_trz":
|
||||
self.calc_fm_ideal_pitch()
|
||||
case "es1man_trz":
|
||||
@@ -1331,6 +1331,7 @@ class DigitalTwin(BECWidget, QWidget):
|
||||
def _multi_move(self):
|
||||
"""
|
||||
Move the selected motors at the same time (if permitted)."""
|
||||
logger.info("Multi move button pressed")
|
||||
abort = threading.Event() # one failure aborts the not-yet-started motors of this batch
|
||||
for w in self.mover.mover_widgets:
|
||||
if w.checkbox.isChecked():
|
||||
|
||||
@@ -492,6 +492,8 @@ class MoverPanel(QWidget):
|
||||
self.multi_move_info = QLabel(
|
||||
"Not all motors can move together at the same time, digital twin will take care of that."
|
||||
)
|
||||
self.multi_move_info.setFixedWidth(352)
|
||||
self.multi_move_info.setWordWrap(True)
|
||||
self.multi_move_group = Group("Multi Move", [self.multi_move, self.multi_move_info])
|
||||
|
||||
# Assemble complete mover group
|
||||
|
||||
@@ -14,6 +14,7 @@ from qtpy.QtCore import QObject, QPropertyAnimation, Qt
|
||||
from qtpy.QtGui import QTransform
|
||||
from qtpy.QtWidgets import QApplication, QCheckBox, QHBoxLayout, QLabel, QPushButton, QWidget
|
||||
|
||||
from .....bec_ipython_client.plugins.digital_twin_core.digital_twin_core import DigitalTwinCore
|
||||
from .....bec_ipython_client.plugins.digital_twin_core.motion_worker import (
|
||||
MotionOutcome,
|
||||
MotionWorker,
|
||||
@@ -142,7 +143,17 @@ class MoveWidget(QWidget):
|
||||
|
||||
_STATUS_TOOLTIPS = {Status.QUEUED: "Waiting for other motors to finish"}
|
||||
|
||||
def __init__(self, core, beamline, dev, motor, label="", unit=None, decimals=3, deadband=0.0):
|
||||
def __init__(
|
||||
self,
|
||||
core: DigitalTwinCore,
|
||||
beamline,
|
||||
dev,
|
||||
motor,
|
||||
label="",
|
||||
unit=None,
|
||||
decimals=3,
|
||||
deadband=0.0,
|
||||
):
|
||||
super().__init__()
|
||||
self.core = core
|
||||
self._cancel: threading.Event | None = None
|
||||
@@ -169,7 +180,7 @@ class MoveWidget(QWidget):
|
||||
|
||||
# Checkbox
|
||||
self.checkbox = QCheckBox()
|
||||
self.checkbox.setFixedWidth(30)
|
||||
self.checkbox.setFixedWidth(20)
|
||||
self.checkbox.setChecked(True)
|
||||
layout.addWidget(self.checkbox)
|
||||
|
||||
@@ -197,7 +208,7 @@ class MoveWidget(QWidget):
|
||||
# Start / Stop button
|
||||
self.btn_action = QPushButton("Move")
|
||||
self.btn_action.setFixedWidth(64)
|
||||
self.btn_action.setFixedHeight(20)
|
||||
self.btn_action.setFixedHeight(24)
|
||||
self.btn_action.clicked.connect(self._on_button_clicked)
|
||||
layout.addWidget(self.btn_action)
|
||||
self.btn_mode = "start"
|
||||
@@ -292,6 +303,7 @@ class MoveWidget(QWidget):
|
||||
self._set_status(Status.NOT_IN_POSITION)
|
||||
|
||||
def _on_button_clicked(self):
|
||||
logger.info(f"Clicked on button, is busy: {self.is_busy}")
|
||||
if self.is_busy:
|
||||
self._stop_motion()
|
||||
else:
|
||||
@@ -300,15 +312,19 @@ class MoveWidget(QWidget):
|
||||
def start_motion(self, abort: threading.Event | None = None):
|
||||
"""Start a motion. `abort` is shared by a batch (Move Selection) so that one failure
|
||||
prevents the not-yet-started motors of that batch from starting."""
|
||||
logger.info(f"start_motion on motor {self.motor}")
|
||||
if self.is_busy:
|
||||
return
|
||||
if abs(self.target - self.fb) <= self.deadband:
|
||||
logger.info("Within deadband")
|
||||
self._set_status(Status.IN_POSITION)
|
||||
return
|
||||
|
||||
self._apply_button_style("stop")
|
||||
self._cancel = threading.Event()
|
||||
|
||||
logger.info("Prepare stuff")
|
||||
|
||||
signals = _WorkerSignals()
|
||||
signals.waiting.connect(self._on_waiting)
|
||||
signals.started.connect(self._on_started)
|
||||
@@ -332,16 +348,13 @@ class MoveWidget(QWidget):
|
||||
self._thread = threading.Thread(
|
||||
target=self._run, args=(worker, signals, self._cancel, abort), daemon=True
|
||||
)
|
||||
logger.info("Start motion now...")
|
||||
self._thread.start()
|
||||
logger.info("Motion has started")
|
||||
|
||||
def _run(self, worker, signals, cancel, abort):
|
||||
try:
|
||||
outcome = self.core.run_exclusive(...)
|
||||
if outcome == MotionOutcome.FAILED and worker.last_exception is not None:
|
||||
signals.error.emit() # harmless if motion() already emitted it
|
||||
finally:
|
||||
signals.finished.emit()
|
||||
try:
|
||||
logger.info("run_exclusive")
|
||||
self.core.run_exclusive(
|
||||
worker,
|
||||
abort=abort,
|
||||
@@ -350,9 +363,11 @@ class MoveWidget(QWidget):
|
||||
on_started=signals.started.emit,
|
||||
)
|
||||
except Exception:
|
||||
logger.info("Exception")
|
||||
signals.error.emit()
|
||||
raise
|
||||
finally:
|
||||
logger.info("finally 2")
|
||||
signals.finished.emit()
|
||||
|
||||
def _on_waiting(self):
|
||||
|
||||
Reference in new issue
Block a user