This commit is contained in:
sfop
2017-04-27 10:18:20 +02:00
parent 6fc1738645
commit 3c97b19cc8
7 changed files with 701 additions and 307 deletions
+52 -11
View File
@@ -19,6 +19,10 @@ class WireScanInfo(DeviceBase):
self.on_status_change(None)
self.initialize()
self.home_offsets = []
for s in ("W1X_U0_SP", "W1Y_U0_SP", "W2X_U0_SP", "W2Y_U0_SP", "FOIL_U0_SP"):
self.home_offsets.append(caget(self.prefix + ":" +s, 'd'))
def on_status_change(self, val):
try:
if self.status_channels[0].get() == 1:
@@ -55,15 +59,38 @@ class WireScanInfo(DeviceBase):
self.curr_cycl.close()
for c in self.status_channels:
c.close()
def get_wire_pos(self, pos_motor):
if (pos_motor is None) or math.isnan(pos_motor):
return [pos_motor] * 4
w1x = (pos_motor - self.home_offsets[0]) / -(math.sqrt(2))
w1y = (pos_motor - self.home_offsets[1]) / (math.sqrt(2))
w2x = (pos_motor - self.home_offsets[2]) / -(math.sqrt(2))
w2y = (pos_motor - self.home_offsets[3]) / (math.sqrt(2))
return [w1x, w1y, w2x, w2y]
def newScanInfoDevice(name, prefix):
def new_scan_info_device(name, prefix):
return WireScanInfo(name, prefix)
def get_wire_pos(wire_scanner, pos):
return wire_scanner.get_wire_pos(pos)
def get_scan_selection(scan_type, index = 0):
if scan_type == WireScanner.WireX1: return WireScanner.W1X
if scan_type == WireScanner.WireY1: return WireScanner.W1Y
if scan_type == WireScanner.WireX2: return WireScanner.W2X
if scan_type == WireScanner.WireY2: return WireScanner.W2Y
if scan_type == WireScanner.Set1: return WireScanner.W1X if (index==0) else WireScanner.W1Y
if scan_type == WireScanner.Set2: return WireScanner.W2X if (index==0) else WireScanner.W2Y
return None
class WireScanner(WireScanInfo):
ScanType = [WireX1, WireY1, WireX2, WireY2, Set1, Set2] = ['X1', 'Y1', 'X2', 'Y2', 'Set1', 'Set2']
Selection = [Garage, W1X, W1Y, W2X, W2Y, Foil] = "GARAGE", "W1X", "W1Y", "W2X", "W2Y", "FOIL"
def __init__(self, prefix, sel = None, start=None , end=None, cycles=None, velocity=None, continuous = None):
def __init__(self, prefix, scan_range, cycles=None, velocity=None, continuous = None):
WireScanInfo.__init__(self, "Wire Scan " + prefix, prefix)
self.motor = ch.psi.pshell.epics.Motor("WireScanner motor", self.prefix + ":MOTOR_1")
self.motor.uploadConfig()
@@ -80,14 +107,10 @@ class WireScanner(WireScanInfo):
self.range = None
self.start = None
self.end = None
self.scan_range = scan_range;
if sel is not None:
self.set_selection(sel)
#Setting parameters
if start is not None:
self.start.write(float(start))
if end is not None:
self.end.write(float(end))
if velocity is not None:
self.wire_velocity.write(float(velocity))
if cycles is not None:
@@ -97,8 +120,7 @@ class WireScanner(WireScanInfo):
self.readback = self.motor_bs_readback.get()
self.cycles = self.nb_cycles.get()
self.velocity = self.wire_velocity.get()
self.scan_range = [self.start.get(), self.end.get()]
self.velocity = self.wire_velocity.get()
self.initialize()
#def on_readback_change(self, val):
@@ -113,7 +135,16 @@ class WireScanner(WireScanInfo):
self.range = Channel(self.prefix + ":" + self.selection + "_RANGE_SP")
self.start = Channel(self.prefix + ":" + self.selection + "_START_SP")
self.end = Channel(self.prefix + ":" + self.selection + "_END_SP")
self.wire_sel.put(WireScanner.Selection.index(sel))
self.wire_sel.put(WireScanner.Selection.index(sel))
#Setting parameters
if start is not None:
if sel in ["W1X", "W2X"]: self.start.write(float(self.scan_range[0]))
if sel in ["W1Y", "W2Y"]: self.start.write(float(self.scan_range[2]))
if end is not None:
if sel in ["W1X", "W2X"]: self.end.write(float(self.scan_range[1]))
if sel in ["W1Y", "W2Y"]: self.end.write(float(self.scan_range[3]))
def abort(self):
caputq(self.prefix + ":ABORT.PROC", 1)
@@ -127,6 +158,16 @@ class WireScanner(WireScanInfo):
def scan(self):
self.cycles = self.nb_cycles.get()
caputq(self.prefix + ":SCAN_WIRE", 1)
def get_sel_wire_pos(self, pos_motor=None):
if pos_motor is None:
pos_motor = self.motor_bs_readback.get()
wire_pos = self.get_wire_pos(pos_motor)
if self.selection == WireScanner.W1X: return wire_pos[0]
if self.selection == WireScanner.W1Y: return wire_pos[1]
if self.selection == WireScanner.W2X: return wire_pos[2]
if self.selection == WireScanner.W2Y: return wire_pos[3]
return float('nan')
def doClose(self):
WireScanInfo.doClose(self)
+54 -29
View File
@@ -6,25 +6,26 @@ run("Devices/WireScanner")
BPM_SENSORS = [("x","X1"), ("y","Y1"), ("q","Q1")] #(logic name sufix, channel sufix)
#Paramter parsing
prefix = args[0] if is_panel else "S30CB09-DWSC440"
sel = args[1] if is_panel else WireScanner.W1X
start = args[2] if is_panel else -200
end = args[3] if is_panel else 200
cycles = args[4] if is_panel else 5
velocity = args[5] if is_panel else 200
bpms = args[6] if is_panel else get_wire_scans_bpms(prefix)
print "WireScan parameters: ", prefix, sel, start, end, cycles, cycles, bpms
prefix = args[0] if is_panel else "S30CB09-DWSC440"
scan_type = args[1] if is_panel else WireScanner.WireX1
scan_range = args[2] if is_panel else [-200, 200]
cycles = args[3] if is_panel else 5
velocity = args[4] if is_panel else 200
bpms = args[5] if is_panel else get_wire_scans_bpms(prefix)
print "WireScan parameters: ", prefix, scan_type, scan_range, cycles, cycles, bpms
#Creating WireScanner object
print "Creating scanner..."
if prefix not in get_wire_scans():
raise Exception("Invalid wire scan: " + prefix)
scanner = WireScanner(prefix, sel, start, end, cycles, velocity, True)
raise Exception("Invalid wire scan: " + prefix)
scanner = WireScanner(prefix, scan_range, cycles, velocity, True)
scanner.set_selection(get_scan_selection(scan_type))
scanner.init()
scanner.waitValue("At start", 60000)
#List of stream channels
channels = [("w_pos", scanner.motor_bs_readback.get_name()),
channels = [("m_pos", scanner.motor_bs_readback.get_name()),
("cur_cycle", scanner.curr_cycl.get_name()),
("scanning", scanner.status_channels[0].get_name())]
@@ -38,16 +39,21 @@ for i in range (len(bpms)):
print "Starting stream..."
st = Stream("pulse_id", dispatcher)
scanner.curr_cycl.write(0)
st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the reansition to know when the finished
st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the transition to know when the finished
for c in channels:
st.addScalar(c[0], c[1], 10, 0)
st.initialize()
st.start()
st.waitCacheChange(10000) #Wait stream be running before starting scan
#Pseudo-device returning the wire position
class w_pos(Readable):
def read(self):
return scanner.get_sel_wire_pos(st.getChildren()[0].take())
#End of scan checking
scan_complete=False
cur_cycle = 1
scan_complete = None
cur_cycle = None
def check_end_scan(record, scan):
global scan_complete,cur_cycle
if record[3]<1:
@@ -61,22 +67,41 @@ def check_end_scan(record, scan):
#Metadata
set_attribute("/", "Wire Scan", prefix)
set_attribute("/", "Selection", sel)
set_attribute("/", "Range", scanner.scan_range)
set_attribute("/", "Cycles", scanner.cycles )
set_attribute("/", "Velocity", scanner.velocity )
set_attribute("/", "Scan Type", scan_type)
set_attribute("/", "Range", scan_range)
set_attribute("/", "Cycles", cycles)
set_attribute("/", "Velocity", velocity)
#Scan
try:
print "Starting scan..."
scanner.scan() #scanner.waitState(State.Busy, 60000) Not needed as stream filter will make the wait
mscan (st, st.getReadables(), -1, -1, after_read = check_end_scan)
except:
if not scanner.isReady():
print "Aborting Wire Scan"
scanner.abort()
if not scan_complete:
raise
#Scan
def do_scan():
global scan_complete, cur_cycle
scan_complete=False
cur_cycle = 1
try:
scanner.scan() #scanner.waitState(State.Busy, 60000) Not needed as stream filter will make the wait
mscan (st, [w_pos()] + st.getReadables(), -1, -1, after_read = check_end_scan)
except:
if not scanner.isReady():
print "Aborting scan"
scanner.abort()
if not scan_complete:
raise
print "Starting scan..."
try:
set_exec_pars(group=scan_type in [WireScanner.WireY1, WireScanner.WireY1] ? "y_{count}" : "x_{count}");
do_scan()
if scan_type in [WireScanner.Set1, WireScanner.Set2]:
scanner.set_selection(get_scan_selection(scan_type))
scanner.curr_cycl.write(0)
scanner.set_selection(get_scan_selection(scan_type, 1))
scanner.init()
scanner.waitValue("At start", 60000)
set_exec_pars(group="y_{count}", reset=True)
do_scan()
finally:
print "Closing scanner"
scanner.close()
+11
View File
@@ -0,0 +1,11 @@
st = Stream("ICTstream", dispatcher)
q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0)
st.initialize()
st.start()
try:
qb = create_averager(q, 5, 0.100)
r = tscan((qb), 10, 1.0)
finally:
st.close()
+25
View File
@@ -0,0 +1,25 @@
prefix = "S30CB09-DWSC440"
prefix = "SINDI01-DWSC090"
channels = [("m_pos", prefix+":ENC_1_BS"),
#("cur_cycle", prefix+":CURR_CYCL"),
# ("scanning", prefix+":SCANNING")
]
class w_pos(Readable):
def read(self):
return st.getChildren()[0].take()
st = Stream("pulse_id", dispatcher)
for c in channels:
st.addScalar(c[0], c[1], 10, 0)
st.initialize()
st.start()
try:
mscan (st, [w_pos()] + st.getReadables(), 10)
finally:
st.close()