diff --git a/Readme.md b/Readme.md index faf3e7b..f5384d9 100644 --- a/Readme.md +++ b/Readme.md @@ -983,8 +983,21 @@ left Y: -1.67 +``` + +Motor 1,2 tuning +---------------- +``` +Current loop: +rise time: 0.25ms +overshot 2.74% +damping: 0.753 +natural frq:1487Hz + +=>system 2ter Ordnung + +k*1/(1+T1*s+t2*s^2) + + +``` -B : -T -L -R diff --git a/python/PBTuning.py b/python/PBTuning.py index bad529e..f4649d7 100755 --- a/python/PBTuning.py +++ b/python/PBTuning.py @@ -99,7 +99,7 @@ class PBTuning: plt.pause(.05) return (res[1,0]/res[0,0],res[1,1]-res[0,1]) - def bode_gather(self,motor=1,minFrq=1,maxFrq= 100,numFrq= 100,amp=10,file='/tmp/bode.npz'): + def bode_gather(self,motor=1,minFrq=1,maxFrq=300,numFrq= 150,amp=10,file='/tmp/bode.npz'): #amp= percentage of maximum amplitude fig = plt.figure() ax = fig.add_subplot(1, 1, 1) @@ -122,20 +122,70 @@ class PBTuning: print('frq %g ampl %g phase %g'%tuple(bode[i,:])) plt.draw_all() - fig = plt.figure() - ax = fig.add_subplot(2, 1, 1) - ax.semilogx(frqLst, bode[:,0]) # Bode magnitude plot - #ax.loglog(frqLst, bode[:,0],'.-') # Bode magnitude plot - ax = fig.add_subplot(2, 1, 2) - ax.semilogx(frqLst, bode[:,1]) # Bode phase plot - plt.show() meta={'motor':motor,'date':time.asctime()} np.savez_compressed(file, bode=bode, meta=meta) + def bode_gather2(self,motor=1,minFrq=5,maxFrq=150,tSec=15,amp=30,mode=1,file='/tmp/bode.npz'): + #amp= percentage of maximum amplitude + self.fnLoc='/tmp/gather.txt' + #self.fnLoc='/tmp/gather70.txt' + mode=1 + data=self.do_command('openloopchirp',motor,amp,minFrq,maxFrq,tSec*1000,mode,0) + self.data = data= np.genfromtxt(self.fnLoc, delimiter=' ') + n = self.data.shape[0] + w=np.hamming(n) + + #data[:,0]*=w + #data[:,1]=(data[:, 1]-data[0, 1])*w + #data[:, 1]-=np.convolve(data[:,1],np.ones(n),'same')/n + n=1000 + d=np.concatenate((np.ones(n-1)*data[0, 1],data[:, 1])) + d=np.convolve(d,np.ones(n),'valid')/n + data[:, 1]-=d + + fig = plt.figure() + ax = fig.add_subplot(1, 1, 1) + ax.plot(data[:, 0]) + + ax.plot(data[:, 1]) + #d=np.concatenate((np.ones(n)*data[0, 1],data[:, 1],np.ones(n)*data[-1, 1])) + + fig = plt.figure() + iFt = np.fft.fft(data[:, 0]) + oFt= np.fft.fft(data[:, 1]) + iPhase = np.angle(iFt) + iAmpl = np.absolute(iFt) + oPhase = np.angle(oFt) + oAmpl = np.absolute(oFt) + ax = fig.add_subplot(2, 1, 1) + ax.plot(iAmpl) + ax.plot(oAmpl) + ax = fig.add_subplot(2, 1, 2) + ax.plot(iPhase) + ax.plot(oPhase) + + frq=np.arange(0,iAmpl.shape[0]) + #bode=np.ndarray((n,3)) + db_mag=20*np.log10(oAmpl-iAmpl) + phase=np.unwrap(oPhase-iPhase)# numpy.unwrap(p, discont=3.141592653589793, axis=-1) + fig = plt.figure() + ax = fig.add_subplot(2, 1, 1) + ax.semilogx(frq, db_mag,'.-') # Bode magnitude plot + ax.xaxis.set_label_text('dB Mag.') + #ax.loglog(frqLst, bode[:,0],'.-') # Bode magnitude plot + ax = fig.add_subplot(2, 1, 2) + ax.semilogx(frq, phase,'.-') # Bode phase plot + ax.xaxis.set_label_text('phase') + plt.show() + + + #meta={'motor':motor,'date':time.asctime()} + #np.savez_compressed(file, bode=bode, meta=meta) + def bode_plot(self,file): f=np.load(file) bode=f['bode'] - meta=f('meta') + meta=f['meta'] frq=bode[:,0] db_mag=20*np.log10(bode[:,1]) phase=np.unwrap(bode[:,2])# numpy.unwrap(p, discont=3.141592653589793, axis=-1) @@ -169,12 +219,14 @@ Examples:'''+''.join(map(lambda s:cmd+s, exampleCmd))+'\n ' parser.add_argument('--dryrun', '-n', action='store_true', help='dryrun to stdout') args=parser.parse_args() - plt.ion() + #plt.ion() tune=PBTuning(args) base='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/data/' - file=sys.path.join(base,'bode1.npz') - tune.bode(file=file,motor=1) - tune.bode_plot(file) + for i in (1,):#(1,2): + file=os.path.join(base,'bode%d.npz'%i) + #tune.bode_gather(file=file,motor=i) + tune.bode_gather2(file=file,motor=i) + tune.bode_plot(file) #tune.do_command('stepmove',1,100,500,0,0) #------------------ Main Code ---------------------------------- #ssh_test()