This commit is contained in:
2022-08-17 20:01:56 +02:00
parent 22fcad62c1
commit c4cdf15bad
4 changed files with 116 additions and 83 deletions

View File

@@ -63,68 +63,28 @@ class AppCfg(QSettings):
self.setValue(AppCfg.GEO_BEAM_POS, [23.4, -54.2]) # beam position relativ to optical center in mm self.setValue(AppCfg.GEO_BEAM_POS, [23.4, -54.2]) # beam position relativ to optical center in mm
if AppCfg.GEO_PIX2POS not in keys: if AppCfg.GEO_PIX2POS not in keys:
_log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. calc default') _log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. use default')
import geometry import numpy as np
geo=geometry.geometry() lut_pix2pos=(np.array([1., 200., 400., 600., 800., 1000.]),
pix2pos_measure={ np.array([[[ 2.42827273e-03, -9.22117396e-05],
1:[(-3.0, -7.6, 116.99110193046, 632.5463827525), [-1.10489804e-04, -2.42592492e-03]],
(-2.0, -7.6, 934.07501517856, 600.7926167715), [[ 1.64346103e-03, -7.52341417e-05],
(-2.0, -7.1, 916.54131238102, 191.0366615002), [-6.60711165e-05, -1.64190224e-03]],
(-3.0, -7.1, 103.74668003329, 226.2150231456)], [[ 9.91307639e-04, -4.02008751e-05],
200:[(-3.1, -7.3, 113.66321353086, 824.9041423107), [-4.23878232e-05, -9.91563507e-04]],
(-2.3, -7.3, 1065.97386092697, 792.2851118419), [[ 5.98443038e-04, -2.54046255e-05],
(-2.3, -6.7, 1033.68452410347, 74.0336610693), [-2.76831563e-05, -6.02738142e-04]],
(-3.1, -6.7, 84.62681572700, 116.6832971512)], [[ 3.64418977e-04, -1.41389267e-05],
400:[(-3.4, -6.7, 155.00053674203, 601.3838942136), [-1.55708176e-05, -3.66233567e-04]],
(-3.0, -6.7, 957.95919656052, 573.0827012272), [[ 2.16526433e-04, -8.23070130e-06],
(-3.2, -6.5, 541.08684037200, 187.9171307943), [-9.29894004e-06, -2.16842976e-04]]]))
(-3.2, -6.8, 564.32152887203, 789.1146957326)], self.setValue(AppCfg.GEO_PIX2POS, lut_pix2pos)
600:[(-3.3, -6.8, 328.27244399903, 509.5061192017),
(-3.1, -6.8, 992.78996735279, 488.0323963092),
(-3.2, -6.9, 672.03111567934, 832.4122409755),
(-3.2, -6.7, 645.70960116180, 164.2534779331)],
800:[(-3.2, -6.7, 639.52253576449, 53.4455632943),
(-3.2, -6.85, 671.47023245203, 882.6335091391),
(-3.3, -6.75, 105.12470026379, 361.3051859197),
(-3.1, -6.75, 1195.96864609255, 313.1068618673)],
1000:[(-3.25, -6.75, 195.05641095116, 353.3492286375),
(-3.15, -6.75, 1117.27204644084, 314.9636405871),
(-3.2, -6.8, 675.10991143017, 790.3040145281),
(-3.2, -6.72, 638.98580653116, 59.3803912957)]}
geo.update_pix2pos(pix2pos_measure)
self.setValue(AppCfg.GEO_PIX2POS, geo._lut_pix2pos)
if AppCfg.GEO_OPT_CTR not in keys: if AppCfg.GEO_OPT_CTR not in keys:
_log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. calc default') _log.warning(f'{AppCfg.GEO_OPT_CTR} not defined. use default')
import geometry import numpy as np
geo=geometry.geometry() opt_ctr=np.array([603.28688025, 520.01112846])
opt_ctr_meas={ # x,y = 0.02, -4.89 self.setValue(AppCfg.GEO_OPT_CTR, opt_ctr)
1000:[(1057.4251530483375, 116.10122290395591),
(117.84916300310408, 190.27827474963223),
(184.2181041281829, 963.2812360887852),
(1092.5616512910262, 899.514998537239)],
800:[(888.2494207687248, 203.2917926172947),
(329.96950424600305, 248.83910515411347),
(372.9141132092893, 708.2162858826),
(906.4683457834523, 675.6824912134438)],
600:[(781.5385742538922, 251.44180872764602),
(447.09116505496564, 264.4553265953085),
(471.81684900352445, 554.6567750441825),
(798.4561474818535, 535.1364982426887)],
400:[(722.9777438494109, 286.5783069703348),
(525.1722722609408, 295.68776947769857),
(535.5830865550707, 462.26079818377866),
(729.4845027832422, 450.5486321028824)],
200:[(689.1425973934884, 308.70128734536104),
(565.5141776506945, 307.39993555859473),
(574.6236401580583, 406.30267135282986),
(693.0466527537872, 399.79591241899857)],
1:[(673.5263759522934, 307.39993555859473),
(591.5412133860195, 308.70128734536104),
(595.4452687463182, 376.3715802572061),
(672.2250241655271, 373.7688766836736)]}
geo.update_optical_center(opt_ctr_meas)
self.setValue(AppCfg.GEO_OPT_CTR, geo._opt_ctr)
#if AppCfg.ACTIVATE_PULSE_PICKER not in keys: #if AppCfg.ACTIVATE_PULSE_PICKER not in keys:
# self.setValue(AppCfg.ACTIVATE_PULSE_PICKER, False) # self.setValue(AppCfg.ACTIVATE_PULSE_PICKER, False)

