update gui and triggering: speed sync works!
This commit is contained in:
@@ -184,9 +184,14 @@ class ShapePath(MotionBase):
|
||||
1. generates program <prgId> and saves to fnPrg
|
||||
the type of generated program is defined by <mode>
|
||||
2. runs the program on the deltatau
|
||||
|
||||
mode=-1 jog a 10mm square
|
||||
mode=0 linear motion
|
||||
mode=1 pvt motion
|
||||
mode=2 spline motion
|
||||
kwargs:
|
||||
acq_per : acquire period: acquire data all acq_per servo loops (default=1)
|
||||
pt2pt_time : time to move from one point to the next point
|
||||
sync_frq : synchronization mark all n points
|
||||
'''
|
||||
prg=['close all buffers','open prog %d'%(prgId)]
|
||||
comm=self.comm
|
||||
@@ -229,6 +234,10 @@ class ShapePath(MotionBase):
|
||||
cnt=kwargs['cnt'] #move path multiple times
|
||||
except KeyError:
|
||||
cnt=1
|
||||
try:
|
||||
sync_frq=kwargs['sync_frq'] #synchronization mark all n points
|
||||
except KeyError:
|
||||
sync_frq=10
|
||||
try:
|
||||
pt=self.ptsCorr
|
||||
except AttributeError:
|
||||
@@ -259,7 +268,10 @@ class ShapePath(MotionBase):
|
||||
prg.append('N100:')
|
||||
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 Y%g:%g'%tuple(pv[idx,(0,2,1,3)]))
|
||||
prg.append('Coord[1].Q[0]=%d' % (idx))
|
||||
prg.append('X%g Y%g' % tuple(pv[-1, (0,1)]))
|
||||
if cnt>1:
|
||||
prg.append('dwell 10')
|
||||
@@ -273,6 +285,8 @@ class ShapePath(MotionBase):
|
||||
prg.append('}')
|
||||
else:
|
||||
prg.append('dwell 1000')
|
||||
if sync_frq is not None:
|
||||
prg.append('Coord[1].Q[0]=-1')
|
||||
prg.append('Gather.Enable=0')
|
||||
elif mode==2: #### spline motion
|
||||
try:
|
||||
@@ -437,28 +451,30 @@ class ShapePath(MotionBase):
|
||||
idxTrigger = np.where(np.diff(idxTrigger) == 1)[0] + 1
|
||||
idxInPos = [] # first point at idx 0
|
||||
try: # find approximate distance of 2 points
|
||||
rng = idxTrigger[2] - idxTrigger[1]
|
||||
rng = idxTrigger[2]-idxTrigger[1]
|
||||
except IndexError:
|
||||
rng = int(lenRec / lenPts)
|
||||
idx = rng / 2
|
||||
rng = int(lenRec/lenPts)
|
||||
idx = rng/2
|
||||
|
||||
for i in range(lenPts):
|
||||
l = rec[idx:idx + rng, (3, 2)] - pts[i, :]
|
||||
l2 = l[:, 0] ** 2 + l[:, 1] ** 2
|
||||
ofs = l2.argmin()
|
||||
print(l2[ofs])
|
||||
idx += ofs
|
||||
l=rec[idx:idx+rng,(3,2)]-pts[i,:]
|
||||
l2=l[:,0]**2+l[:,1]**2
|
||||
ofs=l2.argmin()
|
||||
#print(l2[ofs])
|
||||
idx+=ofs
|
||||
idxInPos.append(idx)
|
||||
idx += rng / 2
|
||||
idx+= rng/2
|
||||
|
||||
idxInPos = np.array(idxInPos)
|
||||
jitter=idxInPos-idxTrigger[:idxInPos.shape[0]]
|
||||
jitter=idxTrigger[:idxInPos.shape[0]]-idxInPos
|
||||
fig = plt.figure('trigger jitter')
|
||||
ax = fig.add_subplot(1, 1, 1)
|
||||
hl = []
|
||||
hl += ax.plot(jitter*ts, 'b-',label='jitter')
|
||||
ax.xaxis.set_label_text('position idx')
|
||||
ax.yaxis.set_label_text('jitter (ms)')
|
||||
ax.yaxis.set_label_text('jitter motion (ms)')
|
||||
print('scaling of DesTimeBase: %f'%(float(idxInPos[-1])/idxTrigger[idxInPos.shape[0]-1]))
|
||||
|
||||
|
||||
|
||||
plt.show()
|
||||
@@ -623,8 +639,8 @@ if __name__=='__main__':
|
||||
sp.setup_gather(acq_per=2)
|
||||
#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 (PLC)
|
||||
sp.setup_sync(mode=2) #sync with timing system (PROG)
|
||||
#sp.setup_sync(mode=1) #sync with timing system (PROG)
|
||||
sp.setup_sync(mode=2) #sync with timing system and PLC to sync speed (PROG)
|
||||
|
||||
#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)
|
||||
@@ -647,7 +663,7 @@ if __name__=='__main__':
|
||||
sp.run()
|
||||
trigger(0.5)
|
||||
sp.gather_upload(fnRec=fn+'.npz')
|
||||
sp.plot_gather()
|
||||
sp.plot_gather(mode=8)
|
||||
|
||||
|
||||
# cfg={"points": [[100,523],[635,632],[756,213]],"sequencer":[sort_points,move_trj+')']}
|
||||
|
||||
Reference in New Issue
Block a user