Commit a0612414 authored by reiche's avatar reiche
Browse files

Initial modification to calculate pointing from X-ray position on two screens

parent 442d23a7
......@@ -118,6 +118,11 @@ class UndulatorOrbit(QMainWindow,Ui_UndulatorOrbitGUI):
self.UICaptureX.clicked.connect(self.capture)
self.UICaptureY.clicked.connect(self.capture)
self.UICalculatePointing.clicked.connect(self.calculatePointing)
self.UICalcClear.clicked.connect(self.clearPointing)
self.UIApplyPointing.clicked.connect(self.applyPointing)
self.UIReadPointing.clicked.connect(self.readPointing)
self.UISaveSnap.clicked.connect(self.savesnap)
self.UILaunchSnap.clicked.connect(self.launchsnap)
self.UIRestoreSnap.clicked.connect(self.restoresnap)
......@@ -135,8 +140,6 @@ class UndulatorOrbit(QMainWindow,Ui_UndulatorOrbitGUI):
self.UIAcRate.setCurrentIndex(1)
self.UIAcRate.currentIndexChanged.connect(self.ToggleTimer)
# generate initial snap file
self.snapcomment='Program Launch: '
self.savesnap()
......@@ -187,12 +190,18 @@ class UndulatorOrbit(QMainWindow,Ui_UndulatorOrbitGUI):
self.ModStart.setEnabled(True)
self.ModEnd.setEnabled(True)
def plot(self):
idx = self.UIBeamline.currentIndex()
orbit = self.BL[idx].readBPM()
orbitFB = self.BL[idx].readFB()
self.plotrefBPM= self.plotCanvas(orbit,orbitFB,'Orbit','FB','Orbit',self.axes1,self.canvas1, self.plotrefBPM)
orbitCalc=self.BL[idx].calcOrbit
if self.BL[idx].hasCalcOrbit:
self.plotrefBPM= self.plotCanvas(orbit,orbitFB,'Orbit','FB','Orbit',self.axes1,self.canvas1, self.plotrefBPM,orbitCalc)
else:
self.plotrefBPM= self.plotCanvas(orbit,orbitFB,'Orbit','FB','Orbit',self.axes1,self.canvas1, self.plotrefBPM)
if self.plotrefQuad is None:
SV = self.BL[idx].readQuadSV()
RB = self.BL[idx].readQuadRB()
......@@ -203,7 +212,7 @@ class UndulatorOrbit(QMainWindow,Ui_UndulatorOrbitGUI):
self.plotrefUnd= self.plotCanvas(SV,RB,'SV','RB','Undulator Mover',self.axes3,self.canvas3, self.plotrefUnd)
self.enforceMoverPlot = False
def plotCanvas(self,y1,y2,leg1,leg2,title,axes,canvas,ref):
def plotCanvas(self,y1,y2,leg1,leg2,title,axes,canvas,ref,y3=None):
lim=axes.get_ylim()
if ref is None or np.min(y1) < lim[0] or np.min(y2) < lim[0] or np.max(y1) > lim[1] or np.max(y2) > lim[1]:
ref = None
......@@ -216,6 +225,10 @@ class UndulatorOrbit(QMainWindow,Ui_UndulatorOrbitGUI):
plt2=axes.plot(y1[1::2],'r',label=r'Y-%s' % leg1)
plt3=axes.plot(y2[0::2],'b--',label=r'X-%s' % leg2)
plt4=axes.plot(y2[1::2],'r--',label=r'Y-%s' % leg2)
if not y3 is None:
plt5=axes.plot(y3[0::2],'b:',label=r'X-Calc')
plt6=axes.plot(y3[1::2],'r:',label=r'Y-Calc')
axes.set_xticks([i for i in range(len(lab))])
axes.set_xticklabels(lab,rotation='vertical',size='x-small')
axes.legend()
......@@ -303,6 +316,49 @@ class UndulatorOrbit(QMainWindow,Ui_UndulatorOrbitGUI):
elif 'Und' in sender:
self.BL[idx].umov[row]=flag
def applyPointing(self):
idx = self.UIBeamline.currentIndex()
if not self.BL[idx].hasCalcOrbit:
return
# range
istart=self.ModStart.currentIndex()
iend=self.ModEnd.currentIndex()
xfb=self.calcOrbit[0::2]
yfb=self.calcOrbit[1::2]
self.BL[idx].applyFB(xfb[istart,iend+1],istart,iend,true,true) # current fb target values are already included
self.BL[idx].applyFB(yfb[istart,iend+1],istart,iend,false,true)
self.BL[idx].hasCalcOrbit=False
self.enforcePlot()
def readPointing(self):
idx = self.UIBeamline.currentIndex()
x1,x2,y1,y2=self.BL[idx].readPhotonOffsets()
self.UIOFFX1.setText('%f' % x1)
self.UIOFFX2.setText('%f' % x2)
self.UIOFFY1.setText('%f' % y1)
self.UIOFFY2.setText('%f' % y2)
def calculatePointing(self):
x1 = float(str(self.UIOFFX1.text()))
x2 = float(str(self.UIOFFX2.text()))
y1 = float(str(self.UIOFFY1.text()))
y2 = float(str(self.UIOFFY2.text()))
idx = self.UIBeamline.currentIndex()
if idx == 0:
z1 = float(str(self.UIOFFARZ1.text()))
z2 = float(str(self.UIOFFARZ2.text()))
else:
z1 = float(str(self.UIOFFATZ1.text()))
z2 = float(str(self.UIOFFATZ2.text()))
self.BL[idx].calcCorrection(x1,x2,y1,y2,z1,z2)
self.enforcePlot()
def clearPointing(self):
idx = self.UIBeamline.currentIndex()
self.BL[idx].hasCalcOrbit=False
self.enforcePlot()
def modify(self):
# current beamline
......
......@@ -94,7 +94,26 @@ class UndulatorOrbitCore:
self.checkConnection(self.PVUndSet)
self.checkConnection(self.PVUndRead)
self.hasCalcOrbit= False
self.calcOrbit=[]
def readPhotonOffsets(self): # returns x1, x2, y1, y2 from two photon screens
return 0,0,0,0
def calcCorrection(self,x1,x2,y1,y2,z1,z2):
ax=(x2-x1)/(z2-z1)
bx=x2-ax*z2
cx=ax*self.dz # change per module
ay=(y2-y1)/(z2-z1)
by=y2-ay*z2
cy=ay*self.dz
self.calcOrbit=self.readFB()
nlen=len(self.bpm)
self.calcOrbit[0::2]=self.calcOrbit[0::2] - np.array([cx*i+bx for i in range(nlen)])
self.calcOrbit[1::2]=self.calcOrbit[1::2] - np.array([cy*i+by for i in range(nlen)])
self.hasCalcOrbit=True
def checkConnection(self,pvs):
con = [pv.wait_for_connection(timeout=0.5) for pv in pvs]
......
......@@ -258,7 +258,7 @@
</rect>
</property>
<property name="title">
<string>Target</string>
<string>Target (Feedback or Movers)</string>
</property>
<widget class="QPushButton" name="UITarget1">
<property name="geometry">
......@@ -350,7 +350,7 @@
<x>10</x>
<y>10</y>
<width>200</width>
<height>181</height>
<height>161</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -568,9 +568,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<y>180</y>
<width>200</width>
<height>171</height>
<height>151</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -683,9 +683,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>400</y>
<y>530</y>
<width>201</width>
<height>101</height>
<height>91</height>
</rect>
</property>
<property name="title">
......@@ -730,6 +730,181 @@
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_12">
<property name="geometry">
<rect>
<x>10</x>
<y>340</y>
<width>201</width>
<height>181</height>
</rect>
</property>
<property name="title">
<string>Using Photon Screens</string>
</property>
<widget class="QPushButton" name="UIApplyPointing">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>102</x>
<y>30</y>
<width>91</width>
<height>26</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 170, 127);</string>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
<widget class="QPushButton" name="UICalculatePointing">
<property name="geometry">
<rect>
<x>8</x>
<y>143</y>
<width>91</width>
<height>26</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Calculate</string>
</property>
</widget>
<widget class="QPushButton" name="UIReadPointing">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>8</x>
<y>30</y>
<width>91</width>
<height>26</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Read Offsets</string>
</property>
</widget>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>82</y>
<width>160</width>
<height>54</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLineEdit" name="UIOFFY1">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="UIOFFX1">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="UIOFFX2">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="UIOFFY2">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QLabel" name="label_22">
<property name="geometry">
<rect>
<x>40</x>
<y>62</y>
<width>59</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>Screen 1</string>
</property>
</widget>
<widget class="QLabel" name="label_23">
<property name="geometry">
<rect>
<x>120</x>
<y>62</y>
<width>59</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>Screen 2</string>
</property>
</widget>
<widget class="QLabel" name="label_24">
<property name="geometry">
<rect>
<x>14</x>
<y>87</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>X</string>
</property>
</widget>
<widget class="QLabel" name="label_25">
<property name="geometry">
<rect>
<x>14</x>
<y>113</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Y</string>
</property>
</widget>
<widget class="QPushButton" name="UICalcClear">
<property name="geometry">
<rect>
<x>102</x>
<y>143</y>
<width>91</width>
<height>26</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
......@@ -738,8 +913,8 @@
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<x>10</x>
<y>10</y>
<width>611</width>
<height>601</height>
</rect>
......@@ -816,12 +991,77 @@
</rect>
</property>
</widget>
<widget class="QLabel" name="label_26">
<property name="geometry">
<rect>
<x>520</x>
<y>30</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Distances</string>
</property>
</widget>
<widget class="QLabel" name="label_27">
<property name="geometry">
<rect>
<x>520</x>
<y>60</y>
<width>59</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>Screen 1</string>
</property>
</widget>
<widget class="QLabel" name="label_28">
<property name="geometry">
<rect>
<x>520</x>
<y>110</y>
<width>59</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>Screen 2</string>
</property>
</widget>
<widget class="QLineEdit" name="UIOFFARZ1">
<property name="geometry">
<rect>
<x>520</x>
<y>80</y>
<width>81</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>55.</string>
</property>
</widget>
<widget class="QLineEdit" name="UIOFFARZ2">
<property name="geometry">
<rect>
<x>520</x>
<y>130</y>
<width>81</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>75.</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_6">
<property name="geometry">
<rect>
<x>650</x>
<y>20</y>
<y>10</y>
<width>611</width>
<height>601</height>
</rect>
......@@ -898,6 +1138,71 @@
</rect>
</property>
</widget>
<widget class="QLineEdit" name="UIOFFATZ1">
<property name="geometry">
<rect>
<x>520</x>
<y>80</y>
<width>81</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>55.</string>
</property>
</widget>
<widget class="QLabel" name="label_29">
<property name="geometry">
<rect>
<x>520</x>
<y>60</y>
<width>59</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>Screen 1</string>
</property>
</widget>
<widget class="QLineEdit" name="UIOFFATZ2">
<property name="geometry">
<rect>
<x>520</x>
<y>130</y>
<width>81</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>75</string>
</property>
</widget>
<widget class="QLabel" name="label_30">
<property name="geometry">
<rect>
<x>520</x>
<y>110</y>
<width>59</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>Screen 2</string>
</property>
</widget>
<widget class="QLabel" name="label_31">
<property name="geometry">
<rect>
<x>520</x>
<y>30</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Distances</string>
</property>
</widget>
</widget>
<widget class="QLabel" name="label_10">
<property name="geometry">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment