app config, tweakers, move_* functions

This commit is contained in:
2022-09-07 18:16:59 +02:00
parent 18a7b2abb4
commit 1d26a309e7
3 changed files with 239 additions and 200 deletions

View File

@@ -891,25 +891,25 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
icon = qtawesome.icon("material.arrow_back")
but = QPushButton(icon, "")
but.clicked.connect(lambda m, dir="x-pos": self.move_post_tube(dir))
but.clicked.connect(lambda m, pos="x+": self.move_post_tube(pos))
glay.addWidget(but, 1, 0)
# c.setLayout(glay)
icon = qtawesome.icon("material.arrow_forward")
but = QPushButton(icon, "")
but.clicked.connect(lambda m, dir="x-neg": self.move_post_tube(dir))
but.clicked.connect(lambda m, pos="x-": self.move_post_tube(pos))
glay.addWidget(but, 1, 1)
# c.setLayout(glay)
icon = qtawesome.icon("material.arrow_downward")
but = QPushButton(icon, "")
but.clicked.connect(lambda m, dir="down": self.move_post_tube(dir))
but.clicked.connect(lambda m, pos="y-": self.move_post_tube(pos))
glay.addWidget(but, 2, 0)
# c.setLayout(glay)
icon = qtawesome.icon("material.arrow_upward")
but = QPushButton(icon, "")
but.clicked.connect(lambda m, dir="up": self.move_post_tube(dir))
but.clicked.connect(lambda m, pos="y+": self.move_post_tube(pos))
glay.addWidget(but, 2, 1)
block.layout().addWidget(c)
@@ -937,26 +937,40 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
def build_group_faststage(self, toolbox):
pfx=QApplication.instance()._cfg.value(AppCfg.GBL_DEV_PREFIX)[0]
qutilities.add_item_to_toolbox(toolbox,"Fast Stage",
widget_list=[
#self.get_tweaker('f"{pfx}:MOT_BLGT', alias='backlight', label='backlight'),
self.get_tweaker(f"{pfx}:MOT_FY", alias="fast_y", label="fast Y"),
self.get_tweaker(f"{pfx}:MOT_FX", alias="fast_x", label="fast X"),
self.get_tweaker(f"{pfx}:MOT_ROT_Y",alias="omega",label="omega",tweak_min=0.001,tweak_max=180.0,),
self.get_tweaker(f"{pfx}:MOT_CX", alias="base_x", label="base X"),
self.get_tweaker(f"{pfx}:MOT_CZ", alias="base_z", label="base Z"),
self.get_tweaker(f"{pfx}:MOT_DET_Z", alias="det_z", label="detector Z"),
],
)
c=QWidget()
c.setLayout(QGridLayout())
f=lambda v: lambda x:self.move_detector(v) #needs nested lambda to work ...
for i,v in enumerate(('in','out')):
but=QPushButton('detector '+v)
but.clicked.connect(f(v))
c.layout().addWidget(but, 0, i)
widgets=[
# self.get_tweaker('f"{pfx}:MOT_BLGT', alias='backlight', label='backlight'),
self.get_tweaker(f"{pfx}:MOT_FY", alias="fast_y", label="fast Y"),
self.get_tweaker(f"{pfx}:MOT_FX", alias="fast_x", label="fast X"),
self.get_tweaker(f"{pfx}:MOT_ROT_Y", alias="omega", label="omega", tweak_min=0.001, tweak_max=180.0, ),
self.get_tweaker(f"{pfx}:MOT_CX", alias="base_x", label="base X"),
self.get_tweaker(f"{pfx}:MOT_CZ", alias="base_z", label="base Z"),
self.get_tweaker(f"{pfx}:MOT_DET_Z", alias="det_z", label="detector Z"),
c
]
qutilities.add_item_to_toolbox(toolbox,"Fast Stage",widget_list=widgets)
def build_group_collimator(self, toolbox):
pfx=QApplication.instance()._cfg.value(AppCfg.GBL_DEV_PREFIX)[1]
qutilities.add_item_to_toolbox(toolbox,"Collimator",
widget_list=[
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",),
],
)
c=QWidget()
c.setLayout(QGridLayout())
f=lambda v: lambda x:self.move_collimator(v) #needs nested lambda to work ...
for i,v in enumerate(('in','out','ready')):
but=QPushButton(v)
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",),
c,
]
qutilities.add_item_to_toolbox(toolbox,"Collimator",widget_list=widgets)
def build_group_posttube(self, toolbox):
pfx=QApplication.instance()._cfg.value(AppCfg.GBL_DEV_PREFIX)[1]
@@ -970,10 +984,10 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
c = QWidget()
c.setLayout(QGridLayout())
but = QPushButton("post tube out")
but.clicked.connect(lambda m, dir="out": self.move_post_tube(dir))
but.clicked.connect(lambda m, pos="out": self.move_post_tube(pos))
c.layout().addWidget(but, 0, 0)
but = QPushButton("post tube in")
but.clicked.connect(lambda m, dir="in": self.move_post_tube(dir))
but.clicked.connect(lambda m, pos="in": self.move_post_tube(pos))
c.layout().addWidget(but, 0, 1)
widgets.append(c)
@@ -991,14 +1005,11 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
def build_group_xeye(self, toolbox):
pfx=QApplication.instance()._cfg.value(AppCfg.GBL_DEV_PREFIX)[1]
qutilities.add_item_to_toolbox(
toolbox,
"X-Ray Eye",
widget_list=[
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"),
],
)
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"),
]
qutilities.add_item_to_toolbox(toolbox,"X-Ray Eye",widget_list=widgets)
def set_active_task(self, task):
_log.info("TASK == {}".format(task))
@@ -1966,6 +1977,8 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
#def _OLD_daq_collect_points(self, points, visualizer_method, visualizer_params):
app = QApplication.instance()
cfg = app._cfg
dt_misc = cfg.value(AppCfg.DT_MISC)
geo = app._geometry
verbose=0xff
fn='/tmp/shapepath'
@@ -1983,7 +1996,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
#sp.gen_grid_points(w=15, h=15, pitch=3, rnd=0, ofs=(0, +2000))
#sp.gen_grid_points(w=5, h=10, pitch=1, rnd=0, ofs=(0, 0));sp.sort_points(False, 10);sp.points
#sp.sort_points(False, 15);
sp.meta['pt2pt_time']=10
sp.meta['pt2pt_time']=dt_misc['pt2pt_time']
sp.setup_gather()
sp.setup_sync(verbose=verbose&32, timeOfs=0.05)
try:
@@ -2005,10 +2018,11 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
_log.info(f'progress {p}/{sp.points.shape[0]}')
time.sleep(.1)
sp.gather_upload(fnRec=fn+'.npz')
dp=deltatau.shapepath.DebugPlot(sp)
dp.plot_gather(mode=11)
plt.show(block=False)
#plt.show(block=True)
if dt_misc['show_plots']:
dp=deltatau.shapepath.DebugPlot(sp)
dp.plot_gather(mode=11)
plt.show(block=False)
#plt.show(block=True)
return
def esc_run_steps(self, steps, title):
@@ -2020,158 +2034,155 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
QMessageBox.warning(self, "escape steps", "ABORTED" + title)
break
def move_post_tube(self, dir):
#backlight="{'pos_in': -10.0, 'pos_out': 0.0}"
def move_post_tube(self, pos):
# post_sample_tube="{'x_up': -0.2, 'y_up': 0.0, 'x_down': 0.0, 'y_down': 0.0, 'x_out_delta': 0.0, 'y_out_delta': 0.0, 'z_in': 0.0, 'z_out': 0.0}"
app=QApplication.instance()
cfg=app._cfg
x_up = cfg.value(AppCfg.PST_X_UP , np.NaN,type=float)
y_up = cfg.value(AppCfg.PST_Y_UP , np.NaN,type=float)
x_down = cfg.value(AppCfg.PST_X_DOWN, np.NaN,type=float)
y_down = cfg.value(AppCfg.PST_Y_DOWN, np.NaN,type=float)
dx = cfg.value(AppCfg.PST_DX , np.NaN,type=float)
dy = cfg.value(AppCfg.PST_DY , np.NaN,type=float)
tz_in = cfg.value(AppCfg.PST_TZ_IN , np.NaN,type=float)
tz_out = cfg.value(AppCfg.PST_TZ_OUT, np.NaN,type=float)
if np.isnan(x_up):
pos_pst = cfg.value(AppCfg.DFT_POS_PST)
if pos_pst is None:
msg = "SwissMX *POST-SAMPLE-TUBE* configuration is incomplete!!!"
_log.warning(msg)
QMessageBox.warning(self, "post tube not configured", msg)
return
usy = self.tweakers["tube_usy"]
dsy = self.tweakers["tube_dsy"]
x_in_us=pos_pst['x_in_us']
y_in_us=pos_pst['y_in_us']
x_in_ds=pos_pst['x_in_ds']
y_in_ds=pos_pst['y_in_ds']
x_out_d=pos_pst['x_out_delta']
y_out_d=pos_pst['y_out_delta']
z_in =pos_pst['z_in']
z_out =pos_pst['z_out']
usx = self.tweakers["tube_usx"]
dsx = self.tweakers["tube_dsx"]
tube_z = self.tweakers["tube_z"]
tw_x_us = self.tweakers["tube_usx"]
tw_y_us = self.tweakers["tube_usy"]
tw_x_ds = self.tweakers["tube_dsx"]
tw_y_ds = self.tweakers["tube_dsy"]
tw_z = self.tweakers["tube_z"]
tandem_twv = float(self._post_tandem_tweak_val.text())
if dir == "in":
_log.info("move post sample tube in")
usy.move_abs(y_up)
dsy.move_abs(y_down)
usx.move_abs(x_up)
dsx.move_abs(x_down)
_log.info(f"move post sample tube {pos}")
if pos == "in":
tw_x_us.move_abs(x_in_us)
tw_y_us.move_abs(y_in_us)
tw_x_ds.move_abs(x_in_ds)
tw_y_ds.move_abs(y_in_ds)
try:
app_utils.assert_tweaker_positions([
(usy, y_up, 0.1),
(dsy, y_down, 0.1),
(usx, x_up, 0.1),
(dsx, x_down, 0.1), ],timeout=10.0,
(tw_x_us, x_in_us, 0.1),
(tw_y_us, y_in_us, 0.1),
(tw_x_ds, x_in_ds, 0.1),
(tw_y_ds, y_in_ds, 0.1), ],timeout=10.0,
)
except app_utils.PositionsNotReached as e:
_log.warning("failed to move post sample tube {}".format(dir))
_log.warning(e)
QMessageBox.warning(self, "failed to move post sample tube XY {in}", "failed to move post sample tube XY {in}",)
msg=f"failed to move post sample tube {pos}: {e}"
_log.warning(msg)
QMessageBox.warning(self, "failed to move post sample tube", msg,)
raise
tube_z.move_abs(tz_in, wait=True)
tw_z.move_abs(z_in, wait=True)
try:
app_utils.assert_tweaker_positions([(tube_z, tz_in, 0.1)])
app_utils.assert_tweaker_positions([(tw_z, z_in, 0.1)])
except app_utils.PositionsNotReached as e:
_log.warning("failed to move post sample tube Z {in}")
_log.warning(e)
QMessageBox.warning(self, "failed to move post sample tube Z {in}", "failed to move post sample tube Z {in}",)
msg=f"failed to move post sample tube {pos}: {e}"
_log.warning(msg)
QMessageBox.warning(self, "failed to move post sample tube", msg,)
raise
elif dir == "out":
_log.info("move post sample tube out")
tube_z.move_abs(tz_out, wait=True)
elif pos == "out":
tw_z.move_abs(z_out, wait=True)
try:
app_utils.assert_tweaker_positions([(tube_z, tz_out, 0.1)])
app_utils.assert_tweaker_positions([(tw_z, z_out, 0.1)])
except app_utils.PositionsNotReached as e:
_log.warning("failed to move post sample tube {out}")
_log.warning(e)
QMessageBox.warning(self,"failed to move post sample tube Z {out}","failed to move post sample tube Z {out}",)
msg=f"failed to move post sample tube {pos}: {e}"
_log.warning(msg)
QMessageBox.warning(self, "failed to move post sample tube", msg,)
raise
usy.move_abs(y_up+dy)
dsy.move_abs(y_down+dy)
usx.move_abs(x_up+dx)
dsx.move_abs(x_down+dx)
x_out_us=x_in_us+x_out_d; tw_x_us.move_abs(x_out_us)
y_out_us=y_in_us+y_out_d; tw_y_us.move_abs(y_out_us)
x_out_ds=x_in_ds+x_out_d; tw_x_ds.move_abs(x_out_ds)
y_out_ds=y_in_ds+y_out_d; tw_y_ds.move_abs(y_out_ds)
try:
app_utils.assert_tweaker_positions([
(usy, y_up + dy, 0.1),
(dsy, y_down + dy, 0.1),
(usx, x_up + dx, 0.1),
(dsx, x_down + dx, 0.1), ], timeout=10.0,
(tw_x_us, x_out_us, 0.1),
(tw_y_us, y_out_us, 0.1),
(tw_x_ds, x_out_ds, 0.1),
(tw_y_ds, y_out_ds, 0.1), ], timeout=10.0,
)
except app_utils.PositionsNotReached as e:
_log.warning("failed to move post sample tube {}".format(dir))
_log.warning(e)
QMessageBox.warning(self,"failed to move post sample tube XY {out}","failed to move post sample tube XY {out}",)
msg=f"failed to move post sample tube {pos}: {e}"
_log.warning(msg)
QMessageBox.warning(self, "failed to move post sample tube", msg,)
raise
elif dir == "x-pos":
_log.info("tamdem move post sample tube X-pos by {} mm".format(tandem_twv))
usx.move_rel(tandem_twv)
dsx.move_rel(tandem_twv)
elif dir == "x-neg":
_log.info("tamdem move post sample tube X-neg {} mm".format(tandem_twv))
usx.move_rel(-tandem_twv)
dsx.move_rel(-tandem_twv)
elif dir == "up":
_log.info("tamdem move post sample tube UP {} mm".format(tandem_twv))
usy.move_rel(tandem_twv)
dsy.move_rel(tandem_twv)
elif dir == "down":
_log.info("tamdem move post sample tube DOWN {} mm".format(tandem_twv))
usy.move_rel(-tandem_twv)
dsy.move_rel(-tandem_twv)
elif pos == "x+":
tw_x_us.move_rel(tandem_twv)
tw_x_ds.move_rel(tandem_twv)
elif pos == "x-":
tw_x_us.move_rel(-tandem_twv)
tw_x_ds.move_rel(-tandem_twv)
elif pos == "y+":
tw_y_us.move_rel(tandem_twv)
tw_y_ds.move_rel(tandem_twv)
elif pos == "y-":
tw_y_us.move_rel(-tandem_twv)
tw_y_ds.move_rel(-tandem_twv)
else:
raise ValueError("post sample tube *{}* is not known!!")
def move_detector(self, pos):
#SAR-EXPMX: MOT_DET_Z.VAL
# detector="{'pos_in': -0.1, 'pos_out': 0.0}"
app=QApplication.instance()
cfg=app._cfg
det_z = self.tweakers["det_z"]
if AppCfg.DFT_POS_DET not in cfg.allKeys():
pos_det = cfg.value(AppCfg.DFT_POS_DET)
if pos_det is None:
msg="detector default positions are not configured."
_log.warning(msg)
QMessageBox.warning(self, "configuration incomplete", msg)
QMessageBox.warning(self, "post tube not configured", msg)
return
pos = cfg.value(AppCfg.DFT_POS_DET)
_log.info("moving collimator {} to X,Y = {:.3f}, {:.3f}".format(pos, x_pos, y_pos))
if pos == "out":
cy.move_abs(y_pos+dy, assert_position=True)
cx.move_abs(x_pos+dx, assert_position=True)
elif pos == "in":
cx.move_abs(x_pos, assert_position=True)
cy.move_abs(y_pos, assert_position=True)
elif pos == "ready":
cx.move_abs(x_pos, assert_position=True)
cy.move_abs(y_pos+dy, assert_position=True)
else:
det_z = self.tweakers["det_z"]
try:
p_z=pos_det['pos_'+pos]
except KeyError:
raise ValueError("Collimator position *{}* is not known!!")
_log.info(f"moving detector {pos} to {p_z:.5g}")
det_z.move_abs(p_z, assert_position=True)
def move_collimator(self, pos):
# collimator="{'x_in': 0.0, 'y_in': -0.1, 'x_out_delta': 0.0, 'y_out_delta': 0.0}"
app=QApplication.instance()
cfg=app._cfg
cx = self.tweakers["colli_x"]
cy = self.tweakers["colli_y"]
x_pos = cfg.value(AppCfg.COL_X_IN, None, type=float)
y_pos = cfg.value(AppCfg.COL_Y_IN, np.NaN, type=float)
dx = cfg.value(AppCfg.COL_DX, np.NaN, type=float)
dy = cfg.value(AppCfg.COL_DY, np.NaN, type=float)
if np.isnan(x_pos + y_pos + dx + dy):
pos_col = cfg.value(AppCfg.DFT_POS_COL)
if pos_col is None:
msg="COLLIMATOR configuration is incomplete!"
_log.warning(msg)
QMessageBox.warning(self, "post tube not configured", msg)
return
_log.info("moving collimator {} to X,Y = {:.3f}, {:.3f}".format(pos, x_pos, y_pos))
x_in = pos_col['x_in']
y_in = pos_col['y_in']
x_out = pos_col['x_out']
y_out = pos_col['y_out']
if pos == "out":
cy.move_abs(y_pos+dy, assert_position=True)
cx.move_abs(x_pos+dx, assert_position=True)
x_pos=x_out
y_pos=y_out
elif pos == "in":
cx.move_abs(x_pos, assert_position=True)
cy.move_abs(y_pos, assert_position=True)
x_pos=x_in
y_pos=y_in
elif pos == "ready":
cx.move_abs(x_pos, assert_position=True)
cy.move_abs(y_pos+dy, assert_position=True)
x_pos=x_in
y_pos=y_out
else:
raise ValueError("Collimator position *{}* is not known!!")
_log.info(f"moving collimator {pos} to X,Y = {x_pos:.3f}, {y_pos:.3f}")
cx.move_abs(x_pos, assert_position=True)
cy.move_abs(y_pos, assert_position=True)
# **************** OBSOLETE AND/OR OLD STUFF ****************