towards measure the mass of the stage

This commit is contained in:
2017-01-30 11:30:08 +01:00
parent 47f8f83f91
commit c2910090f3
2 changed files with 191 additions and 1 deletions

View File

@@ -66,6 +66,8 @@ class MoveRecord:
self.fnNpz=fn+'.npz'
#cfg = {"sequencer": ['prog_1(host="SAROP11-CPPM-MOT6871",acq_per=10)', 'plot_1()']}
cfg = {"sequencer": ['plot_1()']}
#cfg = {"sequencer": ['prog_2(host="SAROP11-CPPM-MOT6871",acq_per=10)', 'plot_2()']}
#cfg = {"sequencer": ['plot_2()']}
self.cfg=dotdict(cfg)
self.args=args
@@ -159,7 +161,8 @@ class MoveRecord:
prg.append('jog3=1000')
prg.append('dwell 100')
prg.append('Gather.Enable=2')
for spd in (5,10,20,30,40):
#for spd in (5,10,20,30,40):
for spd in (20,20,20,20,20,20,20,20,20,20):
prg.append('Motor[3].JogSpeed=%d'%spd)
prg.append('jog3=27000')
prg.append('dwell 100')
@@ -182,12 +185,14 @@ class MoveRecord:
meta['HomePos']=-223.8 #Motor[3].HomePos
meta['PhasePos']=1200 #Motor[3].PhasePos
@staticmethod
def onclick(event):
print 'button=%s, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
obj=event.canvas.figure.obj
def plot_1(self):
try:
rec=self.rec
@@ -230,9 +235,133 @@ class MoveRecord:
legend = ax.legend(loc='upper right', shadow=True)
print 'abs average ',channels[4], np.abs(rec[:, 4]).mean()
fig=plt.figure();
fig.obj=self; cid=fig.canvas.mpl_connect('button_press_event', self.onclick)
fig.canvas.set_window_title('overlay')
ax = fig.add_subplot(1,1,1)
hl=[]
sz=10; weights = np.repeat(1.0, sz) / sz
v = np.convolve(rec[:,4], weights, 'same')
hl+=ax.plot(rec[:,1],v,'r-',label=channels[4])
ax.xaxis.set_label_text(channels[1])
ax.yaxis.set_label_text('current in bits: '+channels[4])
legend = ax.legend(loc='upper right', shadow=True)
plt.show()
def prog_2(self,prgId=2,host=None,acq_per=1):
'''
kwargs:
acq_per : acquire period: acquire data all acq_per servo loops (default=1)
prgId : used program number
file : used filename to save if None, not saved
host : host to send and execute program, if None, nothing is executed
'''
ServoPeriod= .2 #0.2ms Sys.ServoPeriod is dependent of !common() macro
self.prgId=prgId
self.file=file
self.host=host
self.gather={"MaxSamples":1000000, "Period":acq_per}
self.channels=["Motor[3].ActPos","Motor[3].DesPos","Motor[3].PhasePos","Motor[3].idMeas","Motor[3].iqMeas"]
self.meta=meta = {'timebase': ServoPeriod*self.gather['Period']}
self.prg=prg=[]
#prg.append('#1..3$')
#prg.append('#1..3j/')
self.prg_prolog()
prg=self.prg
prg.append(' linear abs')
prg.append('Motor[3].JogTs=0')
prg.append('Motor[3].JogSpeed=40')
prg.append('jog3=10000')
prg.append('dwell 100')
prg.append('Gather.Enable=2')
for acc in (-2.5,-1.25,-.5,-.25):
prg.append('Motor[3].JogTa=%g'%acc)
prg.append('jog3=17000')
prg.append('dwell 100')
prg.append('jog3=10000')
prg.append('dwell 100')
prg.append('Gather.Enable=0')
self.prg_epilog()
# &1 #1->0
# &1 #2->0
# #3$
# an anschlag (kabel) bewegen
# #3hmz
# Motor[3].PhasePos=1200
# #3j/
# &1p
#folgende parameter setzen: Motor[3].HomePos
meta['HomePos']=-223.8 #Motor[3].HomePos
meta['PhasePos']=1200 #Motor[3].PhasePos
def plot_2(self):
try:
rec=self.rec
prg=self.prg
channels=self.channels
meta=self.meta
except AttributeError:
fh=np.load(self.fnNpz)
rec=fh['rec']
prg=list(fh['prg'])
channels=list(fh['channels'])
meta=fh['meta'].item()
time=np.arange(0,rec.shape[0])*meta['timebase']
fig=plt.figure();
fig.obj=self; cid=fig.canvas.mpl_connect('button_press_event', self.onclick)
fig.canvas.set_window_title('position')
ax = fig.add_subplot(1,1,1)
hl=[]
p_avg=rec[:,1].mean();
p=rec[:,0]-p_avg
hl+=ax.plot(time,p,'r-',label=channels[0])
#d=np.diff(p)*100
#hl+=ax.plot(time[1:],d,'r-',label='vel of '+channels[0])
#a=np.diff(d)*100
#hl+=ax.plot(time[2:],a,'r-',label='acc of '+channels[0])
p=rec[:,1]-p_avg
hl+=ax.plot(time,p,'g-',label=channels[1])
d=np.diff(p)*100
hl+=ax.plot(time[1:],d,'g-',label='vel of '+channels[0])
a=np.diff(d)*100
hl+=ax.plot(time[2:],a,'g-',label='acc of '+channels[0])
#hl+=ax.plot(time,rec[:,2],'b-',label=channels[2])
ax.xaxis.set_label_text('ms')
ax.yaxis.set_label_text('um')
legend = ax.legend(loc='upper right', shadow=True)
fig=plt.figure();
fig.obj=self; cid=fig.canvas.mpl_connect('button_press_event', self.onclick)
fig.canvas.set_window_title('current')
ax = fig.add_subplot(1,1,1)
hl=[]
sz=100; weights = np.repeat(1.0, sz) / sz
v = np.convolve(rec[:,3], weights, 'same')
hl+=ax.plot(time,v,'r-',label=channels[3])
v = np.convolve(rec[:, 4], weights, 'same')
hl+=ax.plot(time,v,'g-',label=channels[4])
ax.xaxis.set_label_text('ms')
ax.yaxis.set_label_text('current in bits')
legend = ax.legend(loc='upper right', shadow=True)
print 'abs average ',channels[4], np.abs(rec[:, 4]).mean()
plt.show()
if __name__=='__main__':
from optparse import OptionParser, IndentedHelpFormatter
class MyFormatter(IndentedHelpFormatter):