homing plc and fixes

This commit is contained in:
2017-06-12 09:51:02 +02:00
parent 0bf383e155
commit 3b886088d9
15 changed files with 1133 additions and 87 deletions

View File

@@ -133,8 +133,8 @@ class MAErrorFrame(wx.Frame):
err=doc.err
except AttributeError:
rec=doc.fh['rec']
errx = (rec[:, 2] - rec[:, 5])
erry = (rec[:, 1] - rec[:, 4])
errx = (rec[:, 1] - rec[:, 4])
erry = (rec[:, 2] - rec[:, 5])
errxy = np.sqrt(errx ** 2 + erry ** 2)
doc.err = err = (errx, erry, errxy)
canvas.InitChild(meta,err)

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[:, 2])/tb
velxDes = np.diff(rec[:, 5])/tb
velyAct = np.diff(rec[:, 1])/tb
velyDes = np.diff(rec[:, 4])/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
velAct = np.sqrt(velxAct**2+velyAct**2)
velDes = np.sqrt(velxDes**2+velyDes**2)
doc.vel = vel = (velxAct,velxDes,velyAct,velyDes,velAct,velDes)

View File

@@ -59,8 +59,8 @@ class MPLCanvasImg(FigureCanvas):
ax.add_collection(ec)
hl+=ax.plot(rec[:, 5], rec[:, 4], 'b-',label='recDesPos')
hl+=ax.plot(rec[:,2],rec[:,1],'g-',label='recActPos')
hl+=ax.plot(rec[:, 4], rec[:, 5], 'b-',label='recDesPos')
hl+=ax.plot(rec[:,1],rec[:,2],'g-',label='recActPos')
ax.xaxis.set_label_text('x-pos um')
ax.yaxis.set_label_text('y-pos um')
@@ -267,13 +267,13 @@ class MAxyPlotFrame(wx.Frame):
idx=usrData
rec=self.doc.fh['rec']
hl=canvas.hl
hl[2].set_data(rec[:idx+1, 5], rec[:idx+1, 4])
hl[3].set_data(rec[:idx+1, 2], rec[:idx+1, 1])
hl[2].set_data(rec[:idx+1, 4], rec[:idx+1, 5])
hl[3].set_data(rec[:idx+1, 1], rec[:idx+1, 2])
#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, 2]-x,rec[idx, 2]+x)
ax.set_ylim(rec[idx, 1]-y,rec[idx, 1]+y)
ax.set_xlim(rec[idx, 1]-x,rec[idx, 1]+x)
ax.set_ylim(rec[idx, 2]-y,rec[idx, 2]+y)
canvas.draw()
@staticmethod

99
python/plot_interfero.py Executable file
View File

@@ -0,0 +1,99 @@
#!/usr/bin/env python
# *-----------------------------------------------------------------------*
# | |
# | Copyright (c) 2016 by Paul Scherrer Institute (http://www.psi.ch) |
# | |
# | Author Thierry Zamofing (thierry.zamofing@psi.ch) |
# *-----------------------------------------------------------------------*
#Testing the interferometer
'''
zamofing_t@ganymede:~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/cfg$ gpasciiCommander --host $PPMAC -i
$$$***
!common()
!mx-stage()
Gather.Enable=0
Gather.Items=6
Gather.MaxSamples=1000000
Gather.Period=10
Gather.Addr[0]=Motor[2].DesPos.a
Gather.Addr[1]=Motor[3].DesPos.a
Gather.Addr[2]=Motor[2].ActPos.a
Gather.Addr[3]=Motor[3].ActPos.a
Gather.Addr[4]=Motor[4].ActPos.a
Gather.Addr[5]=Motor[5].ActPos.a
open prog 2
linear abs
X1000 Y1000
dwell 10
Gather.Enable=2
X28000 Y1000
dwell 100
X1000 Y1000
dwell 100
X1000 Y28000
dwell 100
X1000 Y1000
dwell 1000
Gather.Enable=0
close
&1
b2r
download data with
PPMAC=SAR-CPPM-EXPMX1
PBGatherPlot -m24 -v7 --host $PPMAC --dat gather.txt
cat /tmp/gather.txt
Motor[2].MaxSpeed=20;Motor[3].MaxSpeed=20
Motor[2].MaxSpeed=5;Motor[3].MaxSpeed=5
Motor[2].MaxSpeed=2
Motor[3].MaxSpeed=2
b2r
'''
import os, sys, json
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import subprocess as sprc
import telnetlib
if __name__=='__main__':
def plot_gather(base):
#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
f1=plt.figure()
#f2 = plt.figure()
ax1 = f1.add_subplot(1,1,1)
#ax2 = f2.add_subplot(1, 1, 1)
for fn in sorted(os.listdir(base)):
print fn
rec = np.genfromtxt(base+'/'+fn, delimiter=' ')
print rec.shape
x=range(len(rec[:,0]))
#hl=ax[0].plot(x, y, color=col)
hl=ax1.plot(x,-(rec[:,0]-rec[0,0]),'k')
hl=ax1.plot(x,-(rec[:,2]-rec[0,2]),'r')
hl=ax1.plot(x,-(rec[:,4]-rec[0,4])/100,'m')
hl=ax1.plot(x,rec[:,1]-rec[0,1],'k')
hl=ax1.plot(x,rec[:,3]-rec[0,3],'b')
hl=ax1.plot(x,-(rec[:,5]-rec[0,5])/100,'c')
plt.show()
#plot_gather(base='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/gather5/')
#plot_gather(base='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/gather50/')
#plot_gather(base='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/tmp/')
#plot_gather(base='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/data_interfero_spd10')
#plot_gather(base='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/data_interfero_spd20')
plot_gather(base='data_interfero_spd10')

