This commit is contained in:
2019-02-26 11:35:35 +01:00
parent 46aab5ae36
commit 966134a06d
9 changed files with 1264 additions and 41 deletions

View File

@@ -62,7 +62,8 @@ verbose bits:
#points:
#dx,dz,w,fy -> pb coord. be aware of inverted dx,dz signs
from __future__ import print_function
#from __future__ import absolute_import,division,generators,nested_scopes,print_function,unicode_literals,with_statement
import os, sys, json,re
import numpy as np
import matplotlib as mpl
@@ -644,8 +645,9 @@ class HelicalScanTests():
class HelicalScan(MotionBase):
def __init__(self,comm, gather, verbose):
MotionBase.__init__(self,comm, gather, verbose)
def __init__(self, comm, gather, verbose, **kwargs):
if comm==None: return
MotionBase.__init__(self, comm, gather, verbose, **kwargs)
def load_rec(self,fn_npz='/tmp/helicalscan.npz'):
try:
@@ -849,12 +851,17 @@ class HelicalScan(MotionBase):
if comm is None:return
gt=self.gather
gt.set_phasemode(False)
#gt.set_address("Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos")
gt.set_address("Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos","Gate3[1].Chan[1].UserFlag")
#up to now the trigger is not saved
#if self.meta['sync_flag']&2:
# address=("Motor[4].ActPos", "Motor[5].ActPos", "Motor[3].ActPos", "Motor[1].ActPos","Coord[1].Q[11]")
#else:
# address=("Motor[4].ActPos", "Motor[5].ActPos", "Motor[3].ActPos", "Motor[1].ActPos","Gate3[1].Chan[1].UserFlag")
address=("Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos")
gt.set_address(*address)
gt.set_property(MaxSamples=1000000, Period=acq_per)
ServoPeriod= .2 #0.2ms #Sys.ServoPeriod is dependent of !common() macro
#ServoPeriod=comm.gpascii.servo_period
self.meta = {'timebase': ServoPeriod*acq_per}
self.meta.update({'acq_per':acq_per,'address':address})
def setup_coord_trf(self,fnCrdTrf='/tmp/coordTrf.cfg'):
param=self.param
@@ -1107,6 +1114,7 @@ close
yRng = kwargs.get('yRng', self.param[:,1])
pt2pt_time = kwargs.get('pt2pt_time', 100)
smt = kwargs.get('smt', 1) # SegMoveTime, default = 1ms -> velocity calc not yet 100% correct (smt=0 not 100% working)
dwell = kwargs.get('dwell', 100) # wait time at end of motion
numPt=cntVert*cntHor
pt=np.zeros((numPt,4))
@@ -1147,8 +1155,6 @@ close
prg.append(' Coord[1].SegMoveTime=%d'%smt) #to calculate every 1 ms the inverse kinematics
prg.append(' pvt%g abs'%pt2pt_time) #100ms to next position
for idx in range(1,pv.shape[0]):
if sync_frq is not None and idx%sync_frq==0:
prg.append('Coord[1].Q[0]=%d'%(idx))
prg.append(' X%g:%g Z%g:%g B%g:%g Y%g:%g' % tuple(pv[idx, (0,4,1,5,2,6,3,7)]))
#prg.append('Y%g:%g' % tuple(pv[idx, (5, 7)]))
#prg.append('B%g:%g' %(idx*1000,0))
@@ -1159,14 +1165,11 @@ close
prg.append(' {')
prg.append(' linear abs')
prg.append(' X%g Z%g B%g Y%g' % tuple(pv[0, (0, 1, 2, 3)]))
prg.append(' dwell 100')
prg.append(' dwell %d' % dwell)
prg.append(' goto 100')
prg.append(' }')
else:
prg.append(' dwell 1000')
if sync_frq is not None:
prg.append(' Coord[1].Q[0]=-1')
prg.append(' Coord[1].Q[1]=0')
prg.append('dwell %d' % dwell)
prg.append(' Gather.Enable=0')
prg.append('close')
#prg.append('&1\nb%dr\n'%prgId)
@@ -1188,6 +1191,10 @@ close
gt=self.gather
gt.wait_stopped(verbose=True)
self.rec=rec=gt.upload()
channels=self.meta['address']
channels = ["Motor[4].HomePos", "Motor[5].HomePos", "Motor[3].HomePos", "Motor[1].HomePos"]
ofs = np.ndarray(len(channels))
for i, v in enumerate(channels):
@@ -1208,7 +1215,22 @@ if __name__=='__main__':
comm = PPComm(host=args.host)
gather = Gather(comm)
gpascii = comm.gpascii
hs=HelicalScan(comm, gather, args.verbose)
# direct start
#hs=HelicalScan(comm, gather, args.verbose,sync_mode=0)
#simulated start and frame trigger no sync
#hs=HelicalScan(comm, gather, args.verbose,sync_mode=1,sync_flag=3)
#simulated start and frame trigger with sync
#hs=HelicalScan(comm, gather, args.verbose,sync_mode=2,sync_flag=3)
#simulated start real frame trigger no sync
#hs=HelicalScan(comm, gather, args.verbose,sync_mode=1,sync_flag=1)
#simulated start real frame trigger with sync
hs=HelicalScan(comm, gather, args.verbose,sync_mode=2,sync_flag=1)
if mode==0:
# gpasci: #1,4,5p // y,-x ,-z
# 0deg 256.7 -762.5 -396.4
@@ -1222,6 +1244,13 @@ if __name__=='__main__':
y=(1405.7, 1019.2),
z=((-1309.6, -1010.9, -2410.3), (-1219.4, -918.8, -2510.4)))
hs.calcParam(x=((-70.25682272433501, 287.48437780001825, -477.99870973215764),
(-41.466601738723284, 274.71565975031103, -504.9508517714285)),
y=(1207.6326052816642, 1704.2138281362475), z=(
(-1196.2847548574225, -1686.284754857423, -1686.284754857423),
(-1196.2847548574225, -1686.284754857423, -1686.284754857423)))
### use simulation motors ###
# os.chdir(os.path.join(os.path.dirname(__file__),'../cfg'))
# 'sim_8_motors.cfg'
@@ -1232,22 +1261,21 @@ if __name__=='__main__':
# fh=open("/sf/bernina/config/swissmx/exchange/helical.cmd")
# fh=open("/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/helical.cmd")
#fh = open("/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/lyso001_0063_helical_debug.cmd")
fh = open("/sf/bernina/data/p17592/res/20181130/helicaltest/lyso005/lyso005_0072_helical_debug.cmd")
#fh = open("/sf/bernina/data/p17592/res/20181130/helicaltest/lyso005/lyso005_0072_helical_debug.cmd")
# find /sf/bernina/data/p17592/res/ -name '*.cmd'
s = fh.read();
s = s.replace('calcParam', 'hs.calcParam')
eval(s)
#s = fh.read();
#s = s.replace('calcParam', 'hs.calcParam')
#eval(s)
# &1p
# cpx X0 Z0 B0 Y258
# cpx X0 Z0 B120000 Y258
hs.setup_coord_trf()
hs.setup_sync(mode=0) # None: no sync at all mode=1: sync on timing UserFlag
hs.setup_gather()
hs.setup_gather(acq_per=1)
hs.setup_sync(verbose=args.verbose & 32)
hs.setup_coord_trf() # reset to shape path system
# hs.gen_prog(mode=-1)
# hs.gen_prog(mode=0,cntHor=1,cntVert=3,wRng=(120000,120000))
@@ -1274,6 +1302,8 @@ if __name__=='__main__':
# hs.gen_prog(mode=1,cntHor=7,cntVert=2,hRng=(-100,50),wRng=(000,10000),smt=0)
hs.run()
hs.wait_armed() # wait until motors are at first position
hs.trigger(0.5) # send a start trigger (if needed) ater given time
print('wait until gather finished:')
fn = '/tmp/helicalscan'
hs.gather_upload(fn + '.npz')