update gui and triggering

This commit is contained in:
2018-11-21 10:57:43 +01:00
parent 554fd8e1ca
commit 2e534f306e
2 changed files with 132 additions and 68 deletions

View File

@@ -390,6 +390,8 @@ class ShapePath(MotionBase):
except AttributeError as e:
print('plot_gather(): '+str(e)+': no data acquired yet')
return
ts=meta['timebase']
t=np.arange(rec.shape[0],dtype=np.uint32)
if mode&1:
fig=plt.figure('trajectory')
ax = fig.add_subplot(1,1,1)
@@ -414,10 +416,10 @@ class ShapePath(MotionBase):
err=np.sqrt(errx**2+erry**2)
hl = []
hl += ax.plot(errx, 'b-',label='x-error')
hl += ax.plot(erry, 'g-',label='y-error')
hl += ax.plot(err, 'r-',label='error')
ax.xaxis.set_label_text('datapoint (timebase: %g ms per data point)'%meta['timebase'])
hl += ax.plot(t,errx,'b-',label='x-error')
hl += ax.plot(t,erry,'g-',label='y-error')
hl += ax.plot(t,err, 'r-',label='error')
ax.xaxis.set_label_text('ms (timebase: %g ms per data point)'%ts)
ax.yaxis.set_label_text('pos-error um')
legend = ax.legend(loc='upper right', shadow=True)
print('average error x %g um, y %g um, %g um'%(np.abs(errx).mean(),np.abs(erry).mean(),err.mean()))
@@ -426,6 +428,39 @@ class ShapePath(MotionBase):
self.bode_plot(xy=(3,1),mode=31,db=True) # FX
self.bode_plot(xy=(2,0),mode=31,db=True) # FY
if mode&8:
lenRec = rec.shape[0]
lenPts = pts.shape[0]
# idxTrigger=np.hstack(([0],rec[:,4]))
# doc.idxTrigger=idxTrigger=np.where(np.diff(idxTrigger)==1)[0]
idxTrigger = rec[:, 4]
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]
except IndexError:
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
idxInPos.append(idx)
idx += rng / 2
idxInPos = np.array(idxInPos)
jitter=idxInPos-idxTrigger[:idxInPos.shape[0]]
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)')
plt.show()
def bode_plot(self,xy=(0,1),mode=25,db=True):
@@ -593,11 +628,12 @@ if __name__=='__main__':
#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)
sp.gen_grid_points(w=30,h=30,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40)
#sp.gen_grid_points(w=30,h=30,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40)
#sp.gen_grid_points(w=200,h=200,pitch=50,rnd=.2);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40)
#sp.gen_grid_points(w=2,h=20,pitch=50,rnd=0);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=10,acq_per=1)
#sp.gen_rand_points(n=500, scale=1000);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=10,acq_per=1)
sp.gen_grid_points(w=20,h=20,pitch=10,rnd=0);sp.sort_points(xy);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40)
#>>>setup gather and sync<<<