From 736d2e845587f642cd9901d04be8bd414a5989aa Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 27 Jul 2023 13:27:48 -0400 Subject: [PATCH 01/17] Initial commit for setEnergyDialog --- gui/control_main.py | 22 ++++++++++------------ gui/dialog/__init__.py | 1 + gui/dialog/set_energy.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 gui/dialog/set_energy.py diff --git a/gui/control_main.py b/gui/control_main.py index e95a1e2b..dee676f9 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -48,6 +48,7 @@ SnapCommentDialog, StaffScreenDialog, UserScreenDialog, + SetEnergyDialog, ) from gui.raster import RasterCell, RasterGroup from QPeriodicTable import QPeriodicTable @@ -562,7 +563,8 @@ def createSampleTab(self): hBoxColParams3.addWidget(colEnergyLabel) hBoxColParams3.addWidget(self.energyReadback) hBoxColParams3.addWidget(energySPLabel) - hBoxColParams3.addWidget(self.energy_ledit) + # hBoxColParams3.addWidget(self.energy_ledit) + hBoxColParams3.addWidget(moveEnergyButton) hBoxColParams22.addWidget(colTransmissionLabel) hBoxColParams22.addWidget(self.transmissionReadback_ledit) hBoxColParams22.addWidget(transmisionSPLabel) @@ -1411,8 +1413,7 @@ def createSampleTab(self): lambda frame: self.updateCam(self.pixmap_item_HutchTop, frame) ) self.hutchTopCamThread.start() - serverCheckThread = ServerCheckThread( - parent=self, delay=SERVER_CHECK_DELAY) + serverCheckThread = ServerCheckThread(parent=self, delay=SERVER_CHECK_DELAY) serverCheckThread.visit_dir_changed.connect(QApplication.instance().quit) serverCheckThread.start() @@ -1707,18 +1708,12 @@ def saveVidSnapshotCB( if rasterHeatJpeg == None: if reqID != None: filePrefix = db_lib.getRequestByID(reqID)["request_obj"]["file_prefix"] - imagePath = ( - f"{getBlConfig('visitDirectory')}/snapshots/{filePrefix}{int(now)}.jpg" - ) + imagePath = f"{getBlConfig('visitDirectory')}/snapshots/{filePrefix}{int(now)}.jpg" else: if self.dataPathGB.prefix_ledit.text() != "": - imagePath = ( - f"{getBlConfig('visitDirectory')}/snapshots/{self.dataPathGB.prefix_ledit.text()}{int(now)}.jpg" - ) + imagePath = f"{getBlConfig('visitDirectory')}/snapshots/{self.dataPathGB.prefix_ledit.text()}{int(now)}.jpg" else: - imagePath = ( - f"{getBlConfig('visitDirectory')}/snapshots/capture{int(now)}.jpg" - ) + imagePath = f"{getBlConfig('visitDirectory')}/snapshots/capture{int(now)}.jpg" else: imagePath = rasterHeatJpeg logger.info("saving " + imagePath) @@ -2709,6 +2704,7 @@ def moveOmegaCB(self): self.send_to_server(comm_s) def moveEnergyCB(self): + """ energyRequest = float(str(self.energy_ledit.text())) if abs(energyRequest - self.energy_pv.get()) > 10.0: self.popupServerMessage("Energy change must be less than 10 ev") @@ -2717,6 +2713,8 @@ def moveEnergyCB(self): comm_s = 'mvaDescriptor("energy",' + str(self.energy_ledit.text()) + ")" logger.info(comm_s) self.send_to_server(comm_s) + """ + set_energy = SetEnergyDialog(parent=self) def setLifetimeCB(self, lifetime): if hasattr(self, "sampleLifetimeReadback_ledit"): diff --git a/gui/dialog/__init__.py b/gui/dialog/__init__.py index 4a490c57..b50f1daa 100644 --- a/gui/dialog/__init__.py +++ b/gui/dialog/__init__.py @@ -5,3 +5,4 @@ from .puck_dialog import PuckDialog from .dewar import DewarDialog from .screen_defaults import ScreenDefaultsDialog +from .set_energy import SetEnergyDialog diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py new file mode 100644 index 00000000..3209d621 --- /dev/null +++ b/gui/dialog/set_energy.py @@ -0,0 +1,31 @@ +import logging +import typing + +from qtpy import QtCore, QtGui, QtWidgets +from qtpy.QtCore import Qt + +import daq_utils +import db_lib +import setenergy_lsdc + +if typing.TYPE_CHECKING: + from lsdcGui import ControlMain + +logger = logging.getLogger() + + +class SetEnergyDialog(QtWidgets.QDialog): + def __init__(self, parent: "ControlMain"): + super().__init__(parent) + + def initUI(self): + layout = QtWidgets.QGridLayout() + self.current_energy_label = QtWidgets.QLabel("Current Energy: ") + self.current_energy_value = QtWidgets.QLabel("0 eV") + layout.addWidget(self.current_energy_label, 0, 0) + layout.addWidget(self.current_energy_value, 0, 1) + + setenergy_lsdc.hdcm.e.user_readback.subscribe(self.update_energy, run=True) + + def update_energy(self, value): + print(value) From fe8d860af34d51056d75ef323acf730b53a2162d Mon Sep 17 00:00:00 2001 From: vshekar1 Date: Thu, 27 Jul 2023 15:59:11 -0400 Subject: [PATCH 02/17] Added UI components --- gui/dialog/set_energy.py | 80 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py index 3209d621..fcc8cfdb 100644 --- a/gui/dialog/set_energy.py +++ b/gui/dialog/set_energy.py @@ -6,26 +6,98 @@ import daq_utils import db_lib -import setenergy_lsdc +from ophyd import Component as Cpt +from ophyd import Device +from ophyd import EpicsMotor if typing.TYPE_CHECKING: from lsdcGui import ControlMain logger = logging.getLogger() +class DCM(Device): + b = Cpt(EpicsMotor, '-Ax:B}Mtr', labels=['fmx']) + g = Cpt(EpicsMotor, '-Ax:G}Mtr', labels=['fmx']) + p = Cpt(EpicsMotor, '-Ax:P}Mtr', labels=['fmx']) + r = Cpt(EpicsMotor, '-Ax:R}Mtr', labels=['fmx']) + e = Cpt(EpicsMotor, '-Ax:E}Mtr', labels=['fmx']) + + class SetEnergyDialog(QtWidgets.QDialog): def __init__(self, parent: "ControlMain"): + self.hdcm = DCM('XF:17IDA-OP:FMX{Mono:DCM', name='hdcm') super().__init__(parent) + self.initUI() def initUI(self): layout = QtWidgets.QGridLayout() self.current_energy_label = QtWidgets.QLabel("Current Energy: ") - self.current_energy_value = QtWidgets.QLabel("0 eV") + self.current_energy_value_label = QtWidgets.QLabel(f"{self.hdcm.e.user_readback.get()} eV") layout.addWidget(self.current_energy_label, 0, 0) - layout.addWidget(self.current_energy_value, 0, 1) + layout.addWidget(self.current_energy_value_label, 0, 1) + + self.setpoint_label = QtWidgets.QLabel("Energy setpoint: ") + validator = QtGui.QDoubleValidator() + self.setpoint_edit = QtWidgets.QLineEdit() + self.setpoint_edit.setValidator(validator) + self.setpoint_edit.returnPressed.connect(self.check_value) + layout.addWidget(self.setpoint_label, 1, 0) + layout.addWidget(self.setpoint_edit, 1, 1) + + self.message = QtWidgets.QLabel("") + layout.addWidget(self.message, 2, 0, 1, 2) + + self.confirm_button = QtWidgets.QPushButton("Confirm") + self.confirm_button.setAutoDefault(False) + self.confirm_button.setEnabled(False) + self.confirm_button.clicked.connect(self.set_energy) + + self.cancel_button = QtWidgets.QPushButton("Cancel") + self.cancel_button.setEnabled(False) + self.cancel_button.setAutoDefault(False) + self.cancel_button.clicked.connect(self.cancel_set_energy) + + self.close_button = QtWidgets.QPushButton("Close") + self.close_button.clicked.connect(self.close) + self.close_button.setAutoDefault(False) - setenergy_lsdc.hdcm.e.user_readback.subscribe(self.update_energy, run=True) + layout.addWidget(self.confirm_button, 3, 0) + layout.addWidget(self.cancel_button, 3, 1) + layout.addWidget(self.close_button, 4, 0, 1, 2) + + self.hdcm.e.user_readback.subscribe(self.update_energy, run=True) + + self.setLayout(layout) + self.setModal(True) + self.show() def update_energy(self, value): print(value) + + def check_value(self): + if abs(float(self.setpoint_edit.text()) - self.hdcm.e.user_readback.get()) > 10: + # + self.message.setText("Energy change is greater than 10 eV.\nConfirm by clicking button or cancel") + self.confirm_button.setEnabled(True) + self.setpoint_edit.setEnabled(False) + self.cancel_button.setEnabled(True) + + + else: + comm_s = 'mvaDescriptor("energy",' + str(self.energy_ledit.text()) + ")" + print(f"executing {comm_s}") + # self.parent().send_to_server(comm_s) + + def set_energy(self): + import traceback + print("set_energy was called") + traceback.print_stack() + print(r'Executing: self.parent().send_to_server(f"setELsdc({self.setpoint_edit.text()})")') + + def cancel_set_energy(self): + print("Clicked cancel") + self.setpoint_edit.setEnabled(True) + self.confirm_button.setEnabled(False) + self.cancel_button.setEnabled(False) + From aa2501eb2c5c7cb4b1d78de1708b2c1f4dc769ab Mon Sep 17 00:00:00 2001 From: vshekar1 Date: Thu, 27 Jul 2023 17:36:50 -0400 Subject: [PATCH 03/17] Fixes to make UI work at the beamline --- daq_macros.py | 4 ++++ gui/dialog/set_energy.py | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/daq_macros.py b/daq_macros.py index 58be0967..dbccf9b5 100644 --- a/daq_macros.py +++ b/daq_macros.py @@ -38,6 +38,7 @@ import bluesky.plans as bp from bluesky.preprocessors import finalize_wrapper from fmx_annealer import govStatusGet, govStateSet, fmxAnnealer, amxAnnealer # for using annealer specific to FMX and AMX +from setenergy_lsdc import setELsdc try: import ispybLib @@ -85,6 +86,9 @@ def abortBS(): RE.abort() except super_state_machine.errors.TransitionError: logger.error("caught BS") + +def set_energy(energy): + RE(setELsdc(energy)) def changeImageCenterLowMag(x,y,czoom): zoom = int(czoom) diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py index fcc8cfdb..29746f26 100644 --- a/gui/dialog/set_energy.py +++ b/gui/dialog/set_energy.py @@ -25,6 +25,7 @@ class DCM(Device): class SetEnergyDialog(QtWidgets.QDialog): + energy_changed_signal = QtCore.Signal(object) def __init__(self, parent: "ControlMain"): self.hdcm = DCM('XF:17IDA-OP:FMX{Mono:DCM', name='hdcm') super().__init__(parent) @@ -68,12 +69,15 @@ def initUI(self): self.hdcm.e.user_readback.subscribe(self.update_energy, run=True) + self.energy_changed_signal.connect(lambda value: self.current_energy_value_label.setText(f"{value:.2f}")) + self.setLayout(layout) self.setModal(True) self.show() - def update_energy(self, value): - print(value) + def update_energy(self, value, old_value, **kwargs): + self.energy_changed_signal.emit(value) + def check_value(self): if abs(float(self.setpoint_edit.text()) - self.hdcm.e.user_readback.get()) > 10: @@ -85,15 +89,13 @@ def check_value(self): else: - comm_s = 'mvaDescriptor("energy",' + str(self.energy_ledit.text()) + ")" + comm_s = 'mvaDescriptor("energy",' + str(self.setpoint_edit.text()) + ")" print(f"executing {comm_s}") - # self.parent().send_to_server(comm_s) + self.parent().send_to_server(comm_s) def set_energy(self): - import traceback - print("set_energy was called") - traceback.print_stack() - print(r'Executing: self.parent().send_to_server(f"setELsdc({self.setpoint_edit.text()})")') + print('Executing: ') + self.parent().send_to_server(f"set_energy({self.setpoint_edit.text()})") def cancel_set_energy(self): print("Clicked cancel") From 9d369404295c88d8f1f35fffe2f52ca460abddfb Mon Sep 17 00:00:00 2001 From: vshekar1 Date: Thu, 5 Oct 2023 13:51:33 -0400 Subject: [PATCH 04/17] Added buttons --- gui/control_main.py | 6 ++++- gui/dialog/set_energy.py | 47 ++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index dee676f9..3a3c4456 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -2714,7 +2714,11 @@ def moveEnergyCB(self): logger.info(comm_s) self.send_to_server(comm_s) """ - set_energy = SetEnergyDialog(parent=self) + if self.controlEnabled(): + set_energy = SetEnergyDialog(parent=self) + else: + self.popupServerMessage("You don't have control") + def setLifetimeCB(self, lifetime): if hasattr(self, "sampleLifetimeReadback_ledit"): diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py index 29746f26..1bb1252b 100644 --- a/gui/dialog/set_energy.py +++ b/gui/dialog/set_energy.py @@ -49,22 +49,20 @@ def initUI(self): self.message = QtWidgets.QLabel("") layout.addWidget(self.message, 2, 0, 1, 2) - self.confirm_button = QtWidgets.QPushButton("Confirm") - self.confirm_button.setAutoDefault(False) - self.confirm_button.setEnabled(False) - self.confirm_button.clicked.connect(self.set_energy) + self.monochromator_button = QtWidgets.QPushButton("Monochromator") + self.monochromator_button.setAutoDefault(False) + self.monochromator_button.clicked.connect(self.set_monochromator_energy) - self.cancel_button = QtWidgets.QPushButton("Cancel") - self.cancel_button.setEnabled(False) - self.cancel_button.setAutoDefault(False) - self.cancel_button.clicked.connect(self.cancel_set_energy) + self.full_alignment_button = QtWidgets.QPushButton("Full Alignment") + self.full_alignment_button.setAutoDefault(False) + self.full_alignment_button.clicked.connect(self.set_full_alignment_energy) self.close_button = QtWidgets.QPushButton("Close") self.close_button.clicked.connect(self.close) self.close_button.setAutoDefault(False) - layout.addWidget(self.confirm_button, 3, 0) - layout.addWidget(self.cancel_button, 3, 1) + layout.addWidget(self.monochromator_button, 3, 0) + layout.addWidget(self.full_alignment_button, 3, 1) layout.addWidget(self.close_button, 4, 0, 1, 2) self.hdcm.e.user_readback.subscribe(self.update_energy, run=True) @@ -81,25 +79,22 @@ def update_energy(self, value, old_value, **kwargs): def check_value(self): if abs(float(self.setpoint_edit.text()) - self.hdcm.e.user_readback.get()) > 10: - # - self.message.setText("Energy change is greater than 10 eV.\nConfirm by clicking button or cancel") - self.confirm_button.setEnabled(True) - self.setpoint_edit.setEnabled(False) - self.cancel_button.setEnabled(True) - - + self.message.setText("Energy change is greater than 10 eV.\nMonochromator cannot be used for alignment") + self.monochromator_button.setDisabled(True) else: - comm_s = 'mvaDescriptor("energy",' + str(self.setpoint_edit.text()) + ")" - print(f"executing {comm_s}") - self.parent().send_to_server(comm_s) + self.message.setText("Energy change less than 10 eV") + self.monochromator_button.setDisabled(False) + - def set_energy(self): + def set_full_alignment_energy(self): print('Executing: ') self.parent().send_to_server(f"set_energy({self.setpoint_edit.text()})") - def cancel_set_energy(self): - print("Clicked cancel") - self.setpoint_edit.setEnabled(True) - self.confirm_button.setEnabled(False) - self.cancel_button.setEnabled(False) + def set_monochromator_energy(self): + if abs(float(self.setpoint_edit.text()) - self.hdcm.e.user_readback.get()) > 10: + self.message.setText("Energy change is greater than 10 eV.\nMonochromator cannot be used for alignment") + else: + comm_s = 'mvaDescriptor("energy",' + str(self.setpoint_edit.text()) + ")" + print(f"executing {comm_s}") + self.parent().send_to_server(comm_s) From 205b7db4fe2de9d7598c67d1b775960c89e7526f Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 12 Oct 2023 14:36:34 -0400 Subject: [PATCH 05/17] Added Multiple checks: - Set energy button only shown when set in staff panel - Check if BL is in the correct governor state - Check if sample is mounted - Check energy ranges --- config_params.py | 1 + gui/control_main.py | 20 +++++---- gui/dialog/set_energy.py | 83 ++++++++++++++++++++++++++++---------- gui/dialog/staff_screen.py | 23 ++++++++++- 4 files changed, 97 insertions(+), 30 deletions(-) diff --git a/config_params.py b/config_params.py index 5a984c22..287880e3 100644 --- a/config_params.py +++ b/config_params.py @@ -35,6 +35,7 @@ # GUI default configuration BEAM_CHECK = "beamCheck" UNMOUNT_COLD_CHECK = "unmountColdCheck" +SET_ENERGY_CHECK = "setEnergyCheck" # raster request status updates diff --git a/gui/control_main.py b/gui/control_main.py index 3a3c4456..04e11c19 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -17,7 +17,7 @@ from qtpy import QtCore, QtGui, QtWidgets from qtpy.QtCore import QModelIndex, QRectF, Qt, QTimer from qtpy.QtGui import QIntValidator -from qtpy.QtWidgets import QCheckBox, QFrame, QGraphicsPixmapItem, QApplication +from qtpy.QtWidgets import QApplication, QCheckBox, QFrame, QGraphicsPixmapItem import albulaUtils import daq_utils @@ -26,9 +26,10 @@ from config_params import ( CRYOSTREAM_ONLINE, HUTCH_TIMER_DELAY, - SERVER_CHECK_DELAY, RASTER_GUI_XREC_FILL_DELAY, SAMPLE_TIMER_DELAY, + SERVER_CHECK_DELAY, + SET_ENERGY_CHECK, VALID_DET_DIST, VALID_EXP_TIMES, VALID_TOTAL_EXP_TIMES, @@ -45,14 +46,14 @@ PuckDialog, RasterExploreDialog, ScreenDefaultsDialog, + SetEnergyDialog, SnapCommentDialog, StaffScreenDialog, UserScreenDialog, - SetEnergyDialog, ) from gui.raster import RasterCell, RasterGroup from QPeriodicTable import QPeriodicTable -from threads import RaddoseThread, VideoThread, ServerCheckThread +from threads import RaddoseThread, ServerCheckThread, VideoThread logger = logging.getLogger() try: @@ -563,8 +564,14 @@ def createSampleTab(self): hBoxColParams3.addWidget(colEnergyLabel) hBoxColParams3.addWidget(self.energyReadback) hBoxColParams3.addWidget(energySPLabel) - # hBoxColParams3.addWidget(self.energy_ledit) - hBoxColParams3.addWidget(moveEnergyButton) + if daq_utils.beamline == "fmx": + if getBlConfig(SET_ENERGY_CHECK): + hBoxColParams3.addWidget(moveEnergyButton) + else: + hBoxColParams3.addWidget(self.energy_ledit) + else: + hBoxColParams3.addWidget(self.energy_ledit) + hBoxColParams22.addWidget(colTransmissionLabel) hBoxColParams22.addWidget(self.transmissionReadback_ledit) hBoxColParams22.addWidget(transmisionSPLabel) @@ -2718,7 +2725,6 @@ def moveEnergyCB(self): set_energy = SetEnergyDialog(parent=self) else: self.popupServerMessage("You don't have control") - def setLifetimeCB(self, lifetime): if hasattr(self, "sampleLifetimeReadback_ledit"): diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py index 1bb1252b..170599e8 100644 --- a/gui/dialog/set_energy.py +++ b/gui/dialog/set_energy.py @@ -1,45 +1,49 @@ import logging import typing +from ophyd import Component as Cpt +from ophyd import Device, EpicsMotor from qtpy import QtCore, QtGui, QtWidgets from qtpy.QtCore import Qt import daq_utils import db_lib -from ophyd import Component as Cpt -from ophyd import Device -from ophyd import EpicsMotor if typing.TYPE_CHECKING: from lsdcGui import ControlMain logger = logging.getLogger() -class DCM(Device): - b = Cpt(EpicsMotor, '-Ax:B}Mtr', labels=['fmx']) - g = Cpt(EpicsMotor, '-Ax:G}Mtr', labels=['fmx']) - p = Cpt(EpicsMotor, '-Ax:P}Mtr', labels=['fmx']) - r = Cpt(EpicsMotor, '-Ax:R}Mtr', labels=['fmx']) - e = Cpt(EpicsMotor, '-Ax:E}Mtr', labels=['fmx']) +class DCM(Device): + b = Cpt(EpicsMotor, "-Ax:B}Mtr", labels=["fmx"]) + g = Cpt(EpicsMotor, "-Ax:G}Mtr", labels=["fmx"]) + p = Cpt(EpicsMotor, "-Ax:P}Mtr", labels=["fmx"]) + r = Cpt(EpicsMotor, "-Ax:R}Mtr", labels=["fmx"]) + e = Cpt(EpicsMotor, "-Ax:E}Mtr", labels=["fmx"]) class SetEnergyDialog(QtWidgets.QDialog): energy_changed_signal = QtCore.Signal(object) + def __init__(self, parent: "ControlMain"): - self.hdcm = DCM('XF:17IDA-OP:FMX{Mono:DCM', name='hdcm') + self.hdcm = DCM("XF:17IDA-OP:FMX{Mono:DCM", name="hdcm") super().__init__(parent) + self._parent = parent self.initUI() def initUI(self): layout = QtWidgets.QGridLayout() self.current_energy_label = QtWidgets.QLabel("Current Energy: ") - self.current_energy_value_label = QtWidgets.QLabel(f"{self.hdcm.e.user_readback.get()} eV") + self.current_energy_value_label = QtWidgets.QLabel( + f"{self.hdcm.e.user_readback.get()} eV" + ) layout.addWidget(self.current_energy_label, 0, 0) layout.addWidget(self.current_energy_value_label, 0, 1) self.setpoint_label = QtWidgets.QLabel("Energy setpoint: ") validator = QtGui.QDoubleValidator() + validator.setBottom(5.0) self.setpoint_edit = QtWidgets.QLineEdit() self.setpoint_edit.setValidator(validator) self.setpoint_edit.returnPressed.connect(self.check_value) @@ -52,7 +56,7 @@ def initUI(self): self.monochromator_button = QtWidgets.QPushButton("Monochromator") self.monochromator_button.setAutoDefault(False) self.monochromator_button.clicked.connect(self.set_monochromator_energy) - + self.full_alignment_button = QtWidgets.QPushButton("Full Alignment") self.full_alignment_button.setAutoDefault(False) self.full_alignment_button.clicked.connect(self.set_full_alignment_energy) @@ -67,7 +71,9 @@ def initUI(self): self.hdcm.e.user_readback.subscribe(self.update_energy, run=True) - self.energy_changed_signal.connect(lambda value: self.current_energy_value_label.setText(f"{value:.2f}")) + self.energy_changed_signal.connect( + lambda value: self.current_energy_value_label.setText(f"{value:.2f}") + ) self.setLayout(layout) self.setModal(True) @@ -75,26 +81,59 @@ def initUI(self): def update_energy(self, value, old_value, **kwargs): self.energy_changed_signal.emit(value) - - + def check_value(self): if abs(float(self.setpoint_edit.text()) - self.hdcm.e.user_readback.get()) > 10: - self.message.setText("Energy change is greater than 10 eV.\nMonochromator cannot be used for alignment") + self.message.setText( + "Energy change is greater than 10 eV.\nMonochromator cannot be used for alignment" + ) self.monochromator_button.setDisabled(True) else: self.message.setText("Energy change less than 10 eV") self.monochromator_button.setDisabled(False) - + + if float(self.setpoint_edit.text()) <= 10: + self.message.setText( + f"{self.message.text()} \n Beam shape not automatically optimized for energies between 5 keV and 10 keV" + ) + + def unmount_cold_dialog(self): + msg_box = QtWidgets.QMessageBox() + msg_box.setText("A sample is mounted. Unmount cold?") + msg_box.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel) # type: ignore + msg_box.setDefaultButton(QtWidgets.QMessageBox.StandardButton.Ok) + return msg_box def set_full_alignment_energy(self): - print('Executing: ') - self.parent().send_to_server(f"set_energy({self.setpoint_edit.text()})") + if not self._parent.mountedPin_pv.get(): + # If sample is mounted, ask user to unmount cold + response = self.unmount_cold_dialog().exec_() + + if response == QtWidgets.QMessageBox.Ok: + self._parent.send_to_server("unmountCold()") + else: + return + + if self._parent.governorMessage.getEntry() not in [ + "State SE", + "State BA", + "State BL", + "State XF", + "State SA", + ]: + self.message.setText("Governor not in a valid state, call staff!") + return + else: + self._parent.send_to_server("setGovRobot(gov_robot, 'SA')") + + self._parent.send_to_server(f"set_energy({self.setpoint_edit.text()})") def set_monochromator_energy(self): if abs(float(self.setpoint_edit.text()) - self.hdcm.e.user_readback.get()) > 10: - self.message.setText("Energy change is greater than 10 eV.\nMonochromator cannot be used for alignment") + self.message.setText( + "Energy change is greater than 10 eV.\nMonochromator cannot be used for alignment" + ) else: comm_s = 'mvaDescriptor("energy",' + str(self.setpoint_edit.text()) + ")" print(f"executing {comm_s}") - self.parent().send_to_server(comm_s) - + self._parent.send_to_server(comm_s) diff --git a/gui/dialog/staff_screen.py b/gui/dialog/staff_screen.py index 83f41023..be2411e5 100644 --- a/gui/dialog/staff_screen.py +++ b/gui/dialog/staff_screen.py @@ -4,7 +4,12 @@ from qtpy import QtCore, QtWidgets from qtpy.QtWidgets import QCheckBox -from config_params import BEAM_CHECK, TOP_VIEW_CHECK, UNMOUNT_COLD_CHECK +from config_params import ( + BEAM_CHECK, + SET_ENERGY_CHECK, + TOP_VIEW_CHECK, + UNMOUNT_COLD_CHECK, +) from daq_utils import getBlConfig, setBlConfig if typing.TYPE_CHECKING: @@ -64,6 +69,14 @@ def __init__(self, parent: "ControlMain", **kwargs): self.gripperUnmountColdCheckBox.setEnabled(False) self.gripperUnmountColdCheckBox.setChecked(False) + # Set energy checkbox + self.set_energy_checkbox = QCheckBox("Set Energy") + if getBlConfig(SET_ENERGY_CHECK) == 1: + self.set_energy_checkbox.setChecked(True) + else: + self.set_energy_checkbox.setChecked(False) + self.set_energy_checkbox.stateChanged.connect(self.set_energy_check_cb) + self.queueCollectOnCheckBox = QCheckBox("Queue Collect") hBoxColParams1.addWidget(self.queueCollectOnCheckBox) if getBlConfig("queueCollect") == 1: @@ -302,6 +315,14 @@ def beamCheckOnCheckCB(self, state): setBlConfig(BEAM_CHECK, 0) logger.debug(f"{BEAM_CHECK} off") + def set_energy_check_cb(self, state): + if state == QtCore.Qt.Checked: + setBlConfig(SET_ENERGY_CHECK, 1) + logger.debug(f"{SET_ENERGY_CHECK} on") + else: + setBlConfig(SET_ENERGY_CHECK, 0) + logger.debug(f"{SET_ENERGY_CHECK} off") + def unmountColdCheckCB(self, state): if state == QtCore.Qt.Checked: logger.info("unmountColdCheckCB On") From 44dd21b1f7b2cd7b47446665247d24675463d7fb Mon Sep 17 00:00:00 2001 From: vshekar1 Date: Thu, 12 Oct 2023 15:51:03 -0400 Subject: [PATCH 06/17] Fixes to get it working on beamline --- gui/dialog/set_energy.py | 15 ++++++++------- gui/dialog/staff_screen.py | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py index 170599e8..4b44e171 100644 --- a/gui/dialog/set_energy.py +++ b/gui/dialog/set_energy.py @@ -105,7 +105,7 @@ def unmount_cold_dialog(self): return msg_box def set_full_alignment_energy(self): - if not self._parent.mountedPin_pv.get(): + if self._parent.mountedPin_pv.get(): # If sample is mounted, ask user to unmount cold response = self.unmount_cold_dialog().exec_() @@ -114,18 +114,19 @@ def set_full_alignment_energy(self): else: return - if self._parent.governorMessage.getEntry() not in [ - "State SE", - "State BA", - "State BL", - "State XF", - "State SA", + if self._parent.governorMessage.getEntry().text() not in [ + "state SE", + "state BA", + "state BL", + "state XF", + "state SA", ]: self.message.setText("Governor not in a valid state, call staff!") return else: self._parent.send_to_server("setGovRobot(gov_robot, 'SA')") + print("Run set energy") self._parent.send_to_server(f"set_energy({self.setpoint_edit.text()})") def set_monochromator_energy(self): diff --git a/gui/dialog/staff_screen.py b/gui/dialog/staff_screen.py index be2411e5..8064f64c 100644 --- a/gui/dialog/staff_screen.py +++ b/gui/dialog/staff_screen.py @@ -71,12 +71,14 @@ def __init__(self, parent: "ControlMain", **kwargs): # Set energy checkbox self.set_energy_checkbox = QCheckBox("Set Energy") + hBoxColParams1.addWidget(self.set_energy_checkbox) if getBlConfig(SET_ENERGY_CHECK) == 1: self.set_energy_checkbox.setChecked(True) else: self.set_energy_checkbox.setChecked(False) self.set_energy_checkbox.stateChanged.connect(self.set_energy_check_cb) + self.queueCollectOnCheckBox = QCheckBox("Queue Collect") hBoxColParams1.addWidget(self.queueCollectOnCheckBox) if getBlConfig("queueCollect") == 1: From 78ad33f0e0c31a825db514bdff5cf820e49ea02b Mon Sep 17 00:00:00 2001 From: vshekar1 Date: Thu, 26 Oct 2023 10:41:50 -0400 Subject: [PATCH 07/17] Disable GUI when setting energy --- daq_macros.py | 7 ++++++- gui/control_main.py | 5 +++++ gui/dialog/set_energy.py | 7 ++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/daq_macros.py b/daq_macros.py index dbccf9b5..d026b3f9 100644 --- a/daq_macros.py +++ b/daq_macros.py @@ -88,7 +88,12 @@ def abortBS(): logger.error("caught BS") def set_energy(energy): - RE(setELsdc(energy)) + try: + daq_lib.set_field("program_state","Setting Energy") + RE(setELsdc(energy)) + except Exception as e: + logger.error(f"Exception while running set_energy: {e}") + daq_lib.set_field("program_state","Program Ready") def changeImageCenterLowMag(x,y,czoom): zoom = int(czoom) diff --git a/gui/control_main.py b/gui/control_main.py index 04e11c19..03249fd2 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -5173,6 +5173,11 @@ def printServerMessage(self, message_s): print(message_s) def colorProgramState(self, programState_s): + if programState_s == "Setting Energy": + self.setEnabled(False) + else: + self.setEnabled(True) + if programState_s.find("Ready") == -1: self.statusLabel.setColor("yellow") else: diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py index 4b44e171..51ece3ec 100644 --- a/gui/dialog/set_energy.py +++ b/gui/dialog/set_energy.py @@ -43,7 +43,8 @@ def initUI(self): self.setpoint_label = QtWidgets.QLabel("Energy setpoint: ") validator = QtGui.QDoubleValidator() - validator.setBottom(5.0) + validator.setBottom(5000) + validator.setTop(15000) self.setpoint_edit = QtWidgets.QLineEdit() self.setpoint_edit.setValidator(validator) self.setpoint_edit.returnPressed.connect(self.check_value) @@ -92,9 +93,9 @@ def check_value(self): self.message.setText("Energy change less than 10 eV") self.monochromator_button.setDisabled(False) - if float(self.setpoint_edit.text()) <= 10: + if float(self.setpoint_edit.text()) <= 10000: self.message.setText( - f"{self.message.text()} \n Beam shape not automatically optimized for energies between 5 keV and 10 keV" + f"{self.message.text()} \n Beam shape not automatically optimized \nfor energies between 5 keV and 10 keV" ) def unmount_cold_dialog(self): From cf0f2156337d1120670d1a1b6baa06c32f063687 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 7 Mar 2024 11:24:14 -0500 Subject: [PATCH 08/17] Added pitch hold to setE plan --- setenergy_lsdc.py | 70 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/setenergy_lsdc.py b/setenergy_lsdc.py index 70d21127..ffba2a52 100644 --- a/setenergy_lsdc.py +++ b/setenergy_lsdc.py @@ -86,16 +86,21 @@ class DCM(Device): # w = Cpt(EpicsMotor, '-Ax:W}Mtr', labels=['fmx']) class XYPitchMotor(XYMotor): - pitch = Cpt(EpicsMotor, '-Ax:P}Mtr') + pitch = Cpt(EpicsMotor, '-Ax:P}Mtr') + config = Cpt(EpicsSignal, '-PS}:FORMAT') + status_monitor = Cpt(EpicsSignal, "-PS}:UNIT_STATUS_MON.A") + class KBMirror(Device): - hp = Cpt(EpicsMotor, ':KBH-Ax:P}Mtr') - hr = Cpt(EpicsMotor, ':KBH-Ax:R}Mtr') - hx = Cpt(EpicsMotor, ':KBH-Ax:X}Mtr') - hy = Cpt(EpicsMotor, ':KBH-Ax:Y}Mtr') - vp = Cpt(EpicsMotor, ':KBV-Ax:P}Mtr') - vx = Cpt(EpicsMotor, ':KBV-Ax:X}Mtr') - vy = Cpt(EpicsMotor, ':KBV-Ax:Y}Mtr') + hp = Cpt(EpicsMotor, ':KBH-Ax:P}Mtr') + hr = Cpt(EpicsMotor, ':KBH-Ax:R}Mtr') + hx = Cpt(EpicsMotor, ':KBH-Ax:X}Mtr') + hy = Cpt(EpicsMotor, ':KBH-Ax:Y}Mtr') + vp = Cpt(EpicsMotor, ':KBV-Ax:P}Mtr') + vx = Cpt(EpicsMotor, ':KBV-Ax:X}Mtr') + vy = Cpt(EpicsMotor, ':KBV-Ax:Y}Mtr') + config = Cpt(EpicsSignal, ':KB-PS}:FORMAT') + status_monitor = Cpt(EpicsSignal, ":KB-PS}:UNIT_STATUS_MON.A") class Cover(Device): @@ -116,6 +121,20 @@ class GoniometerStack(Device): py = Cpt(EpicsMotor, '-Ax:PY}Mtr', labels=['fmx']) pz = Cpt(EpicsMotor, '-Ax:PZ}Mtr', labels=['fmx']) +class PitchHold(Device): + pitch_control = Cpt(EpicsSignal, "}pitch_control") + mono_scan_freq = Cpt(EpicsSignal, ":mono}pitch-SCAN") + mono_max_tries = Cpt(EpicsSignal, ":mono}pitch-NUM") + mono_deadband = Cpt(EpicsSignal, ":mono}pitch-DB") + mono_target = Cpt(EpicsSignal, ":mono}pitch-SP") # Should be set to hdcm.p + bragg_control = Cpt(EpicsSignal, "}bragg_control") + bpm1_mon = Cpt(EpicsSignal, "}bpm1mon") + set_kb_config = Cpt(EpicsSignal, "}kb_bimorph") + set_hfm_config = Cpt(EpicsSignal, "}hfm_bimorph") + +step_volts = EpicsSignal("XF:17IDA-BI:FMX{Best:1}:TwkCh1.INPA") +pitch_hold = PitchHold("XF:17ID:FMX{Karen", name="pitch_hold") + ## Horizontal Double Crystal Monochromator (FMX) hdcm = DCM('XF:17IDA-OP:FMX{Mono:DCM', name='hdcm') @@ -411,9 +430,21 @@ def setE_motors_FMX(energy): LGP = {m: epics.caget(LGP_fmt.format(m.name)) for m in (kbm.hp, kbm.hx, kbm.vp, kbm.vy)} + label = "highE" # Remove CRLs if going to energy < 9 keV (FMX specific) - if energy < 9001: - set_beamsize('V0','H0') + if energy < 10000: + # set_beamsize('V0','H0') + label = "lowE" + bps.abs_set(hfm.config, f"HFM_{label}") + bps.abs_set(kbm.config, f"KB_{label}") + bps.abs_set(pitch_hold.set_kb_config, 1, wait=True) + bps.abs_set(pitch_hold.set_hfm_config, 1, wait=True) + + while int(kbm.status_monitor.get()) & 2 ** 30 != 1 and int(hfm.status_monitor.get()) & 2 ** 30 != 1: + logger.info("Waiting for ramping to complete... ") + time.sleep(1) + + # Lookup Table def lut(motor): @@ -670,6 +701,8 @@ def setELsdc(energy, slits1XGapOrg = slits1.x_gap.user_readback.get() slits1YGapOrg = slits1.y_gap.user_readback.get() + yield from deactivate_pitch_hold() + print('Setting FMX motor positions') try: yield from setE_motors_FMX(energy) @@ -722,6 +755,8 @@ def setELsdc(energy, yield from bps.mv(slits1.x_gap, slits1XGapOrg) # Move Slit 1 X to original position yield from bps.mv(slits1.y_gap, slits1YGapOrg) # Move Slit 1 Y to original position + yield from activate_pitch_hold() + yield from fmx_reference(transSet=transSet) @@ -1166,6 +1201,21 @@ def fmx_flux_reference(slit1GapList = [2000, 1000, 600, 400], slit1GapDefault = yield from trans_set(transOrgBCU, trans=trans_bcu) +def deactivate_pitch_hold(): + yield from bps.abs_set(pitch_hold.bragg_control, 0, wait=True) + yield from bps.abs_set(pitch_hold.bpm1_mon, 0, wait=True) + +def activate_pitch_hold(): + yield from bps.abs_set(step_volts, 0.01, wait=True) + yield from bps.abs_set(pitch_hold.mono_scan_freq, 1, wait=True) + yield from bps.abs_set(pitch_hold.mono_max_tries, 100, wait=True) + yield from bps.abs_set(pitch_hold.mono_deadband, 0.0003, wait=True) + yield from bps.abs_set(pitch_hold.mono_target, hdcm.p.get(), wait=True) + + # Reactivate bragg control and bpm1mon + yield from bps.abs_set(pitch_hold.bragg_control, 1, wait=True) + yield from bps.abs_set(pitch_hold.bpm1_mon, 1, wait=True) + def fmx_reference(slit1GapDefault = 1000, transSet='All'): """ Calls fmx_flux_reference, then fmx_beamline_reference. From 4633879bf61bd8bbf6e83817ccd10d96f2fa6ba8 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 7 Mar 2024 11:40:49 -0500 Subject: [PATCH 09/17] Moved activate pitch hold before beamalign --- setenergy_lsdc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setenergy_lsdc.py b/setenergy_lsdc.py index ffba2a52..9a141dec 100644 --- a/setenergy_lsdc.py +++ b/setenergy_lsdc.py @@ -739,6 +739,9 @@ def setELsdc(energy, # Activate sector 17 photon local feedback photon_local_feedback_c17.x_enable.put(1) photon_local_feedback_c17.y_enable.put(1) + + # Hold pitch + yield from activate_pitch_hold() # Align LSDC microscope center to beam center if beamCenterAlign: @@ -755,7 +758,7 @@ def setELsdc(energy, yield from bps.mv(slits1.x_gap, slits1XGapOrg) # Move Slit 1 X to original position yield from bps.mv(slits1.y_gap, slits1YGapOrg) # Move Slit 1 Y to original position - yield from activate_pitch_hold() + yield from fmx_reference(transSet=transSet) From 937926d99e756d70a919a77903938d0aa62899c9 Mon Sep 17 00:00:00 2001 From: vshekar1 Date: Thu, 14 Mar 2024 14:10:41 -0400 Subject: [PATCH 10/17] Fixes to complete alignment with ptich hold --- setenergy_lsdc.py | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/setenergy_lsdc.py b/setenergy_lsdc.py index 9a141dec..7be62a00 100644 --- a/setenergy_lsdc.py +++ b/setenergy_lsdc.py @@ -430,19 +430,29 @@ def setE_motors_FMX(energy): LGP = {m: epics.caget(LGP_fmt.format(m.name)) for m in (kbm.hp, kbm.hx, kbm.vp, kbm.vy)} + prev_hfm_config = hfm.config.get() + prev_kb_config = kbm.config.get() + label = "highE" # Remove CRLs if going to energy < 9 keV (FMX specific) if energy < 10000: # set_beamsize('V0','H0') label = "lowE" - bps.abs_set(hfm.config, f"HFM_{label}") - bps.abs_set(kbm.config, f"KB_{label}") - bps.abs_set(pitch_hold.set_kb_config, 1, wait=True) - bps.abs_set(pitch_hold.set_hfm_config, 1, wait=True) + + if prev_hfm_config != f"HFM_{label}": + yield from bps.abs_set(hfm.config, f"HFM_{label}") + yield from bps.abs_set(pitch_hold.set_hfm_config, 1, wait=True) + + if prev_kb_config != f"KB_{label}": + yield from bps.abs_set(kbm.config, f"KB_{label}") + yield from bps.abs_set(pitch_hold.set_kb_config, 1, wait=True) + + logger.info("Waiting for 60 seconds for ramping") + time.sleep(60) - while int(kbm.status_monitor.get()) & 2 ** 30 != 1 and int(hfm.status_monitor.get()) & 2 ** 30 != 1: - logger.info("Waiting for ramping to complete... ") - time.sleep(1) + #while int(kbm.status_monitor.get()) & 2 ** 30 != 1 and int(hfm.status_monitor.get()) & 2 ** 30 != 1: + # logger.info("Waiting for ramping to complete... ") + # time.sleep(1) @@ -736,9 +746,9 @@ def setELsdc(energy, print('ivu_gap_scan() successful') time.sleep(1) - # Activate sector 17 photon local feedback - photon_local_feedback_c17.x_enable.put(1) - photon_local_feedback_c17.y_enable.put(1) + # Activate sector 17 photon local feedback (Legacy) + # photon_local_feedback_c17.x_enable.put(1) + # photon_local_feedback_c17.y_enable.put(1) # Hold pitch yield from activate_pitch_hold() @@ -1207,17 +1217,17 @@ def fmx_flux_reference(slit1GapList = [2000, 1000, 600, 400], slit1GapDefault = def deactivate_pitch_hold(): yield from bps.abs_set(pitch_hold.bragg_control, 0, wait=True) yield from bps.abs_set(pitch_hold.bpm1_mon, 0, wait=True) + yield from bps.abs_set(pitch_hold.pitch_control, 0, wait=True) def activate_pitch_hold(): - yield from bps.abs_set(step_volts, 0.01, wait=True) + yield from bps.abs_set(step_volts, "0.01", wait=True) yield from bps.abs_set(pitch_hold.mono_scan_freq, 1, wait=True) yield from bps.abs_set(pitch_hold.mono_max_tries, 100, wait=True) yield from bps.abs_set(pitch_hold.mono_deadband, 0.0003, wait=True) - yield from bps.abs_set(pitch_hold.mono_target, hdcm.p.get(), wait=True) + yield from bps.abs_set(pitch_hold.mono_target, hdcm.p.user_readback.get(), wait=True) - # Reactivate bragg control and bpm1mon - yield from bps.abs_set(pitch_hold.bragg_control, 1, wait=True) - yield from bps.abs_set(pitch_hold.bpm1_mon, 1, wait=True) + # Reactivate pitch control + yield from bps.abs_set(pitch_hold.pitch_control, 1, wait=True) def fmx_reference(slit1GapDefault = 1000, transSet='All'): """ From 8a69173ab131756eb488c97996a4707802304b74 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Fri, 5 Apr 2024 22:02:05 -0400 Subject: [PATCH 11/17] Clean up of pitch hold --- setenergy_lsdc.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/setenergy_lsdc.py b/setenergy_lsdc.py index 7be62a00..c249a440 100644 --- a/setenergy_lsdc.py +++ b/setenergy_lsdc.py @@ -16,6 +16,7 @@ import socket import time import gov_lib +import daq_lib from start_bs import db, gov_robot, govs import logging @@ -132,6 +133,18 @@ class PitchHold(Device): set_kb_config = Cpt(EpicsSignal, "}kb_bimorph") set_hfm_config = Cpt(EpicsSignal, "}hfm_bimorph") + def save_settings(self): + self.settings = {} + self.settings['pitch_control'] = self.pitch_control.get() + self.settings['bragg_control'] = self.bragg_control.get() + self.settings['bpm1_mon'] = self.bpm1_mon.get() + + def restore_settings(self): + self.pitch_control.put(self.settings['pitch_control']) + self.bragg_control.put(self.settings['bragg_control']) + self.bpm1_mon.put(self.settings['bpm1_mon']) + + step_volts = EpicsSignal("XF:17IDA-BI:FMX{Best:1}:TwkCh1.INPA") pitch_hold = PitchHold("XF:17ID:FMX{Karen", name="pitch_hold") @@ -757,7 +770,8 @@ def setELsdc(energy, if beamCenterAlign: # Check for pre-conditions for beam_center_align() if shutter_hutch_c.status.get(): - print('Experiment hutch shutter closed. Has to be open for this to work. Exiting') + print('Experiment hutch shutter closed. Has to be open for this to work. Stopping') + daq_lib.gui_message(f"Experiment hutch shutter closed. Has to be open for this to work. Stopping") return -1 print('Aligning beam center') @@ -771,6 +785,7 @@ def setELsdc(energy, yield from fmx_reference(transSet=transSet) + daq_lib.gui_message(f"Set energy to {energy} complete") # Alignment =========================================================================================== @@ -1215,6 +1230,7 @@ def fmx_flux_reference(slit1GapList = [2000, 1000, 600, 400], slit1GapDefault = def deactivate_pitch_hold(): + pitch_hold.save_settings() yield from bps.abs_set(pitch_hold.bragg_control, 0, wait=True) yield from bps.abs_set(pitch_hold.bpm1_mon, 0, wait=True) yield from bps.abs_set(pitch_hold.pitch_control, 0, wait=True) @@ -1227,7 +1243,7 @@ def activate_pitch_hold(): yield from bps.abs_set(pitch_hold.mono_target, hdcm.p.user_readback.get(), wait=True) # Reactivate pitch control - yield from bps.abs_set(pitch_hold.pitch_control, 1, wait=True) + pitch_hold.restore_settings() def fmx_reference(slit1GapDefault = 1000, transSet='All'): """ From c8fdb36dc80cf0fa8f07b6b61db3ef92cb666959 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Fri, 5 Apr 2024 22:30:32 -0400 Subject: [PATCH 12/17] Fixes to set energy dialog --- gui/dialog/set_energy.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/gui/dialog/set_energy.py b/gui/dialog/set_energy.py index 51ece3ec..66a5f3c1 100644 --- a/gui/dialog/set_energy.py +++ b/gui/dialog/set_energy.py @@ -36,7 +36,7 @@ def initUI(self): layout = QtWidgets.QGridLayout() self.current_energy_label = QtWidgets.QLabel("Current Energy: ") self.current_energy_value_label = QtWidgets.QLabel( - f"{self.hdcm.e.user_readback.get()} eV" + f"{self.hdcm.e.user_readback.get():.2f} eV" ) layout.addWidget(self.current_energy_label, 0, 0) layout.addWidget(self.current_energy_value_label, 0, 1) @@ -111,7 +111,7 @@ def set_full_alignment_energy(self): response = self.unmount_cold_dialog().exec_() if response == QtWidgets.QMessageBox.Ok: - self._parent.send_to_server("unmountCold()") + self._parent.send_to_server("unmountCold") else: return @@ -125,10 +125,9 @@ def set_full_alignment_energy(self): self.message.setText("Governor not in a valid state, call staff!") return else: - self._parent.send_to_server("setGovRobot(gov_robot, 'SA')") + self._parent.send_to_server("setGovState", ['SA']) - print("Run set energy") - self._parent.send_to_server(f"set_energy({self.setpoint_edit.text()})") + self._parent.send_to_server(f"set_energy", [float(self.setpoint_edit.text())]) def set_monochromator_energy(self): if abs(float(self.setpoint_edit.text()) - self.hdcm.e.user_readback.get()) > 10: @@ -136,6 +135,4 @@ def set_monochromator_energy(self): "Energy change is greater than 10 eV.\nMonochromator cannot be used for alignment" ) else: - comm_s = 'mvaDescriptor("energy",' + str(self.setpoint_edit.text()) + ")" - print(f"executing {comm_s}") - self._parent.send_to_server(comm_s) + self._parent.send_to_server("mvaDescriptor", ["energy", float(self.setpoint_edit.text())]) From 0cbe5cbd0cf9bce64ccb417ab1ad4725861c4d08 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Fri, 5 Apr 2024 22:36:45 -0400 Subject: [PATCH 13/17] Make set energy only available at FMX --- gui/dialog/staff_screen.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/gui/dialog/staff_screen.py b/gui/dialog/staff_screen.py index 214047d9..84f4cda2 100644 --- a/gui/dialog/staff_screen.py +++ b/gui/dialog/staff_screen.py @@ -11,7 +11,7 @@ UNMOUNT_COLD_CHECK, ) from daq_utils import getBlConfig, setBlConfig -import db_lib +import daq_utils if typing.TYPE_CHECKING: from lsdcGui import ControlMain @@ -71,13 +71,14 @@ def __init__(self, parent: "ControlMain", **kwargs): self.gripperUnmountColdCheckBox.setChecked(False) # Set energy checkbox - self.set_energy_checkbox = QCheckBox("Set Energy") - hBoxColParams1.addWidget(self.set_energy_checkbox) - if getBlConfig(SET_ENERGY_CHECK) == 1: - self.set_energy_checkbox.setChecked(True) - else: - self.set_energy_checkbox.setChecked(False) - self.set_energy_checkbox.stateChanged.connect(self.set_energy_check_cb) + if daq_utils.beamline == "fmx": + self.set_energy_checkbox = QCheckBox("Set Energy") + hBoxColParams1.addWidget(self.set_energy_checkbox) + if getBlConfig(SET_ENERGY_CHECK) == 1: + self.set_energy_checkbox.setChecked(True) + else: + self.set_energy_checkbox.setChecked(False) + self.set_energy_checkbox.stateChanged.connect(self.set_energy_check_cb) self.queueCollectOnCheckBox = QCheckBox("Queue Collect") @@ -319,6 +320,10 @@ def set_energy_check_cb(self, state): else: setBlConfig(SET_ENERGY_CHECK, 0) logger.debug(f"{SET_ENERGY_CHECK} off") + msg_box = QtWidgets.QMessageBox() + msg_box.setText("Set Energy state changed, please restart the GUI to access feature") + msg_box.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Ok) # type: ignore + msg_box.setDefaultButton(QtWidgets.QMessageBox.StandardButton.Ok) def unmountColdCheckCB(self, state): if state == QtCore.Qt.Checked: From 2878abc67904a11851f1a4292848a1ab064cfc6a Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 25 Apr 2024 08:58:26 -0400 Subject: [PATCH 14/17] Changed callback name --- gui/control_main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index 5ebdef5e..dbd156fe 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -563,7 +563,7 @@ def createSampleTab(self): ) self.energy_ledit = self.energyMoveLedit.getEntry() self.energy_ledit.setValidator(QtGui.QDoubleValidator()) - self.energy_ledit.returnPressed.connect(self.moveEnergy10eVCB) + self.energy_ledit.returnPressed.connect(self.moveEnergyMaxDeltaCB) moveEnergyButton = QtWidgets.QPushButton("Move Energy") moveEnergyButton.clicked.connect(self.moveEnergyCB) hBoxColParams3.addWidget(colEnergyLabel) @@ -2702,11 +2702,11 @@ def moveOmegaCB(self): {"relative": False} ) - def moveEnergy10eVCB(self): + def moveEnergyMaxDeltaCB(self, max_delta=10.0): energyRequest = float(str(self.energy_ledit.text())) if self.controlEnabled(): - if abs(energyRequest - self.energy_pv.get()) > 10.0: - self.popupServerMessage("Energy change must be less than 10 ev") + if abs(energyRequest - self.energy_pv.get()) > max_delta: + self.popupServerMessage(f"Energy change must be less than or equal to {max_delta:.2f} ev") return else: self.send_to_server("mvaDescriptor", ["energy", float(self.energy_ledit.text())]) From f060df6fe1bb7be3855ca46033fd6bef7c13808e Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 25 Apr 2024 09:03:08 -0400 Subject: [PATCH 15/17] Refactored message --- setenergy_lsdc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setenergy_lsdc.py b/setenergy_lsdc.py index 34c0f995..f458235b 100644 --- a/setenergy_lsdc.py +++ b/setenergy_lsdc.py @@ -770,8 +770,9 @@ def setELsdc(energy, if beamCenterAlign: # Check for pre-conditions for beam_center_align() if shutter_hutch_c.status.get(): - print('Experiment hutch shutter closed. Has to be open for this to work. Stopping') - daq_lib.gui_message(f"Experiment hutch shutter closed. Has to be open for this to work. Stopping") + message = 'Experiment hutch shutter closed. Has to be open for this to work. Stopping' + logging.error(message) + daq_lib.gui_message(message) return -1 print('Aligning beam center') From ed54139fad3cbf7810233461fb937954d1f8e6c1 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 25 Apr 2024 09:04:45 -0400 Subject: [PATCH 16/17] Removed commented out code --- setenergy_lsdc.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/setenergy_lsdc.py b/setenergy_lsdc.py index f458235b..09f5fc13 100644 --- a/setenergy_lsdc.py +++ b/setenergy_lsdc.py @@ -759,9 +759,6 @@ def setELsdc(energy, print('ivu_gap_scan() successful') time.sleep(1) - # Activate sector 17 photon local feedback (Legacy) - # photon_local_feedback_c17.x_enable.put(1) - # photon_local_feedback_c17.y_enable.put(1) # Hold pitch yield from activate_pitch_hold() From 5ffca9cd40b49ed37178e8f2f0d00cc72a85cc1a Mon Sep 17 00:00:00 2001 From: Shekar V Date: Thu, 25 Apr 2024 09:09:51 -0400 Subject: [PATCH 17/17] Added set_energy to whitelist --- daq_main_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daq_main_common.py b/daq_main_common.py index 132a86fc..d303e26d 100755 --- a/daq_main_common.py +++ b/daq_main_common.py @@ -85,7 +85,8 @@ def setGovState(state): unlatchGov, backoffDetector, enableMount, - robotOn + robotOn, + set_energy ] whitelisted_functions: "Dict[str, Callable]" = {