View File

@@ -48,7 +48,7 @@ class geometry:
ax.invert_yaxis() ax.invert_yaxis()
ax.grid() ax.grid()
ax.axis('equal') ax.axis('equal')
for k, v in opt_ctr_meas.items(): for k, v in meas.items():
v=np.array(v) v=np.array(v)
# ax.plot(v[:, 0], v[:, 1]) # ax.plot(v[:, 0], v[:, 1])
ax.fill(v[:, 0], v[:, 1], fill=False) ax.fill(v[:, 0], v[:, 1], fill=False)
@@ -318,6 +318,32 @@ if __name__=="__main__":
(-3.15, -6.75, 1117.27204644084, 314.9636405871), (-3.15, -6.75, 1117.27204644084, 314.9636405871),
(-3.2, -6.8, 675.10991143017, 790.3040145281), (-3.2, -6.8, 675.10991143017, 790.3040145281),
(-3.2, -6.72, 638.98580653116, 59.3803912957)]} (-3.2, -6.72, 638.98580653116, 59.3803912957)]}
measure=\
{1: [(6.4190000000000005, 6.907, 696.2976073449591, 227.76776138682274),
(5.719, 6.807, 410.67447894055806, 284.44919082240665),
(5.719, 5.207, 434.78681995014756, 938.5631353309454),
(6.619, 5.207, 808.7345059175318, 927.4590367789931)],
200: [(6.619, 6.607, 940.264899030901, 187.39774454408854),
(5.519, 6.607, 272.1925062601967, 219.8977706369289),
(5.519, 5.407, 298.31361407848783, 941.97432810785),
(6.619, 5.407, 969.4645435773624, 920.3295993015843)],
400: [(6.719, 6.707, 1099.5956451604673, 46.46696479882394),
(5.719, 6.707, 91.88845211350781, 99.00912182475837),
(5.719, 5.807, 122.49326406274122, 998.8073593766618),
(6.719, 5.807, 1137.5074440945523, 963.4302060882611)],
600: [(6.619, 6.807, 1068.8592966662907, 106.9592377596037),
(6.019, 6.807, 75.47928488084321, 151.1144445833613),
(6.019, 6.307, 103.13064811335389, 977.5525209662414),
(6.619, 6.307, 1104.9406638931132, 939.9675773457886)],
800: [(6.619, 6.307, 1160.5691045813528, 202.93697492698996),
(6.219, 6.307, 65.05964829488164, 253.28864950246646),
(6.219, 6.107, 88.00366601279788, 797.1538427010806),
(6.619, 6.107, 1180.6517090746024, 753.0303703110591)],
1000: [(6.519, 6.267, 1087.8134573150567, 183.90222416155348),
(6.319, 6.267, 160.59872007696185, 229.55456266733404),
(6.319, 6.107, 190.50887289109403, 963.1404158981525),
(6.519, 6.107, 1116.3595117455784, 925.6445737503763)]}
obj.update_pix2pos(measure) obj.update_pix2pos(measure)
obj.interp_zoom(1) obj.interp_zoom(1)
@@ -353,6 +379,33 @@ if __name__=="__main__":
(591.5412133860195, 308.70128734536104), (591.5412133860195, 308.70128734536104),
(595.4452687463182, 376.3715802572061), (595.4452687463182, 376.3715802572061),
(672.2250241655271, 373.7688766836736)]} (672.2250241655271, 373.7688766836736)]}
opt_ctr_meas=\
{1000: [(943.5814614822486, 271.79551650350834),
(310.28543090843203, 317.87448013362246),
(357.2157641345181, 945.3504169712918),
(982.8856744171983, 907.5691713113356)],
# 800: [(804.3925790602868, 377.45059798190084),
# (428.94991325159833, 401.78484483987137),
# (456.760481089279, 776.3584304036324),
# (829.595906163185, 752.0241835456618)],
# 600: [(725.3062767718826, 435.6789743920446),
# (497.52754628726467, 448.43934430925407),
# (514.6798917766387, 674.3986678435945),
# (740.7483129345815, 659.5001702939031)],
400: [(676.5616510826158, 467.6400729767663),
(539.6440684653923, 477.20915075936176),
(550.068542225442, 612.9457099265683),
(686.4200153677604, 603.8457508612842)],
# 200: [(647.9882475277134, 488.31261219978296),
# (564.236743827639, 494.4770028644908),
# (571.9870755133423, 577.6833939808159),
# (654.4623032630916, 571.5416217015793)],
# 1: [(633.8759316189822, 496.84436992197425),
# (578.3851177374523, 500.9472972316709),
# (582.6205681144841, 559.3272486023482),
# (638.3177769017573, 554.8006203263507)]
}
obj.update_optical_center(opt_ctr_meas, True) obj.update_optical_center(opt_ctr_meas, True)

