From 1c776907119158e3b04226bf8843bccbe4463c75 Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Fri, 30 Nov 2018 15:14:06 +0100 Subject: [PATCH] fixes --- Readme.md | 26 ++++++ python/helicalscan.py | 191 ++++++++++++++++++++++++------------------ python/shapepath.py | 2 +- 3 files changed, 138 insertions(+), 81 deletions(-) diff --git a/Readme.md b/Readme.md index f8d7354..0b02bdb 100644 --- a/Readme.md +++ b/Readme.md @@ -1169,4 +1169,30 @@ Try to find encoder count loss Gate3[0].EncClockDiv=2 Gate3[1].EncClockDiv=2 +``` + +Helicalscan setup +----------------- +``` +calcParam( + x=((-34.05489905551743, 208.10204385266277, -606.4416461908648), + (22.139508829306088, 158.83214548238513, -618.6408606756819)), + y=(1700.0, 1252.0231362790232), + z=((-1200.0, -2000.0000000000005, -1900.0000000000005), + (-1200.0, -2000.0000000000005, -1800.0000000000002))) + +cpx X0 Z0 B0 Y1700.0 +cpx X0 Z0 B120000 Y1700.0 +cpx X0 Z0 B240000 Y1700.0 + +cpx X0 Z0 B0 Y1252.0 +cpx X0 Z0 B120000 Y1252.0 +cpx X0 Z0 B240000 Y1252.0 + +send 1"fwd_inp(%f) %f %f %f %f\\n",D0,{qCX},{qCZ},{qW},{qFY} +send 1"fwd_res %f %f %f %f\\n",{DX},{DZ},{W},{Y} +send 1"inv_inp(%f) %f %f %f %f\\n",D0,{DX},{DZ},{W},{Y} +send 1"inv_res %f %f %f %f\\n",{qCX},{qCZ},{qW},{qFY} + + ``` diff --git a/python/helicalscan.py b/python/helicalscan.py index 58bb3f8..3c262ba 100755 --- a/python/helicalscan.py +++ b/python/helicalscan.py @@ -26,6 +26,13 @@ verbose bits: 4 list program #4 upload progress #8 plot gather path + + modes: + 0: test scratch mode + 1: test find rotation center + 2: test param calculation and display the gui + 3: load recorded data, check param calculation not changed display in the gui + 4: load recorded data, display in the interactive_anim gui (default) ''' #motors CX CZ RY FY @@ -770,10 +777,11 @@ class HelicalScan(MotionBase): // 4 5 3 1 &1 a +#1->0 +#2->0 +#3->0 #4->0 #5->0 -#3->0 -#1->0 #4->I #5->I @@ -791,7 +799,7 @@ Motor[5].MaxSpeed=8 subsParam=dict(map(lambda k, i, v: (k + '_' + str(i), v), s * sh[0], c, pbParam.reshape(-1))) subsParam['d2r']=d2r/1000. subsParam['r2d']=1000./d2r - subsParam['cmt']='//'#'' + subsParam['cmt']='//'#'//'#'' subs={'qCX':'L4', 'qCZ':'L5', 'qW':'L3', 'qFY':'L1', @@ -1104,18 +1112,91 @@ close if __name__=='__main__': def run_test(args): - test=args.test + mode=args.mode #args.host=None - if args.host is None: + if args.host is None or mode in(3,4): comm=gather=None else: comm = PPComm(host=args.host) gather = Gather(comm) gpascii = comm.gpascii hs=HelicalScan(comm, gather, args.verbose) + if mode==0: + # gpasci: #1,4,5p // y,-x ,-z + # 0deg 256.7 -762.5 -396.4 + # 120deg 258.5 731.7 -1896.9 + # ... + # &1p + # cpx X0 Z0 B0 Y258 + # cpx X0 Z0 B120000 Y258 - if test==1: + hs.calcParam(x=((-1154.4, 216.3, -250.7), (-1330.2, 340.9, -230.4)), + y=(1405.7, 1019.2), + z=((-1309.6, -1010.9, -2410.3), (-1219.4, -918.8, -2510.4))) + + ### use simulation motors ### + # os.chdir(os.path.join(os.path.dirname(__file__),'../cfg')) + # 'sim_8_motors.cfg' + # ['$$$***','!common()','!SAR-EXPMX1()','#1..7j/','enable plc 1','Motor[1].MaxSpeed=25','Motor[2].MaxSpeed=25']) + # raw_input('press return when homed') + + ### hs.calcParam() ### + # 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") + + # find /sf/bernina/data/p17592/res/ -name '*.cmd' + 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.gen_prog(mode=-1) + # hs.gen_prog(mode=0,cntHor=1,cntVert=3,wRng=(120000,120000)) + # hs.gen_prog(mode=0,cntHor=1) + # hs.gen_prog(mode=0) + # hs.gen_prog(mode=0,cntHor=1,cntVert=5,wRng=(120000,120000)) + # hs.gen_prog(mode=1,cntHor=1,cntVert=5,wRng=(120000,120000),pt2pt_time=100) + # hs.gen_prog(mode=1,cntHor=1,cntVert=5,wRng=(120000,120000),pt2pt_time=100,smt=0) + # hs.gen_prog(mode=1,cntHor=1,cntVert=5,wRng=(0,360000)) + # hs.gen_prog(mode=1,cntHor=1,cntVert=5,hRng=(-.3,.3),wRng=(0,360000),smt=1) + # hs.gen_prog(mode=1,cntHor=7,cntVert=2,hRng=(-3,3),wRng=(120000,120000),smt=0) + # hs.gen_prog(mode=1,cntHor=3,cntVert=6,hRng=(-5,5),wRng=(00,120000),smt=0,pt2pt_time=10) + # hs.gen_prog(mode=0,cntHor=3,cntVert=10,hRng=(-5,5),wRng=(0,120000)) + # hs.gen_prog(mode=0,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000)) + # hs.gen_prog(mode=1,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000),smt=0,pt2pt_time=300) + #hs.setup_motion(mode=1, cntHor=5, cntVert=15, hRng=(-150, 150), wRng=(0, 120000), smt=0, pt2pt_time=200) + hs.setup_motion(mode=1, cntHor=10, cntVert=20, hRng=(-300, 300), wRng=(0, 100000), smt=0, pt2pt_time=40) + # hs.gen_prog(mode=1,cntHor=5,cntVert=25,hRng=(-100,100),wRng=(0,120000),smt=0,pt2pt_time=40) + # hs.gen_prog(mode=1,cntHor=3,cntVert=20,hRng=(-5,5),wRng=(0,1200),smt=0,pt2pt_time=200) + # hs.gen_prog(mode=1, cntHor=2, cntVert=2, wRng=(0, 360000), smt=0) + # hs.gen_prog(mode=1) + # hs.gen_prog(mode=1,pt2pt_time=100,cnt=1,cntVert=35,cntHor=7,hRng=(-.3,.3),wRng=(0,360000*3),yRng=(6.2,2.3)) + # hs.gen_prog(mode=1,pt2pt_time=100,cnt=1,cntVert=10,cntHor=3,hRng=(-30,30),wRng=(0,36000),yRng=(-50,-100)) + # hs.gen_prog(mode=1,cntHor=7,cntVert=2,hRng=(-100,50),wRng=(000,10000),smt=0) + + hs.run() + print('wait until gather finished:') + fn = '/tmp/helicalscan' + hs.gather_upload(fn + '.npz') + hs.load_rec(fn + '.npz') + hsg = HelicalScanGui(hs) + hsg.show_pos() + hsg.show_vel() + hsg.interactive_anim() + + if mode==1: ### test find rotation center ### HelicalScanTests.test_find_rot_ctr(n=32. ,per=1.,bias=2.31,ampl=4.12,phi=0*d2r) HelicalScanTests.test_find_rot_ctr(n=32. ,per=1.,bias=2.31,ampl=4.12,phi=30.*d2r) @@ -1123,14 +1204,17 @@ if __name__=='__main__': HelicalScanTests.test_find_rot_ctr(n=5. ,per=1.,bias=7.25,ampl=6.51,phi=-124.6*d2r) return - elif test==2: + elif mode==2: ### test param calculation and display the gui### HelicalScanTests.calcParamSim(hs) - hs.setup_motion(mode=1,cntHor=5,cntVert=15,hRng=(-50,50),wRng=(0,120000),smt=0,pt2pt_time=200) - hs.setup_coord_trf() - hs.setup_sync(mode=0) # None: no sync at all mode=1: sync on timing UserFlag hs.setup_gather() + # setup_sync(self, crdId=1, prgId=2, plcId=2, mode=0, **kwargs): + # sp.setup_sync() #no sync at all + # sp.setup_sync(mode=1) #sync with timing system (PROG) + hs.setup_sync(mode=2) # sync with timing system and PLC to sync speed (PROG) + hs.setup_coord_trf() + hs.setup_motion(mode=1,cntHor=5,cntVert=15,hRng=(-50,50),wRng=(0,120000),smt=0,pt2pt_time=200) hs.run() print('wait until gather finished:') fn = '/tmp/helicalscan' @@ -1143,12 +1227,13 @@ if __name__=='__main__': hsg=HelicalScanGui(hs);hsg.interactive_anim(manip=manip) return - elif test==3: - ### load recorded data, check param calculation not changed and display in the gui### - fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/helicalscan' - hs.load_rec(fn+'.npz') + elif mode==3: + ### load recorded data, #check param calculation not changed display in the gui### + fn=args.other[0] + hs.load_rec(fn) paramRec=hs.param - 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/helical.cmd") + fh = open(fn[-4]+'_helical_debug.cmd') s=fh.read();s=s.replace('calcParam','hs.calcParam') eval(s) assert (abs(paramRec-hs.param).max()<1E-10) @@ -1158,68 +1243,14 @@ if __name__=='__main__': hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy(manip=manip) hsg=HelicalScanGui(hs);hsg.interactive_dx_dz_w_y(manip=manip) return - - #gpasci: #1,4,5p // y,-x ,-z - # 0deg 256.7 -762.5 -396.4 - #120deg 258.5 731.7 -1896.9 - #... - #&1p - #cpx X0 Z0 B0 Y258 - #cpx X0 Z0 B120000 Y258 - - hs.calcParam(x = ((-1154.4, 216.3, -250.7), ( -1330.2, 340.9, -230.4)), - y = (1405.7,1019.2), - z = ((-1309.6, -1010.9, -2410.3),( -1219.4, -918.8, -2510.4))) - - - ### use simulation motors ### - #os.chdir(os.path.join(os.path.dirname(__file__),'../cfg')) - #'sim_8_motors.cfg' - #['$$$***','!common()','!SAR-EXPMX1()','#1..7j/','enable plc 1','Motor[1].MaxSpeed=25','Motor[2].MaxSpeed=25']) - # raw_input('press return when homed') - - ### hs.calcParam() ### - fh=open("/sf/bernina/config/swissmx/exchange/helical.cmd") - #fh=open("/sf/bernina/config/swissmx/exchange/helical_neg.cmd") - s=fh.read();s=s.replace('calcParam','hs.calcParam') - eval(s) - - hs.setup_coord_trf() - hs.setup_sync(mode=0) # None: no sync at all mode=1: sync on timing UserFlag - hs.setup_gather() - - #hs.gen_prog(mode=-1) - #hs.gen_prog(mode=0,cntHor=1,cntVert=3,wRng=(120000,120000)) - #hs.gen_prog(mode=0,cntHor=1) - #hs.gen_prog(mode=0) - #hs.gen_prog(mode=0,cntHor=1,cntVert=5,wRng=(120000,120000)) - #hs.gen_prog(mode=1,cntHor=1,cntVert=5,wRng=(120000,120000),pt2pt_time=100) - #hs.gen_prog(mode=1,cntHor=1,cntVert=5,wRng=(120000,120000),pt2pt_time=100,smt=0) - #hs.gen_prog(mode=1,cntHor=1,cntVert=5,wRng=(0,360000)) - #hs.gen_prog(mode=1,cntHor=1,cntVert=5,hRng=(-.3,.3),wRng=(0,360000),smt=1) - #hs.gen_prog(mode=1,cntHor=7,cntVert=2,hRng=(-3,3),wRng=(120000,120000),smt=0) - #hs.gen_prog(mode=1,cntHor=3,cntVert=6,hRng=(-5,5),wRng=(00,120000),smt=0,pt2pt_time=10) - #hs.gen_prog(mode=0,cntHor=3,cntVert=10,hRng=(-5,5),wRng=(0,120000)) - #hs.gen_prog(mode=0,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000)) - #hs.gen_prog(mode=1,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000),smt=0,pt2pt_time=300) - hs.setup_motion(mode=1,cntHor=5,cntVert=15,hRng=(-150,150),wRng=(0,120000),smt=0,pt2pt_time=200) - #hs.gen_prog(mode=1,cntHor=5,cntVert=25,hRng=(-100,100),wRng=(0,120000),smt=0,pt2pt_time=40) - #hs.gen_prog(mode=1,cntHor=3,cntVert=20,hRng=(-5,5),wRng=(0,1200),smt=0,pt2pt_time=200) - #hs.gen_prog(mode=1, cntHor=2, cntVert=2, wRng=(0, 360000), smt=0) - #hs.gen_prog(mode=1) - #hs.gen_prog(mode=1,pt2pt_time=100,cnt=1,cntVert=35,cntHor=7,hRng=(-.3,.3),wRng=(0,360000*3),yRng=(6.2,2.3)) - #hs.gen_prog(mode=1,pt2pt_time=100,cnt=1,cntVert=10,cntHor=3,hRng=(-30,30),wRng=(0,36000),yRng=(-50,-100)) - #hs.gen_prog(mode=1,cntHor=7,cntVert=2,hRng=(-100,50),wRng=(000,10000),smt=0) - - hs.run() - print('wait until gather finished:') - fn='/tmp/helicalscan' - hs.gather_upload(fn+'.npz') - hs.load_rec(fn+'.npz') - hsg=HelicalScanGui(hs) - hsg.show_pos() - hsg.show_vel() - hsg.interactive_anim() + elif mode==4: + ### load recorded data, display in the interactive_anim gui### + fn=args.other[0] + hs.load_rec(fn) + hsg = HelicalScanGui(hs) + hsg.show_pos() + hsg.interactive_anim(manip=False) + return from optparse import OptionParser, IndentedHelpFormatter @@ -1239,8 +1270,8 @@ if __name__=='__main__': 'main command line interpreter function' #usage: gpasciiCommunicator.py --host=PPMACZT84 myPowerBRICK.cfg (h, t)=os.path.split(sys.argv[0]);cmd='\n '+(t if len(h)>3 else sys.argv[0])+' ' - exampleCmd=('-n', - '-v15' + exampleCmd=('-m0', + '/sf/bernina/data/p17592/res/20181130/helicaltest/lyso001/lyso001_0062.npz ' ) epilog=__doc__+''' Examples:'''+''.join(map(lambda s:cmd+s, exampleCmd))+'\n ' @@ -1250,7 +1281,7 @@ Examples:'''+''.join(map(lambda s:cmd+s, exampleCmd))+'\n ' parser.add_option('-v', '--verbose', type="int", dest='verbose', help='verbosity bits (see below)', default=255) parser.add_option('--host', help='hostname', default='SAR-CPPM-EXPMX1') - parser.add_option('-t','--test', type="int", default=None) + parser.add_option('-m','--mode', type="int", default=4) (args, other)=parser.parse_args() args.other=other diff --git a/python/shapepath.py b/python/shapepath.py index 56a5460..c925133 100755 --- a/python/shapepath.py +++ b/python/shapepath.py @@ -632,8 +632,8 @@ if __name__=='__main__': #setup_sync(self, crdId=1, prgId=2, plcId=2, mode=0, **kwargs): #sp.setup_sync() #no sync at all #sp.setup_sync(mode=1) #sync with timing system (PROG) - sp.setup_coord_trf() # reset to shape path system sp.setup_sync(mode=2) #sync with timing system and PLC to sync speed (PROG) + sp.setup_coord_trf() # reset to shape path system #sp.gen_grid_points(w=2,h=2,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=10,acq_per=1) #sp.gen_swissmx_points(width=1000,ofs=(-500,0));sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40,acq_per=1)