camera tests; holography sample motion
This commit is contained in:
207
CameraTagging.py
Normal file
207
CameraTagging.py
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
print("Camera Tagging Script")
|
||||||
|
|
||||||
|
from epics import caput, caget, PV
|
||||||
|
import numpy as np
|
||||||
|
import time as time
|
||||||
|
|
||||||
|
#cam1="SATES21-CAMS154-M1"
|
||||||
|
#cam2="SATES24-CAMS161-M1"
|
||||||
|
|
||||||
|
#cam1xs = PV(cam1+':REGIONX_START')
|
||||||
|
#cam1xe = PV(cam1+':REGIONX_END')
|
||||||
|
#cam1ys = PV(cam1+':REGIONY_START')
|
||||||
|
#cam1ye = PV(cam1+':REGIONY_END')
|
||||||
|
#cam1ye = PV(cam1+':STATUS')
|
||||||
|
|
||||||
|
#cam2xs = PV(cam2+':REGIONX_START')
|
||||||
|
#cam2xe = PV(cam2+':REGIONX_END')
|
||||||
|
#cam2ys = PV(cam2+':REGIONY_START')
|
||||||
|
#cam2ye = PV(cam2+':REGIONY_END')
|
||||||
|
#cam2ye = PV(cam2+':STATUS')
|
||||||
|
def camera_tag(daq):
|
||||||
|
def create_cam(cam_name):
|
||||||
|
cam_dict = {
|
||||||
|
'name':cam_name,
|
||||||
|
'xs':PV(cam_name+':REGIONX_START'),
|
||||||
|
'xe':PV(cam_name+':REGIONX_END'),
|
||||||
|
'ys':PV(cam_name+':REGIONY_START'),
|
||||||
|
'ye':PV(cam_name+':REGIONY_ENDimport'),
|
||||||
|
'status':PV(cam_name+':CAMERASTATUS'),
|
||||||
|
'cap':PV(cam_name+':CAPTURE_OK')
|
||||||
|
}
|
||||||
|
|
||||||
|
print('status:', cam_dict['status'].get())
|
||||||
|
|
||||||
|
return cam_dict
|
||||||
|
|
||||||
|
|
||||||
|
def changeROI(cam,xs,xe,ys,ye):
|
||||||
|
cam['status'].put(1)
|
||||||
|
time.sleep(.5)
|
||||||
|
cam['xs'].put(xs)
|
||||||
|
time.sleep(.5)
|
||||||
|
cam['xe'].put(xe)
|
||||||
|
time.sleep(.5)
|
||||||
|
cam['ys'].put(ys)
|
||||||
|
time.sleep(.5)
|
||||||
|
cam['ye'].put(ye)
|
||||||
|
time.sleep(.5)
|
||||||
|
cam['status'].put(2)
|
||||||
|
counter = 0
|
||||||
|
while cam['cap'].get() < 10:
|
||||||
|
print('Waiting...')
|
||||||
|
time.sleep(.5)
|
||||||
|
conter += 1
|
||||||
|
if counter > 10:
|
||||||
|
print('Still waiting... Setting status again')
|
||||||
|
cam['status'].put(2)
|
||||||
|
counter = 0
|
||||||
|
print('Camera set')
|
||||||
|
|
||||||
|
def calcROI(cam, mode,percent): #0=centered 1=horiz
|
||||||
|
maxX=cam["maxX"]
|
||||||
|
maxY=cam["maxY"]
|
||||||
|
ye=2560
|
||||||
|
ys=1
|
||||||
|
xs=1
|
||||||
|
xe=2048
|
||||||
|
if mode==0: #square centered
|
||||||
|
factor=np.sqrt(percent/100)/2
|
||||||
|
xs=1+maxX*(0.5-factor)
|
||||||
|
xe=1+maxX*(0.5+factor)
|
||||||
|
ys=1+maxY*(0.5-factor)
|
||||||
|
ye=1+maxY*(0.5+factor)
|
||||||
|
|
||||||
|
if mode==1: #squashed horizontally (tall and narrow) portrait
|
||||||
|
factor=(percent/200)
|
||||||
|
xs=1+maxX*(0.5-factor)
|
||||||
|
xe=1+maxX*(0.5+factor)
|
||||||
|
ys=1
|
||||||
|
ye=maxY
|
||||||
|
|
||||||
|
if mode==2: #squashed vertically (wide) landscape
|
||||||
|
factor=(percent/200)
|
||||||
|
xs=1
|
||||||
|
xe=maxX
|
||||||
|
ys=1+maxY*(0.5-factor)
|
||||||
|
ye=1+maxY*(0.5+factor)
|
||||||
|
|
||||||
|
if mode==3: #squashed horizontally (tall and narrow) portrait with 50pix crop top and bottom
|
||||||
|
factor=(percent/200)
|
||||||
|
xs=1+maxX*(0.5-factor)
|
||||||
|
xe=1+maxX*(0.5+factor)
|
||||||
|
ys=50
|
||||||
|
ye=maxY-50
|
||||||
|
|
||||||
|
vfill=round(100*(ye-ys+1)/maxY)
|
||||||
|
return xs,xe,ys,ye,vfill
|
||||||
|
|
||||||
|
|
||||||
|
cam1 = create_cam('SATES21-CAMS154-M1')
|
||||||
|
cam2 = create_cam('SATES24-CAMS161-M1')
|
||||||
|
|
||||||
|
|
||||||
|
cam1["scanPoints"]=[10,25,40,50,65,80]
|
||||||
|
cam2["scanPoints"]=[10,25,40,50,65,80]
|
||||||
|
|
||||||
|
cam1["scanPoints"]=[10,20,30,40,50,60,70,80,90]
|
||||||
|
cam2["scanPoints"]=[10,25,40,55,70,85]
|
||||||
|
modesToScan =[1,2,0,3]
|
||||||
|
|
||||||
|
cam1["maxX"] =2560
|
||||||
|
cam1["maxY"] =2160
|
||||||
|
cam2["maxX"] =2560
|
||||||
|
cam2["maxY"] =2160
|
||||||
|
|
||||||
|
mode = 0
|
||||||
|
n_shots = 2500
|
||||||
|
scantype=0 #0 2 camera scan
|
||||||
|
#1 mode scan with 1 camera
|
||||||
|
|
||||||
|
if scantype==0:
|
||||||
|
for i in cam1['scanPoints']:
|
||||||
|
|
||||||
|
xs,xe,ys,ye,vf1=calcROI(cam1,mode,i)
|
||||||
|
changeROI (cam1,xs,xe,ys,ye)
|
||||||
|
|
||||||
|
for j in cam2['scanPoints']:
|
||||||
|
fn = f"test_cam1_{i}_cam2_{j}_mode_{mode}"
|
||||||
|
print(fn)
|
||||||
|
xs,xe,ys,ye,vf2=calcROI(cam2, mode,j)
|
||||||
|
changeROI (cam2,xs,xe,ys,ye)
|
||||||
|
#PV("SGE-CPCW-C1-EVR0:Pul0-Delay-SP").put(10500-j*100)
|
||||||
|
#PV("SGE-CPCW-C1-EVR0:Pul14-Delay-SP").put(10500-i*100)
|
||||||
|
PV("SGE-CPCW-C1-EVR0:Pul0-Delay-SP").put(10500-vf2*100)
|
||||||
|
PV("SGE-CPCW-C1-EVR0:Pul14-Delay-SP").put(10500-vf1*100)
|
||||||
|
if vf1>40:
|
||||||
|
PV("SATES21-CAMS154-M1:SW_PULSID_SRC").put(5) #5=9000uS
|
||||||
|
else:
|
||||||
|
PV("SATES21-CAMS154-M1:SW_PULSID_SRC").put(2) #3=5500uS (2=4500uS)
|
||||||
|
|
||||||
|
if vf2>40:
|
||||||
|
PV("SATES24-CAMS161-M1:SW_PULSID_SRC").put(6) #6=9000uS
|
||||||
|
else:
|
||||||
|
PV("SATES24-CAMS161-M1:SW_PULSID_SRC").put(3) #4=5500uS (3=4500uS)
|
||||||
|
|
||||||
|
print(10500-vf1*100);print(10500-vf2*100)
|
||||||
|
time.sleep(30)
|
||||||
|
daq.acquire(fn, n_pulses=n_shots)
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
if scantype==1: #Mode scan
|
||||||
|
for i in modesToScan: #i is the mode
|
||||||
|
for j in cam1['scanPoints']: #j is the fill %age
|
||||||
|
fn = f"test_cam1_{j}_mode_{i}_"
|
||||||
|
print(fn)
|
||||||
|
xs,xe,ys,ye,vf1=calcROI(cam1,i,j)
|
||||||
|
changeROI (cam1,xs,xe,ys,ye)
|
||||||
|
PV("SGE-CPCW-C1-EVR0:Pul14-Delay-SP" ).put(10500-vf1*100)
|
||||||
|
if vf1>40:
|
||||||
|
PV("SATES21-CAMS154-M1:SW_PULSID_SRC").put(5) #5=9000uS
|
||||||
|
else:
|
||||||
|
PV("SATES21-CAMS154-M1:SW_PULSID_SRC").put(2) #3=5500uS (2=4500uS)
|
||||||
|
|
||||||
|
print(10500-vf1*100);
|
||||||
|
time.sleep(30)
|
||||||
|
daq.acquire(fn, n_pulses=n_shots)
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
#xs,xe,ys,ye=calcROI(cam1,2,20)
|
||||||
|
#print(xs, xe, ys, ye)
|
||||||
|
#print('Width ', xe-xs)
|
||||||
|
#print('Height', ye-ys)
|
||||||
|
|
||||||
|
#changeROI(cam1,xs,xe,ys,ye)
|
||||||
|
|
||||||
|
#time.sleep(10)
|
||||||
|
|
||||||
|
#xs,xe,ys,ye=calcROI(cam1,2,80)
|
||||||
|
#changeROI(cam1,xs,xe,ys,ye)
|
||||||
|
#print(xs, xe, ys, ye)
|
||||||
|
#print('Width ', xe-xs)
|
||||||
|
#print('Height', ye-ys)
|
||||||
|
|
||||||
|
#time.sleep(10)
|
||||||
|
|
||||||
|
#xs,xe,ys,ye=calcROI(cam1,2,100)
|
||||||
|
#changeROI(cam1,xs,xe,ys,ye)
|
||||||
|
#print(xs, xe, ys, ye)
|
||||||
|
#print('Width ', xe-xs)
|
||||||
|
#print('Height', ye-ys)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
66
devices/holo_sample_motion.py
Executable file
66
devices/holo_sample_motion.py
Executable file
@ -0,0 +1,66 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from slic.core.adjustable import Adjustable, Converted, Combined
|
||||||
|
from slic.core.device import SimpleDevice
|
||||||
|
|
||||||
|
|
||||||
|
FACTOR2 = 1/np.sin(30 * np.pi/180)
|
||||||
|
FACTOR1 = -np.cos(30 * np.pi/180)
|
||||||
|
|
||||||
|
|
||||||
|
class HoloSample(Adjustable):
|
||||||
|
|
||||||
|
def __init__(self, m1, m2, ID="HOLOGRAPHY-SAMPLE", name="Holography sample Y", units="mm"):
|
||||||
|
super().__init__(ID, name=name, units=units)
|
||||||
|
self.m1 = m1
|
||||||
|
self.m2 = m2
|
||||||
|
#self.adjs = SimpleDevice(ID, combined=self, m1=m1, m2=m2)
|
||||||
|
|
||||||
|
|
||||||
|
# one master, others are following
|
||||||
|
def get_current_value(self):
|
||||||
|
return self.m2.get_current_value()/FACTOR2
|
||||||
|
|
||||||
|
# current value is average of all
|
||||||
|
#def get_current_value(self):
|
||||||
|
# converted_values = [
|
||||||
|
# self.m1.get_current_value(),
|
||||||
|
# self.m2.get_current_value()
|
||||||
|
# ]
|
||||||
|
# return np.mean(converted_values)
|
||||||
|
|
||||||
|
|
||||||
|
def set_target_value(self, value):
|
||||||
|
#print('current val m1', self.m1.get_current_value())
|
||||||
|
#print('current val m2', self.m2.get_current_value())
|
||||||
|
#print('F1: %f F2 %f'%(FACTOR1, FACTOR2) )
|
||||||
|
#print('requested val: ', value)
|
||||||
|
|
||||||
|
|
||||||
|
tasks = [
|
||||||
|
self.m1.set_target_value(value * FACTOR1),
|
||||||
|
self.m2.set_target_value(value * FACTOR2)
|
||||||
|
]
|
||||||
|
|
||||||
|
for t in tasks:
|
||||||
|
t.wait()
|
||||||
|
|
||||||
|
|
||||||
|
def is_moving(self):
|
||||||
|
return self.m1.is_moving() or self.m2.is_moving()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#def g1(x): return x / FACTOR1
|
||||||
|
#def g2(x): return x / FACTOR2
|
||||||
|
#def s1(x): return x * FACTOR1
|
||||||
|
#def s2(x): return x * FACTOR2
|
||||||
|
|
||||||
|
#m1 = SmarActAxis("SATES21-XSMA166:MOT7", internal=True)
|
||||||
|
#m2 = SmarActAxis("SATES21-XSMA166:MOT8", internal=True)
|
||||||
|
#c1 = Converted("C1", m1, g1, s1, internal=True)
|
||||||
|
#c2 = Converted("C2", m2, g2, s2, internal=True)
|
||||||
|
#comb = Combined("COMBINED", (c1, c2), name="Holo")
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user