From 523a154cd78f9d1c2486403991cf096d7f730fdf Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Wed, 24 May 2023 17:37:51 +0200 Subject: [PATCH] major fixes --- Readme.md | 3 ++ app_config.py | 8 +++- app_utils.py | 4 +- epics_widgets/MotorTweak.py | 22 +++++----- epics_widgets/SimMotorTweak.py | 29 ++++++------- epics_widgets/SmaractMotorTweak.py | 51 +++++++++++------------ swissmx.py | 66 +++++++++++++++++++----------- 7 files changed, 107 insertions(+), 76 deletions(-) diff --git a/Readme.md b/Readme.md index a2c3577..5c34cf9 100644 --- a/Readme.md +++ b/Readme.md @@ -138,6 +138,9 @@ git remote add sf-cristallina gac-cristall@saresc-cons-03:/sf/cristallina/applic git fetch sf-cristallina +# do local changes and commit stuff +git push sf-cristallina + ``` ----------------------------------- SCRATCH ----------------------------------- diff --git a/app_config.py b/app_config.py index b66db10..7d004d1 100644 --- a/app_config.py +++ b/app_config.py @@ -131,7 +131,10 @@ class AppCfg(QSettings): "factor" : 11.33, "geometry" : True, "double_pixel_action" : "mask", - "remove_raw_files" : False + "remove_raw_files" : False, + "save_dap_results" : True, + "make_crystfel_files" : True, + "crystfel_lists_laser" : True, })) if AppCfg.DAQ_LOC not in keys: dflt.append((AppCfg.DAQ_LOC, {'end_station':"cristallina", 'p_group':"p20516"})) @@ -387,6 +390,9 @@ verbose bits: {'name':'geometry', 'value':daq_det['geometry'], 'type':'bool'}, {'name':'double_pixel_action', 'value':daq_det['double_pixel_action'], 'type':'str'}, {'name':'remove_raw_files', 'value':daq_det['remove_raw_files'], 'type':'bool'}, + {'name':'save_dap_results', 'value':daq_det['save_dap_results'], 'type':'bool'}, + {'name':'make_crystfel_files', 'value':daq_det['make_crystfel_files'], 'type':'bool'}, + {'name':'crystfel_lists_laser','value':daq_det['crystfel_lists_laser'],'type':'bool'} ]}, {'name':AppCfg.DAQ_LOC, 'title':'location', 'type':'group', 'children':[ {'name':'end_station', 'value':daq_loc['end_station'], 'type':'str',}, diff --git a/app_utils.py b/app_utils.py index c7d7b3a..f5e4278 100644 --- a/app_utils.py +++ b/app_utils.py @@ -29,13 +29,13 @@ def assert_tweaker_positions(targets, timeout=60.0): summary=[] for i, m in enumerate(targets): mot_tw, target, tolerance=m - name=mot_tw._motor._short_name + label=mot_tw._label notSim=not type(mot_tw).__name__.startswith('Sim') if notSim: pend_event() cur=mot_tw.get_rbv() done=mot_tw.is_done() - s=f"check {name} {cur:.5g} == {target:.5g} [done={done}]" + s=f"check {label} {cur:.5g} == {target:.5g} [done={done}]" _log.debug(s) summary.append(s) if done and tolerance>=abs(cur-target): diff --git a/epics_widgets/MotorTweak.py b/epics_widgets/MotorTweak.py index b5c1348..4bbbf47 100644 --- a/epics_widgets/MotorTweak.py +++ b/epics_widgets/MotorTweak.py @@ -33,22 +33,23 @@ class MotorTweak(QWidget, Ui_MotorTweak): self._locked = False self._label_style = 'basic' self._templates_source = { - 'basic': '{short_name} {{rbv:.{precision}f}} {units}', - 'small': '{short_name} {{rbv:.{precision}f}} {units}', - '2 lines': '{short_name}
{{rbv:.{precision}f}} {units}', - 'busy': '{short_name} {{rbv:.{precision}f}} {units}' + 'basic': '{label} {{rbv:.{precision}f}} {units}', + 'small': '{label} {{rbv:.{precision}f}} {units}', + '2 lines': '{label}
{{rbv:.{precision}f}} {units}', + 'busy': '{label} {{rbv:.{precision}f}} {units}' } self._templates = {} - def connect_motor(self, rec_name, short_name, **kwargs): + def connect_motor(self, rec_name, **kwargs): # TODO: DO NOT USE Motor base class, but reduce to the only really needed PV: s.a. class QopticZoom(object) # TODO: have a own motor Class as class SimMotor: - m = Motor(motor_base) + label=kwargs['label'] + self._label=label + m = Motor(rec_name) m.get_position() self._ignore_limits = m.HLM == m.LLM # if both high/low limits are equal they are meaningless self._motor = m - m._short_name = short_name self._rec_name = rec_name for attr in ['RTYP', 'JVEL', 'HLS', 'LLS', 'TWV', 'RBV', 'VAL', 'LVIO', 'HLM', 'LLM']: @@ -96,6 +97,7 @@ class MotorTweak(QWidget, Ui_MotorTweak): def set_val(self, **kw): v = kw['char_value'] _log.debug('updating VAL = {}'.format(v)) + self._val=float(v) # rewrite in case of tweaking self._drive_val.setText(v) @@ -187,7 +189,7 @@ class MotorTweak(QWidget, Ui_MotorTweak): ''' field = kw['motor_field'] src = kw['source_field'] - kw['alias'] = self.short_name + kw['alias'] = self._label if field != src: return if field == 'VAL': @@ -243,7 +245,7 @@ class MotorTweak(QWidget, Ui_MotorTweak): def contextMenuEvent(self, event): m = self._motor menu = QMenu(self) - menu.setTitle(self.short_name) + menu.setTitle(self._label) lockmotor = QAction('lock motor', menu, checkable=True) lockmotor.setChecked(self._locked) @@ -336,7 +338,7 @@ class MotorTweak(QWidget, Ui_MotorTweak): for k in source: target[k] = source[k].format( - short_name=self.short_name, + label=self._label, precision=m.PREC, units=m.units) try: diff --git a/epics_widgets/SimMotorTweak.py b/epics_widgets/SimMotorTweak.py index 64ed209..c2460d9 100644 --- a/epics_widgets/SimMotorTweak.py +++ b/epics_widgets/SimMotorTweak.py @@ -22,14 +22,13 @@ _log = logging.getLogger(__name__) #logger.setLevel(logging.INFO) class SimMotor: - def __init__(self,rec_name, short_name): + def __init__(self,rec_name): self._llm = -10 self._hlm = 10 self._prec = 5 self._twv = 0.1 self._units = 'mm' self._pos = 3.1415 - self._short_name=short_name self._rec_name=rec_name class SimMotorTweak(QWidget, Ui_MotorTweak): @@ -48,17 +47,19 @@ class SimMotorTweak(QWidget, Ui_MotorTweak): self._locked = False self._label_style = 'basic' self._templates_source = { - 'basic': '{short_name} {{rbv:.{precision}f}} {units}', - 'small': '{short_name} {{rbv:.{precision}f}} {units}', - '2 lines': '{short_name}
{{rbv:.{precision}f}} {units}', - 'busy': '{short_name} {{rbv:.{precision}f}} {units}' + 'basic': '{label} {{rbv:.{precision}f}} {units}', + 'small': '{label} {{rbv:.{precision}f}} {units}', + '2 lines': '{label}
{{rbv:.{precision}f}} {units}', + 'busy': '{label} {{rbv:.{precision}f}} {units}' } self._templates = {} - def connect_motor(self, rec_name, short_name, *args, **kwargs): - self.label.setToolTip('{} => {}'.format(rec_name, short_name)) - self._motor=m=SimMotor(rec_name, short_name) + def connect_motor(self, rec_name, **kwargs): + label=kwargs['label'] + self._label=label + self.label.setToolTip('{} => {}'.format(rec_name, label)) + self._motor=m=SimMotor(rec_name) self.set_motor_validator() self._drive_val.setText(str(m._pos)) self._drive_val.returnPressed.connect(self.move_abs) @@ -107,7 +108,7 @@ class SimMotorTweak(QWidget, Ui_MotorTweak): m._pos += dist if delay: sleep(delay) - _log.debug('{} rel move => {}'.format(m._short_name, dist)) + _log.debug('{} rel move => {} {:5.4g}'.format(self._label, dist,m._pos)) self.update_label() self.emit_signals(source_field='VAL') @@ -149,9 +150,9 @@ class SimMotorTweak(QWidget, Ui_MotorTweak): if assert_position: wait=True if drive is None: - _log.debug('{} abs target from widget'.format(m._short_name)) + _log.debug('{} abs target from widget'.format(self._label)) drive = float(self._drive_val.text()) - _log.debug('{} abs move => {}'.format(m._short_name, drive)) + _log.debug('{} abs move => {}'.format(self._label, drive)) m._pos=drive self.update_label() self.emit_signals(source_field='VAL') @@ -225,7 +226,7 @@ class SimMotorTweak(QWidget, Ui_MotorTweak): prec = self._prec menu = QMenu(self) - menu.setTitle(self.short_name) + menu.setTitle(self._label) lockmotor = QAction('lock motor', menu, checkable=True) lockmotor.setChecked(self._locked) @@ -292,7 +293,7 @@ class SimMotorTweak(QWidget, Ui_MotorTweak): for k in source: target[k] = source[k].format( - short_name=m._short_name, + label=self._label, precision=m._prec, units=m._units) self.label.setText(target[self._label_style].format(rbv=m._pos)) diff --git a/epics_widgets/SmaractMotorTweak.py b/epics_widgets/SmaractMotorTweak.py index 6d37e2e..2ea597a 100644 --- a/epics_widgets/SmaractMotorTweak.py +++ b/epics_widgets/SmaractMotorTweak.py @@ -36,31 +36,33 @@ class SmaractMotorTweak(QWidget, Ui_MotorTweak): self._locked = False self._label_style = 'basic' self._templates_source = { - 'basic': '{short_name} {{rbv:.{precision}f}} {units}', - 'small': '{short_name} {{rbv:.{precision}f}} {units}', - '2 lines': '{short_name}
{{rbv:.{precision}f}} {units}', - 'busy': '{short_name} {{rbv:.{precision}f}} {units}' + 'basic': '{label} {{rbv:.{precision}f}} {units}', + 'small': '{label} {{rbv:.{precision}f}} {units}', + '2 lines': '{label}
{{rbv:.{precision}f}} {units}', + 'busy': '{label} {{rbv:.{precision}f}} {units}' } self._templates = {} - def connect_motor(self, motor_base, short_name=None, *args, **kwargs): + def connect_motor(self, rec_name, **kwargs): # TODO: DO NOT USE so many PVs, but reduce to the only really needed PV: s.a. class QopticZoom(object) - self._pvname = motor_base+':DRIVE' - self._pv_name = PV(motor_base+':NAME') - self._pv_drive = PV(motor_base+':DRIVE') - self._pv_readback = PV(motor_base+':MOTRBV') - self._pv_tweak_r = PV(motor_base+':TWR.PROC') - self._pv_tweak_f = PV(motor_base+':TWF.PROC') - self._pv_tweak_val = PV(motor_base+':TWV') - self._pv_status = PV(motor_base + ':STATUS') - self._pv_home_f = PV(motor_base + ':FRM_FORW.PROC') - self._pv_home_b = PV(motor_base + ':FRM_BACK.PROC') - self._pv_is_homed = PV(motor_base + ':GET_HOMED') - self._pv_llm = PV(motor_base + ':LLM') - self._pv_hlm = PV(motor_base + ':HLM') + label=kwargs['label'] + self._label=label + self._pvname = rec_name+':DRIVE' + self._pv_name = PV(rec_name+':NAME') + self._pv_drive = PV(rec_name+':DRIVE') + self._pv_readback = PV(rec_name+':MOTRBV') + self._pv_tweak_r = PV(rec_name+':TWR.PROC') + self._pv_tweak_f = PV(rec_name+':TWF.PROC') + self._pv_tweak_val = PV(rec_name+':TWV') + self._pv_status = PV(rec_name + ':STATUS') + self._pv_home_f = PV(rec_name + ':FRM_FORW.PROC') + self._pv_home_b = PV(rec_name + ':FRM_BACK.PROC') + self._pv_is_homed = PV(rec_name + ':GET_HOMED') + self._pv_llm = PV(rec_name + ':LLM') + self._pv_hlm = PV(rec_name + ':HLM') - self.label.setToolTip('{} => {}'.format(motor_base, self._pv_name.get())) + self.label.setToolTip('{} => {}'.format(rec_name, self._pv_name.get())) try: self._prec = kwargs['prec'] @@ -73,9 +75,6 @@ class SmaractMotorTweak(QWidget, Ui_MotorTweak): self._units = 'mm' self._ignore_limits = self._pv_llm.get() == self._pv_hlm.get() # if both high/low limits are equal they are meaningless - if not short_name: - short_name = self._pv_name.value - self.short_name = short_name self.set_motor_validator() self._drive_val.setText(self._pv_drive.get(as_string=True)) @@ -169,9 +168,9 @@ class SmaractMotorTweak(QWidget, Ui_MotorTweak): if assert_position: wait=True if drive is None: - logger.debug('{} abs target from widget'.format(self.short_name)) + logger.debug('{} abs target from widget'.format(self._label)) drive = float(self._drive_val.text()) - logger.debug('{} abs move => {}'.format(self.short_name, drive)) + logger.debug('{} abs move => {}'.format(self._label, drive)) self._pv_drive.put(drive) if wait: self.wait() @@ -243,7 +242,7 @@ class SmaractMotorTweak(QWidget, Ui_MotorTweak): prec = self._prec menu = QMenu(self) - menu.setTitle(self.short_name) + menu.setTitle(self._label) lockmotor = QAction('lock motor', menu, checkable=True) lockmotor.setChecked(self._locked) @@ -309,7 +308,7 @@ class SmaractMotorTweak(QWidget, Ui_MotorTweak): for k in source: target[k] = source[k].format( - short_name=self.short_name, + label=self._label, precision=self._prec, units=self._units) self.label.setText(target[self._label_style].format(rbv=self._pv_readback.get())) diff --git a/swissmx.py b/swissmx.py index cb343dc..616bcd0 100755 --- a/swissmx.py +++ b/swissmx.py @@ -88,6 +88,7 @@ import pyqtUsrObj as UsrGO from epics_widgets.MotorTweak import MotorTweak from epics_widgets.SmaractMotorTweak import SmaractMotorTweak from epics_widgets.SimMotorTweak import SimMotorTweak +# from epics import caput, caget # TODO: shutter ts.log('Import part 5/8:') import numpy as np np.set_printoptions(suppress=True,linewidth=196) @@ -811,22 +812,22 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): self.move_post_tube("out") bl.move(pos) - def get_tweaker(self, rec, alias=None, label=None, mtype="epics_motor", layout=None, **kwargs): + def get_tweaker(self, rec, mtype=0, **kwargs): app = QApplication.instance() sim=app._args.sim - if mtype == "epics_motor": + if mtype == 0: # default epics motor record if sim&0x10: - m=SimMotorTweak() + m_tw=SimMotorTweak() else: - m = MotorTweak() - else: + m_tw=MotorTweak() + elif mtype==1: # smaract motor record if sim&0x20: - m=SimMotorTweak() + m_tw=SimMotorTweak() else: - m = SmaractMotorTweak() - m.connect_motor(rec, label, **kwargs) - self.tweakers[alias] = m - return m + m_tw=SmaractMotorTweak() + m_tw.connect_motor(rec, **kwargs) + self.tweakers[kwargs['alias']] = m_tw + return m_tw def build_post_tube_tandem_tweaker(self): block = QWidget() @@ -922,8 +923,8 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): but.clicked.connect(f(v)) c.layout().addWidget(but, 0, i) widgets = [ - self.get_tweaker(f"{pfx}1", alias="colli_x", label="colli X", mtype="smaract_motor",), - self.get_tweaker(f"{pfx}2", alias="colli_y", label="colli Y", mtype="smaract_motor",), + self.get_tweaker(f"{pfx}1", alias="colli_x", label="colli X", mtype=1,), + self.get_tweaker(f"{pfx}2", alias="colli_y", label="colli Y", mtype=1,), c, ] qutilities.add_item_to_toolbox(toolbox,"Collimator",widget_list=widgets) @@ -931,11 +932,11 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): def build_group_posttube(self, toolbox): pfx=QApplication.instance()._cfg.value(AppCfg.GBL_DEV_PREFIX)[1] widgets = [ - self.get_tweaker(f"{pfx}4", alias="tube_usx", label="upstream X", mtype="smaract_motor",), - self.get_tweaker(f"{pfx}6", alias="tube_usy", label="upstream Y", mtype="smaract_motor",), - self.get_tweaker(f"{pfx}5", alias="tube_dsx", label="downstream X", mtype="smaract_motor",), - self.get_tweaker(f"{pfx}7", alias="tube_dsy", label="downstream Y", mtype="smaract_motor",), - self.get_tweaker(f"{pfx}8", alias="tube_z", label="tube Z", mtype="smaract_motor"), + self.get_tweaker(f"{pfx}4", alias="tube_usx", label="upstream X", mtype=1,), + self.get_tweaker(f"{pfx}6", alias="tube_usy", label="upstream Y", mtype=1,), + self.get_tweaker(f"{pfx}5", alias="tube_dsx", label="downstream X", mtype=1,), + self.get_tweaker(f"{pfx}7", alias="tube_dsy", label="downstream Y", mtype=1,), + self.get_tweaker(f"{pfx}8", alias="tube_z", label="tube Z", mtype=1), ] c = QWidget() c.setLayout(QGridLayout()) @@ -962,8 +963,8 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): def build_group_xeye(self, toolbox): pfx=QApplication.instance()._cfg.value(AppCfg.GBL_DEV_PREFIX)[1] widgets=[ - self.get_tweaker(f"{pfx}14", alias="xeye_x", label="X", mtype="smaract_motor"), - self.get_tweaker(f"{pfx}15", alias="xeye_y", label="Y", mtype="smaract_motor"), + self.get_tweaker(f"{pfx}14", alias="xeye_x", label="X", mtype=1), + self.get_tweaker(f"{pfx}15", alias="xeye_y", label="Y", mtype=1), ] qutilities.add_item_to_toolbox(toolbox,"X-Ray Eye",widget_list=widgets) @@ -1539,6 +1540,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): app=QApplication.instance() steps = [ # lambda: sample_selection.tell.set_current(30.0), + lambda:self.move_detector("out"), lambda: self.move_collimator("out"), lambda:self.move_detector("out"), lambda:self.move_post_tube("out"), @@ -2158,6 +2160,16 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) return dlg.setLabelText("Homing and get ready");dlg+=5 sp.homing() # homing if needed + + # TODO: shutter + # open laser shutter + # caput("SLAAR02-LMOT-M262:MOT.VAL", 1) + # time.sleep(4) + + # TODO: shutter + # open fast shutter + #caput("SARES30-LTIM01-EVR0:RearUniv0-Ena-SP", 1) + sp.run() # start motion program sp.wait_armed() # wait until motors are at first position #time.sleep(1.0) # wait armed does not wor yet ?!? @@ -2186,6 +2198,14 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) plt.show(block=False) #plt.show(block=True) + # TODO: shutter + # clos fast shutter + # caput("SARES30-LTIM01-EVR0:RearUniv0-Ena-SP", 0) + + # TODO: shutter + # close laser shutter + # caput("SLAAR02-LMOT-M262:MOT.VAL", 40) + def esc_run_steps(self, steps, title, esc_state): self._esc_state ="busy" with pg.ProgressDialog(title, 0, len(steps)) as dlg: @@ -3034,10 +3054,10 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch) toolbox, "Slits", widget_list=[ - self.get_tweaker(f"{pfx}10", alias="slit_right", label="left", mtype="smaract_motor", ), - self.get_tweaker(f"{pfx}11", alias="slit_left", label="right", mtype="smaract_motor",), - self.get_tweaker(f"{pfx}12", alias="slit_bottom", label="bottom", mtype="smaract_motor",), - self.get_tweaker(f"{pfx}13",alias="slit_top",label="top",mtype="smaract_motor",), + self.get_tweaker(f"{pfx}10", alias="slit_right", label="left", mtype=1, ), + self.get_tweaker(f"{pfx}11", alias="slit_left", label="right", mtype=1,), + self.get_tweaker(f"{pfx}12", alias="slit_bottom", label="bottom", mtype=1,), + self.get_tweaker(f"{pfx}13",alias="slit_top",label="top",mtype=1,), ], )