bugfixing

This commit is contained in:
2017-01-19 13:40:04 +01:00
parent 3519c559a1
commit df42fa49b3
10 changed files with 129 additions and 51 deletions

View File

@@ -133,8 +133,8 @@ class MAErrorFrame(wx.Frame):
err=doc.err
except AttributeError:
rec=doc.fh['rec']
errx = abs(rec[:, 1] - rec[:, 4])
erry = abs(rec[:, 2] - rec[:, 5])
errx = (rec[:, 2] - rec[:, 5])
erry = (rec[:, 1] - rec[:, 4])
errxy = np.sqrt(errx ** 2 + erry ** 2)
doc.err = err = (errx, erry, errxy)
canvas.InitChild(meta,err)
@@ -175,7 +175,7 @@ class MAErrorFrame(wx.Frame):
if msg == 0:
canvas = self.canvas
ax = canvas.ax
len = usrData
idx = usrData
err = self.doc.err
hl = canvas.hl
#hl[0].set_data(rec[:len, 4], rec[:len, 5])
@@ -185,7 +185,7 @@ class MAErrorFrame(wx.Frame):
x = (x[1] - x[0]) / 2;
#y = ax.get_ylim();
#y = (y[1] - y[0]) / 2;
ax.set_xlim(len-x, len + x,emit=True)
ax.set_xlim(idx-x, idx + x,emit=True)
#ax.set_ylim(rec[len, 2] - y, rec[len, 2] + y)
canvas.draw()

View File

@@ -148,10 +148,10 @@ class MAVelocityFrame(wx.Frame):
#datapoint timebase: 2 ms () per data point
#velocity: um/ms (deltatau desVel= motor units per serco cycle)
rec=doc.fh['rec']
velxAct = np.diff(rec[:, 1])/tb
velxDes = np.diff(rec[:, 4])/tb
velyAct = np.diff(rec[:, 2])/tb
velyDes = np.diff(rec[:, 5])/tb
velxAct = np.diff(rec[:, 2])/tb
velxDes = np.diff(rec[:, 5])/tb
velyAct = np.diff(rec[:, 1])/tb
velyDes = np.diff(rec[:, 4])/tb
velAct = np.sqrt(velxAct**2+velyAct**2)
velDes = np.sqrt(velxDes**2+velyDes**2)
doc.vel = vel = (velxAct,velxDes,velyAct,velyDes,velAct,velDes)
@@ -194,7 +194,7 @@ class MAVelocityFrame(wx.Frame):
if msg == 0:
canvas = self.canvas
ax = canvas.ax
len = usrData
idx = usrData
hl = canvas.hl
#hl[0].set_data(rec[:len, 4], rec[:len, 5])
#hl[3].set_data(rec[:len, 1], rec[:len, 2])
@@ -203,7 +203,7 @@ class MAVelocityFrame(wx.Frame):
x = (x[1] - x[0]) / 2;
#y = ax.get_ylim();
#y = (y[1] - y[0]) / 2;
ax.set_xlim(len-x, len + x,emit=True)
ax.set_xlim(idx-x, idx + x,emit=True)
#ax.set_ylim(rec[len, 2] - y, rec[len, 2] + y)
canvas.draw()

View File

@@ -59,8 +59,8 @@ class MPLCanvasImg(FigureCanvas):
ax.add_collection(ec)
hl+=ax.plot(rec[:, 4], rec[:, 5], 'b-',label='recDesPos')
hl+=ax.plot(rec[:,1],rec[:,2],'g-',label='recActPos')
hl+=ax.plot(rec[:, 5], rec[:, 4], 'b-',label='recDesPos')
hl+=ax.plot(rec[:,2],rec[:,1],'g-',label='recActPos')
ax.xaxis.set_label_text('x-pos um')
ax.yaxis.set_label_text('y-pos um')
@@ -264,16 +264,16 @@ class MAxyPlotFrame(wx.Frame):
if msg==0:
canvas=self.canvas
ax=canvas.ax
len=usrData
idx=usrData
rec=self.doc.fh['rec']
hl=canvas.hl
hl[2].set_data(rec[:len, 4], rec[:len, 5])
hl[3].set_data(rec[:len, 1], rec[:len, 2])
hl[2].set_data(rec[:idx+1, 5], rec[:idx+1, 4])
hl[3].set_data(rec[:idx+1, 2], rec[:idx+1, 1])
#ax.draw_artist(hl[2])
x=ax.get_xlim();x=(x[1]-x[0])/2;
y=ax.get_ylim();y=(y[1]-y[0])/2;
ax.set_xlim(rec[len, 1]-x,rec[len, 1]+x)
ax.set_ylim(rec[len, 2]-y,rec[len, 2]+y)
ax.set_xlim(rec[idx, 2]-x,rec[idx, 2]+x)
ax.set_ylim(rec[idx, 1]-y,rec[idx, 1]+y)
canvas.draw()
@staticmethod

View File

@@ -21,6 +21,14 @@ from MAVelocity import *
import wxutils as ut
class MADoc():
'''
lenRec=fh['rec']
lenPts=fh['pts']
pts= X,Y array
#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
Implemented messages
0: The time slider has changed. usrData=index

View File

@@ -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()