View File

@@ -300,7 +300,7 @@ class Main(QMainWindow, Ui_MainWindow):
self.create_helical_widgets() #ZAC: orig. code self.create_helical_widgets() #ZAC: orig. code
self.center_piece_update(0) # start camera updater self.center_piece_update(0) # start camera updater
curzoom = app._zoom.get() curzoom = app._zoom.get_sp()
_log.debug(f"starting app with zoom at {curzoom}") _log.debug(f"starting app with zoom at {curzoom}")
self.zoom_changed_cb(curzoom) self.zoom_changed_cb(curzoom)
self._tabs_daq_methods.currentChanged.connect(self.switch_task) self._tabs_daq_methods.currentChanged.connect(self.switch_task)
@@ -442,7 +442,7 @@ class Main(QMainWindow, Ui_MainWindow):
QtCore.QTimer.singleShot(delay, self.new_frame_sim_cb) QtCore.QTimer.singleShot(delay, self.new_frame_sim_cb)
def new_frame_pv_cb(self, **kwargs): def new_frame_pv_cb(self, **kwargs):
_log.debug('new_frame_pv_cb count {}'.format(kwargs['count'])) #_log.debug('new_frame_pv_cb count {}'.format(kwargs['count']))
app=QApplication.instance() app=QApplication.instance()
sz=app._camera._sz sz=app._camera._sz
if kwargs['count']==sz[0]*sz[1]: if kwargs['count']==sz[0]*sz[1]:
@@ -1022,7 +1022,9 @@ class Main(QMainWindow, Ui_MainWindow):
print(s) print(s)
res=QMessageBox.question(self, "calibration", f"use calibration\n{s} ? ") res=QMessageBox.question(self, "calibration", f"use calibration\n{s} ? ")
if res==QMessageBox.Yes: if res==QMessageBox.Yes:
app._geometry.update_pix2pos(app._raw_pix2pos) geo=app._geometry
geo.update_pix2pos(app._raw_pix2pos)
app._cfg.setValue(AppCfg.GEO_PIX2POS, geo._lut_pix2pos)
del app._raw_pix2pos del app._raw_pix2pos
def update_opt_ctr(self, calib): def update_opt_ctr(self, calib):
@@ -1035,7 +1037,12 @@ class Main(QMainWindow, Ui_MainWindow):
print(s) print(s)
res=QMessageBox.question(self, "calibration", f"use calibration\n{s} ? ") res=QMessageBox.question(self, "calibration", f"use calibration\n{s} ? ")
if res==QMessageBox.Yes: if res==QMessageBox.Yes:
app._geometry.update_optical_center(app._raw_opt_ctr) geo=app._geometry
geo.update_optical_center(app._raw_opt_ctr)
app._cfg.setValue(AppCfg.GEO_OPT_CTR, geo._opt_ctr)
go=self._goOptCtr
oc_sz=go.size()
go.setPos(-geo._opt_ctr-oc_sz/2)
del app._raw_opt_ctr del app._raw_opt_ctr
return return
@@ -1067,8 +1074,10 @@ class Main(QMainWindow, Ui_MainWindow):
# state = (zoom, fx, fy) (created at first call of self.track_objects() ) # state = (zoom, fx, fy) (created at first call of self.track_objects() )
app=QApplication.instance() app=QApplication.instance()
geo=app._geometry geo=app._geometry
zoom = app._zoom.get() zoom = app._zoom.get_sp()
fast_x=self.tweakers["fast_x"];fast_y=self.tweakers["fast_y"] fast_x=self.tweakers["fast_x"];fast_y=self.tweakers["fast_y"]
# TODO: get_position() is delayed as it is the RBV. do same as for the zoom
# TODO: and return the last set_point
fx=fast_x.get_position() fx=fast_x.get_position()
fy=fast_y.get_position() fy=fast_y.get_position()
try: try:
@@ -1109,7 +1118,7 @@ class Main(QMainWindow, Ui_MainWindow):
if fx_old!=fx or fy_old!=fy: if fx_old!=fx or fy_old!=fy:
p1=geo.pos2pix((fx_old,fy_old)) p1=geo.pos2pix((fx_old,fy_old))
p2=geo.pos2pix((fx,fy)) p2=geo.pos2pix((fx,fy))
d=p2-p1 d=p1-p2
for o in tracked['objLst']: for o in tracked['objLst']:
pos=o.pos() pos=o.pos()
@@ -1167,7 +1176,7 @@ class Main(QMainWindow, Ui_MainWindow):
self._mouse_pos = pos self._mouse_pos = pos
task = self.active_task() task = self.active_task()
xy = self._goImg.mapFromScene(pos) xy = self._goImg.mapFromScene(pos)
z = app._zoom.get() z = app._zoom.get_sp()
#_log.debug('mouse_pos:{} scene_pos:{} zoom:{}'.format(pos,xy,z)) #_log.debug('mouse_pos:{} scene_pos:{} zoom:{}'.format(pos,xy,z))
#TODO: implement mouse handling #TODO: implement mouse handling
# if self._ppm_toolbox._force_ppm > 0: # if self._ppm_toolbox._force_ppm > 0:
@@ -1277,8 +1286,8 @@ class Main(QMainWindow, Ui_MainWindow):
#dy=-(y-by)/ppm #dy=-(y-by)/ppm
#fx+=dx #fx+=dx
#fy+=dy #fy+=dy
fx_motor.move_relative(mm[0]) fx_motor.move_relative(-mm[0])
fy_motor.move_relative(mm[1]) fy_motor.move_relative(-mm[1])
#self.fast_dx_position.emit(dx) #self.fast_dx_position.emit(dx)
#self.fast_dy_position.emit(dy) #self.fast_dy_position.emit(dy)
pass pass
@@ -3436,9 +3445,9 @@ def main():
hostname=socket.gethostname() hostname=socket.gethostname()
if hostname=='ganymede': if hostname=='ganymede':
#use EPICS locally #use EPICS locally
os.environ['EPICS_CA_ADDR_LIST']='localhost' #os.environ['EPICS_CA_ADDR_LIST']='localhost'
#use EPICS if connected to ESC network #use EPICS if connected to ESC network
# os.environ['EPICS_CA_ADDR_LIST'] ='129.129.244.255 sf-saresc-cagw.psi.ch:5062 sf-saresc-cagw.psi.ch:5066' os.environ['EPICS_CA_ADDR_LIST'] ='129.129.244.255 sf-saresc-cagw.psi.ch:5062 sf-saresc-cagw.psi.ch:5066'

