From 882ac3a66e93056194f4620211074f17488034ad Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Tue, 20 Nov 2018 08:29:00 +0100 Subject: [PATCH] restructure shapepath data format --- python/PBMotionAnalyzer/MAError.py | 10 +- python/PBMotionAnalyzer/MAVelocity.py | 6 +- python/PBMotionAnalyzer/MAxyPlot.py | 24 +-- python/PBMotionAnalyzer/PBMotionAnalyzer.py | 15 +- python/shapepath.py | 175 +++++++++++--------- 5 files changed, 124 insertions(+), 106 deletions(-) diff --git a/python/PBMotionAnalyzer/MAError.py b/python/PBMotionAnalyzer/MAError.py index cc25517..de21eb1 100644 --- a/python/PBMotionAnalyzer/MAError.py +++ b/python/PBMotionAnalyzer/MAError.py @@ -133,8 +133,8 @@ class MAErrorFrame(wx.Frame): err=doc.err except AttributeError: rec=doc.fh['rec'] - errx = (rec[:, 1] - rec[:, 4]) - erry = (rec[:, 2] - rec[:, 5]) + errx = (rec[:, 1] - rec[:, 3]) + erry = (rec[:, 0] - rec[:, 2]) errxy = np.sqrt(errx ** 2 + erry ** 2) doc.err = err = (errx, erry, errxy) canvas.InitChild(meta,err) @@ -178,15 +178,15 @@ class MAErrorFrame(wx.Frame): idx = usrData err = self.doc.err hl = canvas.hl - #hl[0].set_data(rec[:len, 4], rec[:len, 5]) - #hl[3].set_data(rec[:len, 1], rec[:len, 2]) + #hl[0].set_data(rec[:len, 3], rec[:len, 2]) + #hl[3].set_data(rec[:len, 1], rec[:len, 0]) # 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(idx-x, idx + x,emit=True) - #ax.set_ylim(rec[len, 2] - y, rec[len, 2] + y) + #ax.set_ylim(rec[len, 0] - y, rec[len, 0] + y) canvas.draw() @staticmethod diff --git a/python/PBMotionAnalyzer/MAVelocity.py b/python/PBMotionAnalyzer/MAVelocity.py index ca4f245..b1df163 100644 --- a/python/PBMotionAnalyzer/MAVelocity.py +++ b/python/PBMotionAnalyzer/MAVelocity.py @@ -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'] + velyAct = np.diff(rec[:, 0])/tb velxAct = np.diff(rec[:, 1])/tb - velxDes = np.diff(rec[:, 4])/tb - velyAct = np.diff(rec[:, 2])/tb - velyDes = np.diff(rec[:, 5])/tb + velyDes = np.diff(rec[:, 2])/tb + velxDes = np.diff(rec[:, 3])/tb velAct = np.sqrt(velxAct**2+velyAct**2) velDes = np.sqrt(velxDes**2+velyDes**2) doc.vel = vel = (velxAct,velxDes,velyAct,velyDes,velAct,velDes) diff --git a/python/PBMotionAnalyzer/MAxyPlot.py b/python/PBMotionAnalyzer/MAxyPlot.py index 9053ad0..f855c71 100644 --- a/python/PBMotionAnalyzer/MAxyPlot.py +++ b/python/PBMotionAnalyzer/MAxyPlot.py @@ -55,13 +55,13 @@ class MPLCanvasImg(FigureCanvas): #idx 0 1 2 3 4 5 #idx=np.ndarray(shape=len(pts),dtype=np.int32) #for i in range(len(pts)): - # l=rec[:,4:6]-pts[i,:] + # l=rec[:,(3,2)]-pts[i,:] # l2=l[:,0]**2+l[:,1]**2 # idx[i]=np.argmin(l2) idx=[] for i in range(len(pts)): - l=rec[:,4:6]-pts[i,:] + l=rec[:,(3,2)]-pts[i,:] l2=l[:,0]**2+l[:,1]**2 idx.extend(np.where(l2<1)[0].tolist()) #print idx @@ -69,9 +69,9 @@ class MPLCanvasImg(FigureCanvas): #f2 = plt.figure() #a2 = f2.add_axes([0.075,0.075,0.85,0.85]) #a2.plot(rec[:,1],'r-',label='ptsDot') #,picker=5 default value - #a2.plot(rec[:,2],'g-',label='ptsDot') #,picker=5 default value - #a2.plot(rec[:,4],'r--',label='ptsDot') #,picker=5 default value - #a2.plot(rec[:,5],'g--',label='ptsDot') #,picker=5 default value + #a2.plot(rec[:,0],'g-',label='ptsDot') #,picker=5 default value + #a2.plot(rec[:,3],'r--',label='ptsDot') #,picker=5 default value + #a2.plot(rec[:,2],'g--',label='ptsDot') #,picker=5 default value #plt.show() @@ -84,12 +84,12 @@ 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(recPts[:,1],recPts[:,2],'g.',label='recDot') + hl+=ax.plot(rec[:, 3], rec[:, 2], 'b-',label='recDesPos') + hl+=ax.plot(rec[:,1],rec[:,0],'g-',label='recActPos') + hl+=ax.plot(recPts[:,1],recPts[:,0],'g.',label='recDot') ax.xaxis.set_label_text('x-pos um') ax.yaxis.set_label_text('y-pos um') - + ax.axis('equal') fig.obj=self self.ax=ax self.hl=hl @@ -293,13 +293,13 @@ class MAxyPlotFrame(wx.Frame): idx=usrData rec=self.doc.fh['rec'] hl=canvas.hl - hl[2].set_data(rec[:idx+1, 4], rec[:idx+1, 5]) - hl[3].set_data(rec[:idx+1, 1], rec[:idx+1, 2]) + hl[2].set_data(rec[:idx+1, 3], rec[:idx+1, 2]) + hl[3].set_data(rec[:idx+1, 1], rec[:idx+1, 0]) #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[idx, 1]-x,rec[idx, 1]+x) - ax.set_ylim(rec[idx, 2]-y,rec[idx, 2]+y) + ax.set_ylim(rec[idx, 0]-y,rec[idx, 0]+y) canvas.draw() @staticmethod diff --git a/python/PBMotionAnalyzer/PBMotionAnalyzer.py b/python/PBMotionAnalyzer/PBMotionAnalyzer.py index 44b3557..55d1cb2 100755 --- a/python/PBMotionAnalyzer/PBMotionAnalyzer.py +++ b/python/PBMotionAnalyzer/PBMotionAnalyzer.py @@ -24,11 +24,18 @@ 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 - + idx 0 1 2 3 4 5 6 + OLD Motor[3].ActPos Motor[2].ActPos Motor[1].ActPos Motor[3].DesPos Motor[2].DesPos Motor[1].DesPos Gate3[1].Chan[1].UserFlag + NEW Motor[1].ActPos Motor[2].ActPos Motor[1].DesPos Motor[2].DesPos Gate3[1].Chan[1].UserFlag + NEW y.ActPos x.ActPos y.DesPos x.DesPos Gate3[1].Chan[1].UserFlag + OLD->NEW + 0->none + 1->1 + 2->0 + 3->none + 4->3 + 5->2 Implemented messages 0: The time slider has changed. usrData=index diff --git a/python/shapepath.py b/python/shapepath.py index 604b066..827c874 100755 --- a/python/shapepath.py +++ b/python/shapepath.py @@ -16,10 +16,19 @@ verbose bits: 8 plot gather path Gather motor order -"Motor[3].ActPos","Motor[2].ActPos","Motor[1].ActPos","Motor[3].DesPos","Motor[2].DesPos","Motor[1].DesPos") - ACT DES -motors RY FX FY RY FX FY - 3 2 1 3 2 1 + +idx 0 1 2 3 4 5 6 +OLD Motor[3].ActPos Motor[2].ActPos Motor[1].ActPos Motor[3].DesPos Motor[2].DesPos Motor[1].DesPos Gate3[1].Chan[1].UserFlag +NEW Motor[1].ActPos Motor[2].ActPos Motor[1].DesPos Motor[2].DesPos Gate3[1].Chan[1].UserFlag +NEW y.ActPos x.ActPos y.DesPos x.DesPos Gate3[1].Chan[1].UserFlag +OLD->NEW +0->none +1->1 +2->0 +3->none +4->3 +5->2 + Mot 1: Stage Y Parker MX80L D11 25mm one pole cycle = 13mm = 2048 phase_step Mot 2: Stage X Parker MX80L D11 25mm one pole cycle = 13mm = 2048 phase_step Mot 3: Rotation stage LS Mecapion MDM-DC06DNC0H 32 poles = 1 rev = 16*2048=32768 phase_step @@ -28,9 +37,6 @@ Mot 5: Stage Z Stada Stepper 670mA 200 poles 1 rev = 100*2 Enc 6: Interferometer Y Enc 7: Interferometer X - - - ''' from __future__ import print_function import os, sys, time @@ -51,7 +57,7 @@ class ShapePath(MotionBase): def __init__(self,comm, gather, verbose): MotionBase.__init__(self,comm, gather, verbose) - def gen_swissmx_points(self,scale=10): + def gen_swissmx_points(self,flipx=False,flipy=False,ofs=(0,0),width=1000): 'generathe a path that writes swissfel' #string from inkscape path of the drawing d="m 524.7061,637.31536 3.54883,0 3.54882,0 3.54883,0 0,-4.20801 0,-4.20801 0,-4.208 0,-4.20801 4.22949,0 4.22949,0 4.2295,0 4.22949,0 0,-3.55957 0,-3.55957 0,-3.55957 0,-3.55957 -4.22949,0 -4.2295,0 -4.22949,0 -4.22949,0 0,-4.22949 0,-4.2295 0,-4.22949 0,-4.22949 -3.54883,0 -3.54882,0 -3.54883,0 -3.54883,0 0,4.22949 0,4.22949 0,4.2295 0,4.22949 -4.20752,0 -4.20752,0 -4.20752,0 -4.20752,0 0,3.55957 0,3.55957 0,3.55957 0,3.55957 4.20752,0 4.20752,0 4.20752,0 4.20752,0 0,4.20801 0,4.208 0,4.20801 0,4.20801 -11.87126,0.36152 -12.12171,-0.13934 -2.52941,3.93977 -2.57238,3.94369 -2.50854,3.88614 -2.50731,3.91767 -2.49035,3.88268 -2.50987,3.91244 -2.50453,3.88732 -2.51897,3.9189 -6.39782,5.72802 -6.63782,6.70894 -3.21517,5.11464 -3.3404,5.32333 -3.08995,5.11464 -3.17343,5.15637 -16.69223,0.0698 5.55908,0 5.55909,0 5.55908,0 3.18604,-5.17432 3.18603,-5.17431 3.18604,-5.17432 3.18603,-5.17431 3.17481,5.17431 3.1748,5.17432 3.17481,5.17431 3.1748,5.17432 5.59229,0 5.59228,0 5.59229,0 5.59228,0 -2.74121,-4.15283 -2.74121,-4.15283 -2.74121,-4.15283 -2.74121,-4.15284 -2.74122,-4.15283 -2.74121,-4.15283 -2.74121,-4.15283 -2.74121,-4.15283 2.50488,-3.90015 2.50489,-3.90015 2.50488,-3.90014 2.50488,-3.90015 2.50488,-3.90015 2.50489,-3.90015 2.50488,-3.90014 2.50488,-3.90015 -5.42724,0 -5.42725,0 -5.42724,0 -5.42725,0 -2.76855,4.95508 -2.76856,4.95508 -2.76855,4.95508 -2.76856,4.95508 -2.85644,-4.95508 -2.85645,-4.95508 -2.85644,-4.95508 -2.85645,-4.95508 -5.48193,0 -5.48194,0 -5.48194,0 -5.48193,0 2.52686,3.8562 2.52685,3.8562 2.52686,3.8562 2.52686,3.85621 2.52685,3.8562 2.52686,3.8562 2.52685,3.8562 2.52686,3.8562 -2.77954,4.19678 -2.77954,4.19678 -2.77954,4.19677 -2.77955,4.19678 -2.77954,4.19678 -2.77954,4.19678 -2.77954,4.19677 -2.77954,4.19678 -4.91638,0 -4.91638,0 -4.91639,0 -4.91638,0 -4.91638,0 -4.91638,0 -4.91638,0 -4.91638,0 -4.91639,0 -4.91638,0 -4.91638,0 -4.91638,0 -4.91638,0 -4.91639,0 -4.91638,0 -4.91638,0 4.07568,0 4.07568,0 4.07569,0 4.07568,0 0,-6.14136 0,-6.14135 0,-6.14136 0,-6.14136 0,-6.14136 0,-6.14135 0,-6.14136 0,-6.14136 1.57105,6.14136 1.57104,6.14136 1.57104,6.14135 1.57105,6.14136 1.57105,6.14136 1.57104,6.14136 1.57104,6.14135 1.57105,6.14136 3.68066,0 3.68067,0 3.68067,0 3.68066,0 1.57642,-6.14136 1.57641,-6.14135 1.57642,-6.14136 1.57641,-6.14136 1.57642,-6.14136 1.57642,-6.14135 1.57641,-6.14136 1.57642,-6.14136 0,6.14136 0,6.14136 0,6.14135 0,6.14136 0,6.14136 0,6.14136 0,6.14135 0,6.14136 4.06494,0 4.06494,0 4.06494,0 4.06494,0 0,-8.05298 0,-8.05298 0,-8.05298 0,-8.05297 0,-8.05298 0,-8.05298 0,-8.05298 0,-8.05298 -6.52588,0 -6.52588,0 -6.52587,0 -6.52588,0 -1.25781,4.8999 -1.25782,4.89991 -1.25781,4.8999 -1.25781,4.8999 -1.25781,4.8999 -1.25782,4.89991 -1.25781,4.8999 -1.25781,4.8999 -1.26343,-4.8999 -1.26343,-4.8999 -1.26343,-4.89991 -1.26343,-4.8999 -1.26342,-4.8999 -1.26343,-4.8999 -1.26343,-4.89991 -1.26343,-4.8999 -6.54785,0 -6.54785,0 -6.54785,0 -6.54785,0 0,8.05298 0,8.05298 0,8.05298 0,8.05298 0,8.05297 0,8.05298 0,8.05298 -4.25755,8.13646 -8.40743,0.19687 -8.40743,0.19687 -8.40743,0.19687 -8.40743,0.19687 5.93521,0.22812 8.09742,-0.56079 6.18579,-1.6814 4.55883,-2.66919 3.13062,-3.43823 1.84571,-3.87866 0.61523,-3.98853 -0.58179,-3.83373 -1.74634,-3.50416 -2.802,-2.95581 -3.83472,-2.18676 -5.49316,-1.60401 -7.77832,-1.20849 -7.64649,-1.58204 -1.75781,-2.59179 1.36328,-2.59375 4.4375,-1.09766 5.09766,1.40625 2.19727,3.29492 4.24072,-0.41748 4.24073,-0.41748 4.24072,-0.41748 4.24072,-0.41748 -1.98804,-4.09741 -2.44946,-3.15259 -2.97778,-2.3291 -3.65894,-1.62598 -5.05371,-0.95629 -7.25098,-0.3191 -7.10766,0.41748 -5.50367,1.25244 -4.19677,2.05494 -3.18604,2.91186 -2.01099,3.65796 -0.67065,4.29517 0.61523,3.98852 1.84571,3.5271 2.78002,2.823 3.32935,1.87817 5.06421,1.42822 7.89868,1.56006 7.69141,1.84571 2.02148,2.98828 -1.53906,2.85742 -5.58008,1.53711 -5.27344,-1.36133 -3.07617,-4.52734 -4.43847,0.41748 -4.43848,0.41748 -4.43848,0.41748 -4.43847,0.41748 2.50488,5.95459 4.43848,4.4165 3.18313,1.59592 4.10031,1.14017 -3.65979,0.0939 -5.9713,6e-5 -5.97131,5e-5 -5.9713,6e-5 -5.9713,6e-5 -5.9713,5e-5 -5.97131,6e-5 -5.9713,5e-5 -5.9713,6e-5 5.34491,0.81842 8.09742,-0.56079 6.18579,-1.6814 4.55883,-2.66919 3.13062,-3.43823 1.84571,-3.87866 0.61523,-3.98853 -0.58179,-3.83373 -1.74634,-3.50416 -2.802,-2.95581 -3.83472,-2.18676 -5.49316,-1.60401 -7.77832,-1.20849 -7.64649,-1.58204 -1.75781,-2.59179 1.36328,-2.59375 4.4375,-1.09766 5.09766,1.40625 2.19727,3.29492 4.24072,-0.41748 4.24073,-0.41748 4.24072,-0.41748 4.24072,-0.41748 -1.98804,-4.09741 -2.44946,-3.15259 -2.97778,-2.3291 -3.65894,-1.62598 -5.05371,-0.95629 -7.25098,-0.3191 -7.10766,0.41748 -5.50367,1.25244 -4.19677,2.05494 -3.18604,2.91186 -2.01099,3.65796 -0.67065,4.29517 0.61523,3.98852 1.84571,3.5271 2.78002,2.823 3.32935,1.87817 5.06421,1.42822 7.89868,1.56006 7.69141,1.84571 2.02148,2.98828 -1.53906,2.85742 -5.58008,1.53711 -5.27344,-1.36133 -3.07617,-4.52734 -4.43847,0.41748 -4.43848,0.41748 -4.43848,0.41748 -4.43847,0.41748 2.50488,5.95459 4.43848,4.4165 3.18313,1.59592 4.10031,1.14017 -3.06953,-0.0416 -3.06952,-0.0416 -8.58102,-0.0261 -10.12782,-0.0261 -7.03422,-0.0261 -8.58102,-0.0261 4.47168,0 6.6151,0 2.32826,0 4.47168,0 0,-5.83374 0,-5.83374 0,-5.83374 0,-5.83374 0,-5.83374 0,-5.83374 0,-5.83374 0,-5.83374 -4.47168,0 -4.47168,0 -4.47168,0 0,-5.5796 4.47168,0 4.47168,0 4.47168,0 0,-6.08691 0,-6.08692 -4.47168,0 -4.47168,0 -4.47168,0 -4.47168,0 0,6.08692 0,6.08691 0,5.5796 0,5.83374 0,5.83374 0,5.83374 0,5.83374 0,5.83374 0,5.83374 0,5.83374 -3.67318,5.83374 -8.7308,0 -10.73079,0 -6.7308,0 -9.10563,0 -2.25201,0.007 -8.72971,0.0266 -7.53755,-0.0442 -9.68477,0.0107 -6.3443,0 3.99902,0 3.99902,0 3.99903,0 3.99902,0 2.28516,-7.02002 2.28516,-7.02002 2.28516,-7.02002 2.28516,-7.02002 2.36181,7.02002 2.36182,7.02002 2.36181,7.02002 2.36182,7.02002 3.97705,0 3.97705,0 3.97705,0 3.97705,0 2.14795,-5.83374 2.14795,-5.83374 2.14795,-5.83374 2.14795,-5.83374 2.14795,-5.83374 2.14795,-5.83374 2.14795,-5.83374 2.14795,-5.83374 -4.2959,0 -4.2959,0 -4.2959,0 -4.2959,0 -0.93921,3.67505 -0.93921,3.67505 -0.93921,3.67505 -0.93921,3.67505 -0.9392,3.67504 -0.93921,3.67505 -0.93921,3.67505 -0.93921,3.67505 -1.23047,-3.67505 -1.23047,-3.67505 -1.23047,-3.67505 -1.23047,-3.67504 -1.23046,-3.67505 -1.23047,-3.67505 -1.23047,-3.67505 -1.23047,-3.67505 -4.03223,0 -4.03222,0 -4.03223,0 -4.03223,0 -1.18652,3.67505 -1.18653,3.67505 -1.18652,3.67505 -1.18653,3.67505 -1.18652,3.67504 -1.18652,3.67505 -1.18653,3.67505 -1.18652,3.67505 -0.93921,-3.67505 -0.93921,-3.67505 -0.93921,-3.67505 -0.93921,-3.67504 -0.9392,-3.67505 -0.93921,-3.67505 -0.93921,-3.67505 -0.93921,-3.67505 -4.32862,0 -4.32861,0 -4.32862,0 -4.32861,0 2.16431,5.83374 2.1643,5.83374 2.16431,5.83374 2.16431,5.83374 2.16431,5.83374 2.1643,5.83374 2.16431,5.83374 -3.84635,5.83374 -5.60781,0.003 -5.6078,0.003 -5.60781,0.003 -5.6078,0.003 -5.4839,-1.59358 0,0 5.47119,-3.35034 4.10888,-4.60278 2.5708,-5.4712 0.85694,-5.95459 -0.64868,-5.02123 -1.94507,-4.51587 -3.32837,-3.91114 -4.88843,-3.20801 -7.482173,-2.87842 -5.1337,-1.42273 -6.06186,-1.41174 -6.67969,-2.37304 -1.44922,-2.76758 1.75782,-3.56055 5.22851,-1.49414 6.5918,1.97852 1.99951,2.5708 1.16455,3.75732 4.69141,-0.2749 4.691403,-0.2749 4.6914,-0.27491 4.69141,-0.2749 -0.94483,-4.66918 -1.604,-3.98804 -2.26318,-3.30688 -2.92236,-2.62574 -3.59802,-2.01858 -4.334103,-1.44162 -5.0702,-0.86484 -5.80627,-0.28824 -4.76547,0.1593 -4.23282,0.47791 -6.86695,1.91162 -5.04223,2.98828 -3.61401,3.95507 -2.14283,4.53687 -0.7146,4.82251 1.40625,6.88892 4.21875,5.54858 3.26035,2.31812 4.19986,2.07641 5.13919,1.83472 6.07834,1.59302 6.54785,1.81226 3.64746,1.92211 2.19727,4.48242 -2.33008,4.65821 -6.54688,1.97851 -5.05371,-0.97827 -3.73535,-2.93384 -1.57153,-2.9663 -0.93433,-4.06495 -4.73486,0.29688 -4.73487,0.29687 -4.73486,0.29688 -4.73486,0.29687 0.76065,4.6637 1.44711,4.23523 2.13376,3.80676 2.82059,3.3783 3.79577,2.76855 5.0592,1.97754 6.32264,1.18652 7.58606,0.39551 9.481626,-0.95145 -7.224723,-0.043 -7.224724,-0.043 -7.224723,-0.043 -7.224723,-0.043 -7.224723,-0.043 -7.224723,-0.043 -7.224724,-0.043 -7.224723,-0.043" @@ -60,10 +66,14 @@ class ShapePath(MotionBase): for i in xrange(pts.shape[0]): pts[i,:]=map(float,d[i+1].split(',')) - pts[0,:]=(5,0) + pts[0,:]=(0,0) pts=pts.cumsum(0) - pts[:,1]=-pts[:,1] - pts*=scale + pts=pts[::-1,:] + pts=pts-pts[0] + pts*=width/pts[:,0].max() + if flipx: pts[:,0]=-pts[:,0] + if not flipy: pts[:,1]=-pts[:,1] + pts+=ofs self.points=pts verb=self.verbose @@ -72,7 +82,7 @@ class ShapePath(MotionBase): plt.show() - def gen_swissfel_points(self,scale=10): + def gen_swissfel_points(self,flipx=False,flipy=False,ofs=(0,0),width=1000): 'generathe a path that writes swissfel' #string from inkscape path of the drawing d="m 15.801613,951.54022 -1.655274,-0.17578 -1.809082,-0.52002 0,-1.52344 1.765137,0.76172 1.699219,0.25635 1.955566,-0.49805 0.688477,-1.4209 -0.498047,-1.25976 -1.618652,-0.68115 -0.900879,-0.17578 -1.426392,-0.42298 -0.968628,-0.60974 -0.739746,-1.95557 0.254516,-1.29638 0.76355,-0.98877 1.217652,-0.62622 1.602173,-0.20874 1.567383,0.13916 1.6333,0.41748 0,1.44287 -1.589355,-0.60059 -1.442871,-0.19775 -1.071167,0.11719 -0.796509,0.35156 -0.651856,1.33301 0.432129,1.09863 1.655274,0.59326 0.893555,0.18311 1.437377,0.43579 1.001587,0.67749 0.593262,0.92651 0.197754,1.19751 -0.267334,1.3971 -0.802002,1.01257 -1.311035,0.61523 2.995605,-0.004 2.995606,-0.004 -0.536499,-2.05078 -0.536499,-2.05078 -0.536499,-2.05079 -0.536499,-2.05078 1.347656,0 0.421142,1.60034 0.421143,1.60034 0.421143,1.60035 0.421142,1.60034 0.419312,-1.60034 0.419311,-1.60035 0.419312,-1.60034 0.419311,-1.60034 1.589356,0 0.421142,1.60034 0.421143,1.60034 0.421143,1.60035 0.421142,1.60034 0.419312,-1.60034 0.419311,-1.60035 0.419312,-1.60034 0.419311,-1.60034 1.347657,0 -0.536499,2.05078 -0.5365,2.05079 -0.536499,2.05078 -0.536499,2.05078 -1.589355,0 -0.441284,-1.68091 -0.441285,-1.68091 -0.441284,-1.6809 -0.441284,-1.68091 -0.443115,1.68091 -0.443116,1.6809 -0.443115,1.68091 -0.443115,1.68091 2.330933,-8e-5 2.330933,-8e-5 2.330932,-8e-5 2.330933,-8e-5 0,-2.05078 0,-2.05078 0,-2.05079 0,-2.05078 0.673828,-1.48681 0.673828,0 0,-0.85327 0,-0.85327 -0.673828,0 -0.673828,0 0,0.85327 0,0.85327 0.673828,1.48681 0.673828,0 0,2.05078 0,2.05079 0,2.05078 0,2.05078 2.545166,0.1062 2.545166,0.1062 -1.376953,-0.13183 -1.501465,-0.38086 0,-1.3916 1.472168,0.58593 1.435547,0.19043 1.464844,-0.32226 0.512695,-0.92285 -0.373535,-0.84229 -1.038789,-0.41935 -1.048614,-0.25448 -1.078491,-0.33325 -0.730591,-0.47241 -0.55664,-1.50147 0.205078,-1.02539 0.615234,-0.76172 0.99243,-0.47241 1.336672,-0.15747 1.40625,0.10986 1.21582,0.32959 0,1.27442 -1.186523,-0.43946 -1.274414,-0.14648 -1.508789,0.30762 -0.498047,0.92285 0.358886,0.73975 0.763094,0.30189 0.76857,0.22893 0.785513,0.20842 0.813927,0.24037 0.809326,0.49988 0.455932,0.66833 0.151978,0.89173 -0.227051,1.02355 -0.681152,0.78553 -1.071167,0.49988 3.205262,0.0833 3.205261,0.0833 -1.376953,-0.13183 -1.501465,-0.38086 0,-1.3916 1.472168,0.58593 1.435547,0.19043 1.464843,-0.32226 0.512696,-0.92285 -0.373536,-0.84229 -1.038789,-0.41935 -1.048613,-0.25448 -1.078491,-0.33325 -0.730591,-0.47241 -0.556641,-1.50147 0.205078,-1.02539 0.615235,-0.76172 0.99243,-0.47241 1.336672,-0.15747 1.40625,0.10986 1.21582,0.32959 0,1.27442 -1.186524,-0.43946 -1.274414,-0.14648 -1.508789,0.30762 -0.498047,0.92285 0.358887,0.73975 0.805073,0.3095 0.76935,0.22988 0.764915,0.20509 0.791765,0.23514 0.809327,0.49988 0.455932,0.66833 0.151978,0.89173 -0.227051,1.02355 -0.681152,0.78553 -1.071167,0.49988 2.095642,-0.0229 2.095642,-0.0229 0,-1.36688 0,-1.36688 0,-1.36689 0,-1.36688 0,-1.36688 0,-1.36688 0,-1.36689 0,-1.36688 1.571045,0 1.571045,0 1.571045,0 1.571045,0 0,1.24512 -1.201172,0 -1.201172,0 -1.201172,0 -1.201172,0 0,0.80566 0,0.80567 0,0.80566 0,0.80566 1.083984,0 1.083985,0 1.083984,0 1.083985,0 0,1.24512 -1.083985,0 -1.083984,0 -1.083985,0 -1.083984,0 0,1.30554 0,1.30555 0,1.30554 0,1.30554 3.581543,0 3.581543,0 0,-1.36688 0,-1.36688 0,-1.36689 0,-1.36688 0,-1.36688 0,-1.36688 0,-1.36689 0,-1.36688 1.728516,0 1.728516,0 1.728515,0 1.728516,0 0,1.24512 -1.358643,0 -1.358642,0 -1.358643,0 -1.358643,0 0,0.80932 0,0.80933 0,0.80933 0,0.80932 1.30188,0 1.30188,0 1.30188,0 1.30188,0 0,1.24512 -1.30188,0 -1.30188,0 -1.30188,0 -1.30188,0 0,0.9906 0,0.9906 0,0.9906 0,0.9906 1.391602,0 1.391601,0 1.391602,0 1.391602,0 0,1.24512 -3.587581,3.8e-4 -1.964972,0 3.702844,0 4.295998,0 0,-1.36733 0,-1.36688 0,-1.36689 0,-1.36688 0,-1.36688 0,-1.36689 0,-1.36688 0,-1.36688 1.479492,0 0,1.21124 0,1.21124 0,1.21125 0,1.21124 0,1.21124 0,1.21124 0,1.21125 0,1.21124 1.331177,0 1.331177,0 1.331176,0 1.331177,0 0,1.24512 -1.70105,0 -1.701049,0 -1.70105,0" @@ -81,10 +91,14 @@ class ShapePath(MotionBase): for i in xrange(pts.shape[0]): pts[i,:]=map(float,d[i+1].split(',')) - pts[0,:]=(5,0) + pts[0,:]=(0,0) pts=pts.cumsum(0) - pts[:,1]=-pts[:,1] - pts*=scale + pts=pts[::-1,:] + pts=pts-pts[0] + pts*=width/pts[:,0].max() + if flipx: pts[:,0]=-pts[:,0] + if not flipy: pts[:,1]=-pts[:,1] + pts+=ofs self.points=pts verb=self.verbose @@ -119,7 +133,7 @@ class ShapePath(MotionBase): #idx 0 1 2 3 4 5 rec=fh['rec'] pts=fh['pts'] - desPos=rec[:,4:6] + desPos=rec[:,(3,2)] idx=np.ndarray(shape=len(pts),dtype=np.int32) for i in range(len(pts)): @@ -128,7 +142,7 @@ class ShapePath(MotionBase): idx[i]=np.argmin(l2) recPts=rec[idx,:] - ptsCorr=(pts-recPts[:,1:3]+recPts[:,4:6]) + ptsCorr=(pts-recPts[:,(1,0)]+recPts[:,(3,2)]) self.points=pts self.ptsCorr=ptsCorr print(ptsCorr) @@ -142,12 +156,12 @@ class ShapePath(MotionBase): comm=self.comm gt=self.gather gt.set_phasemode(False) - #gt.set_address("Motor[3].ActPos","Motor[2].ActPos","Motor[1].ActPos","Motor[3].DesPos","Motor[2].DesPos","Motor[1].DesPos") - gt.set_address("Motor[3].ActPos","Motor[2].ActPos","Motor[1].ActPos","Motor[3].DesPos","Motor[2].DesPos","Motor[1].DesPos","Gate3[1].Chan[1].UserFlag") + address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Gate3[1].Chan[1].UserFlag") + gt.set_address(*address) gt.set_property(MaxSamples=1000000, Period=acq_per) ServoPeriod= .2 #0.2ms #Sys.ServoPeriod is dependent of !common() macro #ServoPeriod=comm.gpascii.servo_period - self.meta = {'timebase': ServoPeriod*acq_per} + self.meta = {'timebase': ServoPeriod*acq_per,'address':address} def setup_coord_trf(self): comm = self.comm @@ -306,14 +320,10 @@ class ShapePath(MotionBase): self.rec=rec=gt.upload() pts=self.points - - #rec=Motor[1].ActPos,Motor[2].ActPos,Motor[3].ActPos,Motor[1].DesPos,Motor[2].DesPos,Motor[3].DesPos - #res=rot.ActPos,x.ActPos,y.ActPos,rot.DesPos,x.DesPos,y.DesPos - #idx 0 1 2 3 4 5 - ofsy=-rec[0,4]+pts[0,0] - ofsx=-rec[0,5]+pts[0,1] - rec[:,(1,4)]+=ofsy - rec[:,(2,5)]+=ofsx + ofsy=-rec[0,2]+pts[0,1] + ofsx=-rec[0,3]+pts[0,0] + rec[:,(1,3)]+=ofsx + rec[:,(0,2)]+=ofsy if fnRec: np.savez_compressed(fnRec, rec=rec, pts=pts, meta=self.meta) @@ -371,45 +381,49 @@ class ShapePath(MotionBase): self.ax=ax self.hl=hl - def plot_gather(self): + def plot_gather(self,mode=255): try: meta=self.meta pts=self.points # X,Y array - rec = self.rec + rec = self.rec # yA,xA,yD,xD,trig except AttributeError as e: print('plot_gather(): '+str(e)+': no data acquired yet') return - fig=plt.figure() - ax = fig.add_subplot(1,1,1) - #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-') # desired path - hl=ax.plot(rec[:,1],rec[:,2],'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) - fig.obj=self - self.ax=ax - self.hl=hl + if mode&1: + fig=plt.figure('trajectory') + ax = fig.add_subplot(1,1,1) + #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[:,3],rec[:,2], 'b-') # desired path + hl=ax.plot(rec[:,1],rec[:,0],'g-') # actual path + ax.xaxis.set_label_text('x-pos um') + ax.yaxis.set_label_text('y-pos um') + ax.axis('equal') + cid = fig.canvas.mpl_connect('button_press_event', self.onclick) + fig.obj=self + self.ax=ax + self.hl=hl - fig = plt.figure() - ax = fig.add_subplot(1, 1, 1) - errx=rec[:,1]-rec[:,4] - erry=rec[:,2]-rec[:,5] - err=np.sqrt(errx**2+erry**2) + if mode&2: + fig = plt.figure('position error') + ax = fig.add_subplot(1, 1, 1) + errx=rec[:,1]-rec[:,3] + erry=rec[:,0]-rec[:,2] + 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') - 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())) + 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') + 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())) - self.bode_plot(xy=(4,1),mode=31,db=True) # FX - self.bode_plot(xy=(5,2),mode=31,db=True) # FY + if mode&4: + self.bode_plot(xy=(3,1),mode=31,db=True) # FX + self.bode_plot(xy=(2,0),mode=31,db=True) # FY plt.show() @@ -427,19 +441,12 @@ class ShapePath(MotionBase): 4: display bode of Y(s) signal +8: display bode of G(s) signal +16: clip frequencies out of minFrq,maxFrq - -"Motor[3].ActPos","Motor[2].ActPos","Motor[1].ActPos","Motor[3].DesPos","Motor[2].DesPos","Motor[1].DesPos") - ACT DES -motors RY FX FY RY FX FY - 3 2 1 3 2 1 - - ''' - data=self.rec - strMot=('RY.act','FX.act','FY.act','RY.des','FX.des','FY.des') + rec=self.rec + strMot=('FY.act','FX.act','FY.des','FX.des') ts=self.meta['timebase']*1E-3 #0.2ms - num=data.shape[0] + num=rec.shape[0] #rngMin=int(.01/ts);rngMax=int(num-1.001/ts) #0.01s from start 1.01 sec before end rngMin=int(.01/ts);rngMax=rngMin+int((self.points.shape[0]-2)*.01/ts) @@ -449,8 +456,8 @@ motors RY FX FY RY FX FY maxFrq=1/(2*ts) #maximal frq to show bode xIdx,yIdx=xy #remove DC value - x=data[rngMin:rngMax,xIdx]-data[rngMin,xIdx] - y=data[rngMin:rngMax,yIdx]-data[rngMin,yIdx] + x=rec[rngMin:rngMax,xIdx]-rec[rngMin,xIdx] + y=rec[rngMin:rngMax,yIdx]-rec[rngMin,yIdx] #make last value same as first (nice periodicity) x=x-(x[-1]*np.arange(num)/(num-1.)) y=y-(y[-1]*np.arange(num)/(num-1.)) @@ -486,22 +493,24 @@ motors RY FX FY RY FX FY ftY=ftY[i:j+1] ftLst=[] if mode&2: - ftLst.append((ftX,'b')) + ftLst.append((ftX,'b','input')) if mode&4: - ftLst.append((ftY,'g')) + ftLst.append((ftY,'g','output')) if mode&8: - ftLst.append((ftY/ftX,'r')) + ftLst.append((ftY/ftX,'r','out/inp')) - for ft,c in ftLst: + for ft,c,s in ftLst: phase=np.angle(ft) phase=np.degrees(np.unwrap(phase)) mag=np.abs(ft) #ftY)/np.abs(ftX) if db: magDb=20*np.log10(mag) #in decibel (20=10*2: factor 2 because rfft only half) - ax1.semilogx(f,magDb,c) # Bode magnitude plot + ax1.semilogx(f,magDb,c,label=s) # Bode magnitude plot else: - ax1.semilogx(f, mag, c) # Bode magnitude plot - ax2.semilogx(f,phase,c) # Bode phase plot + ax1.semilogx(f, mag, c,label=s) # Bode magnitude plot + ax2.semilogx(f,phase,c,label=s) # Bode phase plot + ax2.set_ylim(-360,360) + ax2.legend() plt.show(block=False) @@ -516,13 +525,15 @@ if __name__=='__main__': # ) def run_test(args): + #args.host=None if args.host is None: comm=gather=None else: comm = PPComm(host=args.host) gather = Gather(comm) sp = ShapePath(comm, gather, args.verbose) - + #sp.gen_swissmx_points(width=1000,ofs=(-500,0)) + #sp.gen_swissfel_points(width=1000,ofs=(-500,0)) #fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/PBMotionAnalyzer/records/mode1' #fh=np.load(fn+'.npz') #for k,v in fh.iteritems(): @@ -545,9 +556,9 @@ if __name__=='__main__': #>>>point source and sorting<<< #sp.points = np.array([[100,523],[635,632],[756,213]]) #sp.points = np.array([[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]]) - #sp.gen_rand_points(n=107, scale=1000);sp.sort_points(xy=args.xy) + #sp.gen_rand_points(n=107, scale=1000);sp.sort_points(xy=xy) #sp.gen_grid_points(w=100,h=100,pitch=10,rnd=.2) - #sp.gen_swissfel_points(scale=300) + #sp.gen_swissfel_points(width=1000,ofs=(-500,0));sp.sort_points(xy=xy) #sp.gen_grid_points(w=10,h=10,pitch=50,rnd=.2) #sp.gen_grid_points(w=100,h=100,pitch=50,rnd=.2) @@ -557,10 +568,10 @@ if __name__=='__main__': #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=2) #sync with timing system (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(scale=10);sp.setup_motion(fnPrg=fn+'.prg',mode=1,pt2pt_time=40,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=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)