bugfixing
This commit is contained in:
@@ -83,10 +83,10 @@ class ShapePath:
|
||||
#cfg = {"points": [[0, 0],[100, 0],[200, 0],[300, 0],[400, 0],[400, 100],[300, 100],[200, 100],[100, 100],[0, 100],[10, 200],[100, 200],[200, 200],[300, 200],[400, 200],[410, 300],[300, 300],[200, 300],[100, 300],[0, 300],[0, 400],[100, 400],[200, 400],[300, 400],[400, 400]],"sequencer": ['gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=0)', 'plot_gather("'+fn+'.npz")']}
|
||||
#cfg = {"sequencer": ['gen_grid_points(w=2,h=2,pitch=10000,rnd=0)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=-1)', 'plot_gather("'+fn+'.npz")']}
|
||||
#cfg = {"sequencer": ['gen_grid_points(w=2,h=2,pitch=10000,rnd=0)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=1,pt2pt_time=1000)', 'plot_gather("'+fn+'.npz")']}
|
||||
#cfg = {"sequencer": ['gen_grid_points(w=20,h=20,pitch=100,rnd=0.2)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=1,pt2pt_time=10)', 'plot_gather("'+fn+'.npz")']}
|
||||
cfg = {"sequencer": ['gen_grid_points(w=20,h=20,pitch=100,rnd=0.2)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=1,pt2pt_time=10,acq_per=10)', 'plot_gather("'+fn+'.npz")']}
|
||||
#cfg = {"sequencer": ['gen_rand_points(n=400, scale=1000)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=1,pt2pt_time=10)', 'plot_gather("'+fn+'.npz")']}
|
||||
#cfg = {"sequencer": ['gen_grid_points(w=5,h=5,pitch=100,rnd=0.2)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=2,pt2pt_time=10)', 'plot_gather("'+fn+'.npz")']}
|
||||
cfg = {"sequencer":['gen_rand_points(n=400, scale=1000)','sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=1,pt2pt_time=100)','plot_gather("'+fn+'.npz")']}
|
||||
#cfg = {"sequencer":['gen_rand_points(n=400, scale=1000)','sort_points()','gen_prog(file="'+fn+'.prg",host="SAROP11-CPPM-MOT6871",mode=1,pt2pt_time=10)','plot_gather("'+fn+'.npz")']}
|
||||
|
||||
self.cfg=dotdict(cfg)
|
||||
self.args=args
|
||||
@@ -124,10 +124,16 @@ class ShapePath:
|
||||
self.points=pts
|
||||
|
||||
def gen_prog(self,prgId=2,file=None,host=None,mode=0,**kwargs):
|
||||
'''
|
||||
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
|
||||
'''
|
||||
prg=[]
|
||||
gather={"MaxSamples":1000000, "Period":1}
|
||||
acq_frq=kwargs.get('acq_frq',1)
|
||||
gather={"MaxSamples":1000000, "Period":acq_frq}
|
||||
#Sys.ServoPeriod is dependent of !common() macro
|
||||
ServoPeriod= .2
|
||||
ServoPeriod= .2 #0.2ms
|
||||
#ServoPeriod = .05
|
||||
self.meta = {'timebase': ServoPeriod*gather['Period']}
|
||||
#channels=["Motor[1].ActPos","Motor[2].ActPos","Motor[3].ActPos"]
|
||||
@@ -250,24 +256,26 @@ class ShapePath:
|
||||
#if verb&2:
|
||||
# self.plot_points(pts)
|
||||
|
||||
#sort points along y
|
||||
pts=pts[pts[:, 1].argsort()]
|
||||
#if verb&2:
|
||||
# self.plot_points(pts)
|
||||
|
||||
#group sorting
|
||||
cnt=pts.shape[0]
|
||||
idx=np.ndarray(cnt,dtype=np.int32)
|
||||
grp_cnt=int(np.sqrt(cnt))
|
||||
grp_sz=int(np.ceil(float(cnt)/grp_cnt))
|
||||
if self.args.yx==True:
|
||||
idxA=0;idxB=1
|
||||
else:
|
||||
idxA=1;idxB=0
|
||||
|
||||
#sort points along idxA
|
||||
pts=pts[pts[:,idxA].argsort()]
|
||||
#group sorting along idxB
|
||||
for i in range(grp_cnt):
|
||||
a=i*grp_sz
|
||||
#print a,a+grp_sz
|
||||
if i%2:
|
||||
idx[a:a+grp_sz]=a+pts[a:a+grp_sz,0].argsort()[::-1]
|
||||
idx[a:a+grp_sz]=a+pts[a:a+grp_sz,idxB].argsort()[::-1]
|
||||
else:
|
||||
idx[a:a+grp_sz]=a+pts[a:a+grp_sz,0].argsort()
|
||||
#print(idx)
|
||||
idx[a:a+grp_sz]=a+pts[a:a+grp_sz,idxB].argsort()
|
||||
#print(idx)
|
||||
pts=pts[idx]
|
||||
|
||||
if verb&2:
|
||||
@@ -294,8 +302,11 @@ class ShapePath:
|
||||
|
||||
def plot_gather(self,fnOut='/tmp/shapepath.npz',fnLoc='/tmp/gather.txt'):
|
||||
meta=self.meta
|
||||
pts=self.points
|
||||
pts=self.points # X,Y array
|
||||
rec = np.genfromtxt(fnLoc, delimiter=' ')
|
||||
#rec=Motor[1].ActPos,Motor[2].ActPos,Motor[3].ActPos,Motor[1].DesPos,Motor[2].DesPos,Motor[3].DesPos
|
||||
#res=rot.ActPos,y.ActPos,x.ActPos,rot.DesPos,y.DesPos,x.DesPos
|
||||
#idx 0 1 2 3 4 5
|
||||
if fnOut:
|
||||
# time base:
|
||||
# Gather.Period=10
|
||||
@@ -308,8 +319,8 @@ class ShapePath:
|
||||
#hl=ax[0].plot(x, y, color=col)
|
||||
hl=ax.plot(pts[:,0],pts[:,1],'r.')
|
||||
hl=ax.plot(pts[:,0],pts[:,1],'y--')
|
||||
hl = ax.plot(rec[:, 4], rec[:, 5], 'b-')
|
||||
hl=ax.plot(rec[:,1],rec[:,2],'g-')
|
||||
hl = ax.plot(rec[:, 5], rec[:, 4], 'b-') # desired path
|
||||
hl=ax.plot(rec[:,2],rec[:,1],'g-') # actual path
|
||||
ax.xaxis.set_label_text('x-pos um')
|
||||
ax.yaxis.set_label_text('y-pos um')
|
||||
cid = fig.canvas.mpl_connect('button_press_event', self.onclick)
|
||||
@@ -319,11 +330,18 @@ class ShapePath:
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(1, 1, 1)
|
||||
err=np.sqrt((rec[:,1]-rec[:,4])**2+(rec[:,1]-rec[:,4])**2)
|
||||
hl = ax.plot(err, 'r-')
|
||||
ax.xaxis.set_label_text('datapoint (timebase: %g ms per data point)' % meta['timebase'])
|
||||
errx=rec[:,2]-rec[:,5]
|
||||
erry=rec[:,1]-rec[:,4]
|
||||
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'])
|
||||
ax.yaxis.set_label_text('pos-error um')
|
||||
print('average error %g um'%err.mean())
|
||||
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()))
|
||||
plt.show()
|
||||
|
||||
if __name__=='__main__':
|
||||
@@ -358,6 +376,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=0)
|
||||
parser.add_option('-n', '--dryrun', action='store_true', help='dryrun to stdout')
|
||||
parser.add_option('--yx', action='store_true', help='sort y,x instead x,y')
|
||||
parser.add_option('--cfg', help='config file containing json configuration structure')
|
||||
|
||||
(args, other)=parser.parse_args()
|
||||
|
||||
Reference in New Issue
Block a user