View File

@@ -83,11 +83,11 @@ 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="SAR-CPPM-EXPMX1",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="SAR-CPPM-EXPMX1",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="SAR-CPPM-EXPMX1",mode=1,pt2pt_time=1000)', 'plot_gather("'+fn+'.npz")']}
cfg = {"sequencer": ['gen_grid_points(w=20,h=20,pitch=50,rnd=0.2)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAR-CPPM-EXPMX1",mode=1,pt2pt_time=10,acq_per=10)', 'plot_gather("'+fn+'.npz")']}
#cfg = {"sequencer": ['gen_grid_points(w=20,h=20,pitch=50,rnd=0.2)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAR-CPPM-EXPMX1",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="SAR-CPPM-EXPMX1",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="SAR-CPPM-EXPMX1",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="SAR-CPPM-EXPMX1",mode=1,pt2pt_time=10,acq_per=1)','plot_gather("'+fn+'.npz")']}
cfg = {"sequencer": ['gen_swissfel_points(scale=300)','gen_prog(file="'+fn+'.prg",host="SAR-CPPM-EXPMX1",mode=1,pt2pt_time=100,acq_per=10)', 'plot_gather("'+fn+'.npz")']}
cfg = {"sequencer": ['gen_grid_points(w=15,h=15,pitch=100,rnd=0.2)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAR-CPPM-EXPMX1",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="SAR-CPPM-EXPMX1",mode=1,pt2pt_time=20,acq_per=10)','plot_gather("'+fn+'.npz")']}
#cfg = {"sequencer": ['gen_swissfel_points(scale=300)','gen_prog(file="'+fn+'.prg",host="SAR-CPPM-EXPMX1",mode=1,pt2pt_time=100,acq_per=10)', 'plot_gather("'+fn+'.npz")']}
self.cfg=dotdict(cfg)
self.args=args
@@ -281,10 +281,10 @@ class ShapePath:
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:
if self.args.xy==True:
idxA=1;idxB=0
else:
idxA=0;idxB=1
#sort points along idxA
pts=pts[pts[:,idxA].argsort()]
@@ -327,10 +327,10 @@ class ShapePath:
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
#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,1]
ofsx=-rec[0,5]+pts[0,0]
ofsy=-rec[0,4]+pts[0,0]
ofsx=-rec[0,5]+pts[0,1]
rec[:,(1,4)]+=ofsy
rec[:,(2,5)]+=ofsx
if fnOut:
@@ -345,8 +345,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[:, 5], rec[:, 4], 'b-') # desired path
hl=ax.plot(rec[:,2],rec[:,1],'g-') # actual path
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)
@@ -356,8 +356,8 @@ class ShapePath:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
errx=rec[:,2]-rec[:,5]
erry=rec[:,1]-rec[:,4]
errx=rec[:,1]-rec[:,4]
erry=rec[:,2]-rec[:,5]
err=np.sqrt(errx**2+erry**2)
hl = []
@@ -388,11 +388,8 @@ if __name__=='__main__':
'main command line interpreter function'
#usage: gpasciiCommunicator.py --host=PPMACZT84 myPowerBRICK.cfg
(h, t)=os.path.split(sys.argv[0]);cmd='\n '+(t if len(h)>3 else sys.argv[0])+' '
exampleCmd=('--host=PPMAC1391 -m 63 --cfg gather.cfg',
'samplePowerBrick.cfg',
'-n stackCheck1.cfg',
'--host=PPMACZT84 stackCheck1.cfg',
'--host=PPMACZT84 stackCheck1.cfg -v15',
exampleCmd=('-n',
'-v15'
)
epilog=__doc__+'''
Examples:'''+''.join(map(lambda s:cmd+s, exampleCmd))+'\n '
@@ -402,7 +399,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('--xy', action='store_true', help='sort x,y instead y,x')
parser.add_option('--cfg', help='config file containing json configuration structure')
(args, other)=parser.parse_args()

View File

@@ -0,0 +1,44 @@
#plot and calculate rms values of sine, six state trapezoidal etc.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as pyplot
pyplot.figure()
x=np.arange(360.)
y=np.sin(x/360.*2.*np.pi)
y1=x.copy()
y1[0: 60]=x[0:60]/60
y1[ 60:120]=1
y1[120:180]=1-x[0:60]/60
y1[180:240]=-x[0:60]/60
y1[240:300]=-1
y1[300:360]=-1+x[0:60]/60
y2=x.copy()
y2[0: 30]=0
y2[30:150]=1
y2[150:210]=0
y2[210:330]=-1
y2[330:360]=0
y3=x.copy()
y3[0: 60]=.5
y3[60:120]=1
y3[120:180]=.5
y3[180:240]=-.5
y3[240:300]=-1
y3[300:360]=-.5
pyplot.plot(x,y,x,y1,x,y2,x,y3);pyplot.show()
rms=np.sqrt(np.mean(y**2))
b=np.sqrt(2)/2
rms1=np.sqrt(np.mean(y1**2))
rms2=np.sqrt(np.mean(y2**2))
rms3=np.sqrt(np.mean(y3**2))
print rms,rms1,rms2,rms3,b
print 0.8/rms, 0.8/rms1, 0.8/rms2, 0.8/rms3
#https://e2e.ti.com/blogs_/b/motordrivecontrol/archive/2013/11/08/generate-your-own-commutation-table-trapezoidal-control-3-phase-bldc-motors-using-hall-sensors