33
zoom.py
View File

@@ -68,7 +68,9 @@ class Zoom(QGroupBox, Ui_Zoom):
# pv.callbacks ... = self.zoom_update_cb # pv.callbacks ... = self.zoom_update_cb
# check also: pv.clear_auto_monitor() # disconnect PV monitor callback -> program exit faster. # check also: pv.clear_auto_monitor() # disconnect PV monitor callback -> program exit faster.
buttons=((1, "1"), (200, "200"), (400, "400"), (600, "600"), (800, "800"), (1000, "1000"),) buttons=((1, "1"), (200, "200"), (400, "400"), (600, "600"), (800, "800"), (1000, "1000"),)
current_zoom_value = self.get_zoom()
zoom=QApplication.instance()._zoom
current_zoom_value = zoom.get_rb()
# zoom widgets # zoom widgets
layout = QVBoxLayout() layout = QVBoxLayout()
@@ -269,11 +271,11 @@ class Zoom(QGroupBox, Ui_Zoom):
self._zoom_spinner.blockSignals(False) self._zoom_spinner.blockSignals(False)
self.zoomChanged.emit(float(value)) self.zoomChanged.emit(float(value))
def get_zoom(self) -> int: # def get_zoom(self) -> int:
zoom=QApplication.instance()._zoom # zoom=QApplication.instance()._zoom
pos = zoom.get() # pos = zoom.get()
_log.debug("get_zoom(epics) => {}".format(pos)) # _log.debug("get_zoom(epics) => {}".format(pos))
return pos # return pos
# def zoom_update_cb(self, pvname, value, char_value, **kwargs): # def zoom_update_cb(self, pvname, value, char_value, **kwargs):
# self._zoom_spinner.blockSignals(True) # self._zoom_spinner.blockSignals(True)
@@ -304,24 +306,33 @@ class QopticZoom(object):
self._pv[name]=pv self._pv[name]=pv
return pv return pv
def get(self) -> int: def get_rb(self) -> int:
# get_rb somtimes lags. therefore get_sp will get the last set_point without usage of pvs
try: try:
pv = self.getPv('POS_RB') pv = self.getPv('POS_RB') #default do not get the RBV, because this might be delayed
except AttributeError: except AttributeError:
val=self._val; _log.debug('simulated mode:{}'.format(val)) val=self._val; _log.debug('simulated mode:{}'.format(val))
return val return val
else: else:
pv=self.getPv('POS_RB') return pv.get()
return pv.get()
def get_sp(self) -> int:
try:
val=self._val
except AttributeError:
pv=self.getPv('POS_RB') # default do not get the RBV, because this might be delayed
self._val=val=pv.get()
return val
def set(self, val: int): def set(self, val: int):
try: try:
pv=self.getPv('POS_SP') pv=self.getPv('POS_SP')
except AttributeError: except AttributeError:
_log.debug('simulated mode:{}'.format(val)) _log.debug('simulated mode:{}'.format(val))
self._val=val #simulated mode
else: else:
pv.put(val) pv.put(val)
self._val=val
if __name__ == "__main__": if __name__ == "__main__":