wip
This commit is contained in:
@@ -36,7 +36,10 @@ class MotionBase:
|
||||
self.gather=gather
|
||||
self.verbose=verbose
|
||||
#ServoPeriod=0.2 #ms, Sys.ServoPeriod is dependent of !common() macro
|
||||
ServoPeriod=comm.gpascii.servo_period*1000
|
||||
if comm is None:
|
||||
ServoPeriod=.2
|
||||
else:
|
||||
ServoPeriod=comm.gpascii.servo_period*1000
|
||||
|
||||
self.meta={'srv_per':ServoPeriod,'pt2pt_time':40,'sync_flag':0,'sync_mode':2}
|
||||
self.meta.update(kwargs)
|
||||
@@ -106,6 +109,7 @@ class MotionBase:
|
||||
self.sync_prg = prg
|
||||
#download and start triggerSync code
|
||||
comm=self.comm
|
||||
if comm is None: return
|
||||
|
||||
arg=0 #argument to pass to triggerSync program
|
||||
if sync_mode==2:arg+=1 #synchronize
|
||||
@@ -144,6 +148,7 @@ class MotionBase:
|
||||
def run(self, crdId=1):
|
||||
'runs the code sync_run which has been generated with setup_sync()'
|
||||
comm = self.comm
|
||||
if comm is None: return
|
||||
gpascii = comm.gpascii
|
||||
try:
|
||||
cmd=self.sync_run
|
||||
@@ -157,6 +162,7 @@ class MotionBase:
|
||||
return
|
||||
else:
|
||||
comm = self.comm
|
||||
if comm is None: return
|
||||
gpascii = comm.gpascii
|
||||
while (True):
|
||||
val = gpascii.get_variable('Coord[{crdId}].Q[0]'.format(crdId=crdId), type_=int)
|
||||
@@ -172,7 +178,7 @@ class MotionBase:
|
||||
if ge == 0: return -1
|
||||
cnt = gpascii.get_variable('Gather.Samples', type_=int)
|
||||
try:
|
||||
cnt*=self.meta['srv_per']/(self.meta['acq_per']*self.meta['pt2pt_time'])
|
||||
cnt*=self.meta['srv_per']*self.meta['acq_per']/self.meta['pt2pt_time']
|
||||
except KeyError:
|
||||
pass
|
||||
return cnt
|
||||
@@ -184,6 +190,7 @@ class MotionBase:
|
||||
time.sleep(wait)
|
||||
if self.meta['sync_flag']&1:
|
||||
comm = self.comm
|
||||
if comm is None: return
|
||||
gpascii = comm.gpascii
|
||||
gpascii.send_block('Coord[1].Q[10]=1')
|
||||
else:
|
||||
|
||||
@@ -1254,11 +1254,11 @@ 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)))
|
||||
#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 ###
|
||||
|
||||
@@ -240,9 +240,6 @@ class DebugPlot:
|
||||
plt.show(block=False)
|
||||
|
||||
|
||||
plt.show(block=False)
|
||||
|
||||
|
||||
def plot_pos_error(self):
|
||||
rec = self.rec # yA,xA,yD,xD,trig
|
||||
ts=self.meta['srv_per']*self.meta['acq_per']
|
||||
@@ -455,7 +452,7 @@ class ShapePath(MotionBase):
|
||||
verb=self.verbose
|
||||
if verb&2:
|
||||
self.plot_points(pts)
|
||||
plt.show()
|
||||
plt.show(block=False)
|
||||
|
||||
|
||||
def gen_swissfel_points(self,flipx=False,flipy=False,ofs=(0,0),width=1000):
|
||||
@@ -480,7 +477,7 @@ class ShapePath(MotionBase):
|
||||
verb=self.verbose
|
||||
if verb&2:
|
||||
self.plot_points(pts)
|
||||
plt.show()
|
||||
plt.show(block=False)
|
||||
|
||||
def gen_rand_points(self,n=107,scale=1000,ofs=(0,0)):
|
||||
'generate random distributed points'
|
||||
@@ -500,10 +497,10 @@ class ShapePath(MotionBase):
|
||||
pts+=ofs
|
||||
self.points=pts
|
||||
|
||||
def gen_spiral_points(self,rStart=1.,rInc=.2,numSeg=4,numCir=6, ofs=(0, 0)):
|
||||
def gen_spiral_points(self,rStart=1.,rInc=.2,numSeg=4,numCir=6, phase=0, ofs=(0, 0)):
|
||||
#rInc radius increment per circle
|
||||
r=rStart+np.arange(numSeg*numCir)*(float(rInc)/numSeg)
|
||||
ang=2.*np.pi/numSeg*np.arange(numSeg*numCir)
|
||||
ang=2.*np.pi/numSeg*np.arange(numSeg*numCir)+phase*np.pi/180
|
||||
|
||||
pts=np.vstack((np.sin(ang)*r,np.cos(ang)*r)).T
|
||||
pts+=ofs
|
||||
@@ -586,7 +583,7 @@ class ShapePath(MotionBase):
|
||||
|
||||
if verb&2:
|
||||
DebugPlot.plot_points(pts)
|
||||
plt.show()
|
||||
plt.show(block=False)
|
||||
self.points=pts
|
||||
|
||||
|
||||
@@ -713,7 +710,7 @@ class ShapePath(MotionBase):
|
||||
verb=self.verbose
|
||||
if verb&16:
|
||||
dp=DebugPlot(self);self.pvt=dp.plot_gen_pvt(pv)
|
||||
plt.show()
|
||||
plt.show(block=False)
|
||||
|
||||
pv[1:-1, (2, 3)]*=CoordFeedTime #scaling for Deltatau
|
||||
prg.append(' linear abs')
|
||||
@@ -857,32 +854,37 @@ if __name__=='__main__':
|
||||
#sp.gen_closed_shifted()
|
||||
#sp.gen_swissmx_points(width=1000,ofs=(-500,0))
|
||||
#sp.gen_swissfel_points(width=1000,ofs=(-500,0))
|
||||
sp.gen_rand_points(n=200, scale=1000);sp.sort_points(xy=False)
|
||||
sp.gen_rand_points(n=2000, scale=1000);sp.sort_points(xy=False)
|
||||
#sp.gen_swissmx_points(width=1000, ofs=(-500, 0));
|
||||
#sp.gen_spiral_points(rStart=100,rInc=10,numSeg=4,numCir=60, ofs=(0, 0))
|
||||
#sp.gen_spiral_points(rStart=100,rInc=130,numSeg=4,numCir=2, ofs=(0, 0))
|
||||
#sp.gen_grid_points(w=10,h=10,pitch=100,rnd=0,ofs=(0,0));sp.sort_points(False);
|
||||
#sp.gen_grid_points(w=1,h=10,pitch=100,rnd=0,ofs=(0,0))
|
||||
#sp.gen_spiral_points(rStart=100,rInc=20,numSeg=8,numCir=32, ofs=(0, 0))
|
||||
#sp.gen_spiral_points(rStart=100,rInc=10,numSeg=2,numCir=32, phase=45, ofs=(0, 0))
|
||||
#sp.gen_spiral_points(rStart=100,rInc=10,numSeg=4,numCir=32, ofs=(0, 0))
|
||||
#sp.gen_closed_shifted()
|
||||
|
||||
sp.setup_gather(acq_per=1)
|
||||
gtMaxLn=116508;ovhdTime=100
|
||||
acq_per=int(np.ceil((sp.meta['pt2pt_time']*sp.points.shape[0]+ovhdTime)/(gtMaxLn*sp.meta['srv_per'])))
|
||||
sp.setup_gather(acq_per=acq_per)
|
||||
sp.setup_sync(verbose=args.verbose&32)
|
||||
|
||||
sp.setup_coord_trf() # reset to shape path system
|
||||
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1,dwell=10)
|
||||
#sp.meta['pt2pt_time']=10 #put between setup_sync and setup_motion to have more motion points than FEL syncs
|
||||
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1.,dwell=10)
|
||||
#sp.setup_motion(fnPrg=fn + '.prg', mode=1, scale=1,dwell=10)
|
||||
#sp.setup_motion(fnPrg=fn + '.prg', mode=1, scale=0,dwell=10)
|
||||
sp.homing() #homing if needed
|
||||
sp.run() #start motion program
|
||||
sp.wait_armed() # wait until motors are at first position
|
||||
sp.trigger(0.5) #send a start trigger (if needed) ater given time
|
||||
while True:
|
||||
p=sp.progress()
|
||||
if p<0: break
|
||||
print('progress %d'%p);time.sleep(.1)
|
||||
sp.gather_upload(fnRec=fn+'.npz')
|
||||
dp=DebugPlot(sp);dp.plot_gather(mode=11)
|
||||
if not comm is None:
|
||||
while True:
|
||||
p=sp.progress()
|
||||
if p<0: break
|
||||
print('progress %d/%d'%(p,sp.points.shape[0]));time.sleep(.1)
|
||||
sp.gather_upload(fnRec=fn+'.npz')
|
||||
dp=DebugPlot(sp);dp.plot_gather(mode=11)
|
||||
|
||||
print('done')
|
||||
plt.show(block=False)
|
||||
|
||||
Reference in New Issue
Block a user