working on document
This commit is contained in:
@@ -16,7 +16,8 @@ bit 3=8: custom chirp record/plot for various transfer function
|
||||
bit 4=16: plot the full bode recording
|
||||
bit 5=32: plot the full bode recording with an approximation model
|
||||
bit 6=64: plot all raw acquired data files
|
||||
bit 7=128: generate observer code (after files generated with matlab)
|
||||
bit 7=128: custom plots
|
||||
bit 8=256: generate observer code (after files generated with matlab)
|
||||
|
||||
-> check https://github.com/klauer/ppmac for fast data gathering server which supports
|
||||
phase gathering -> not yet compiling: /home/zamofing_t/Documents/prj/SwissFEL/PowerBrickInspector/ppmac/fast_gather
|
||||
@@ -37,6 +38,27 @@ from pbtools.misc.gather import Gather
|
||||
from pbtools.misc.tuning import Tuning
|
||||
|
||||
|
||||
# import sys, os
|
||||
|
||||
def wait_key():
|
||||
''' Wait for a key press on the console and return it. '''
|
||||
result = None
|
||||
import termios
|
||||
fd = sys.stdin.fileno()
|
||||
|
||||
oldterm = termios.tcgetattr(fd)
|
||||
newattr = termios.tcgetattr(fd)
|
||||
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
|
||||
termios.tcsetattr(fd, termios.TCSANOW, newattr)
|
||||
try:
|
||||
result = sys.stdin.read(1)
|
||||
except IOError:
|
||||
pass
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
|
||||
return result
|
||||
|
||||
|
||||
class MXTuning(Tuning):
|
||||
tuneDir='/opt/ppmac/tune/'
|
||||
|
||||
@@ -75,7 +97,7 @@ class MXTuning(Tuning):
|
||||
#identify matlab: k:0.671226 w0:134.705 damp:0.191004
|
||||
mag1=6 #10**(db_mag1/20)
|
||||
db_mag1=20*np.log10(mag1)#dB
|
||||
w1=53.4705*_N #rad/sec
|
||||
w1=50.*_N #rad/sec
|
||||
f1=w1/2/np.pi; # ca. 6.5Hz
|
||||
T1=1/w1
|
||||
d1=0.6 # daempfung =1 -> keine resonanz -> den1= np.poly1d([T1,1])**2
|
||||
@@ -126,7 +148,7 @@ class MXTuning(Tuning):
|
||||
#identify matlab: k:1.7282 w0:51.069 damp:0.327613
|
||||
mag1=12. #10**(db_mag1/20)
|
||||
db_mag1=20*np.log10(mag1)#dB
|
||||
w1=18.*_N #rad/sec
|
||||
w1=21.*_N #rad/sec
|
||||
f1=w1/2/np.pi; # ca. 6.5Hz
|
||||
T1=1/w1
|
||||
d1=0.4 # daempfung =1 -> keine resonanz -> den1= np.poly1d([T1,1])**2
|
||||
@@ -134,8 +156,8 @@ class MXTuning(Tuning):
|
||||
den1 = np.poly1d([T1**2,2*T1*d1,1])
|
||||
|
||||
#resonance frequency
|
||||
f2=np.array([57.8,61.8])
|
||||
d2=np.array([.08,.095])#daempfung
|
||||
f2=np.array([55.,61.])
|
||||
d2=np.array([.2,.2])#daempfung
|
||||
w2=f2*2*np.pi #rad/sec
|
||||
T2=1/w2
|
||||
num2 = np.poly1d([T2[0]**2,2*T2[0]*d2[0],1])
|
||||
@@ -144,7 +166,7 @@ class MXTuning(Tuning):
|
||||
#bode(mdl)
|
||||
|
||||
#resonance frequency
|
||||
f3=np.array([136,148])
|
||||
f3=np.array([128,137])
|
||||
d3=np.array([.05,.05])#daempfung
|
||||
w3=f3*2*np.pi #rad/sec
|
||||
T3=1/w3
|
||||
@@ -456,7 +478,7 @@ EXPORT_SYMBOL(obsvr_servo_ctrl_{motid});'''.format(motid=motid)
|
||||
save_figs(os.path.join(self.baseDir,'bode_model_plot'))
|
||||
|
||||
if mode&64: # plot all raw acquired data files
|
||||
# display bode plots
|
||||
plt.close('all')
|
||||
import glob
|
||||
for fn in glob.glob(os.path.join(self.baseDir,'*.npz')):
|
||||
print(fn)
|
||||
@@ -464,11 +486,64 @@ EXPORT_SYMBOL(obsvr_servo_ctrl_{motid});'''.format(motid=motid)
|
||||
meta = fh['meta'].item()
|
||||
data = fh['data']
|
||||
plt.close('all')
|
||||
self.bode_plot(data, mode=25, kwargs=meta)
|
||||
bm=25
|
||||
if fn.find('all')>0:
|
||||
bm+=32 #amplitude linear (not dB)
|
||||
self.bode_plot(data, mode=bm, kwargs=meta)
|
||||
plt.show(block=False)
|
||||
save_figs(fn)
|
||||
#wait_key()
|
||||
raw_input('press return')
|
||||
|
||||
if mode&128: #generater code
|
||||
|
||||
if mode&128: #custom plots
|
||||
plt.close('all')
|
||||
G1=signal.lti([1/8.8], [2.4E-3/8.8,1]) # num denum
|
||||
print('rise time %e s'%(2.4E-3/8.8))
|
||||
bode(G1)
|
||||
t,y=G1.step()
|
||||
fig=plt.figure();ax=fig.add_subplot(1,1,1)
|
||||
ax.plot(t,y)
|
||||
#current loop 2nd order approx
|
||||
#identification with matlab: k=1, w0=8725, d=0.75
|
||||
dc=.75 # daempfung =1 -> keine resonanz -> den1= np.poly1d([T1,1])**2
|
||||
wc=8725. # rad/sec
|
||||
#...but phase lag seems to have earlier effect -> reduce wc. Probably because of the slower outer servo loop
|
||||
wc*=.5 # rad/sec
|
||||
Tc=1/wc
|
||||
num=np.poly1d([1.])
|
||||
den=np.poly1d([Tc**2,2*Tc*dc,1])
|
||||
mdl=signal.lti(num, den) # num denum
|
||||
bode(mdl)
|
||||
t,y=mdl.step()
|
||||
ax.plot(t,y)
|
||||
ax.grid(True)
|
||||
plt.show(block=False)
|
||||
raw_input('press return')
|
||||
|
||||
plt.close('all')
|
||||
fn=os.path.join(self.baseDir,'chirp_all_1a.npz')
|
||||
fh=np.load(fn)
|
||||
data=fh['data']
|
||||
meta=fh['meta'].item()
|
||||
meta['file']=fn
|
||||
# 2 DesPos,ActPos,IqCmd,IqMeas,IqVolts (for current, plant and regulation transfer function)
|
||||
for xy in ((2, 3), (2, 4)):
|
||||
self.bode_plot(data, xy=xy, mode=25+32, kwargs=meta)
|
||||
|
||||
fig=plt.figure(2)
|
||||
fig.axes[0].set_ylim(.9, 1.1)
|
||||
fig.axes[1].set_ylim(-40,10)
|
||||
fig.suptitle('tf: iqCmd->iqMeas', fontsize=16)
|
||||
fig=plt.figure(4)
|
||||
fig.axes[0].set_ylim(15,30)
|
||||
fig.axes[1].set_ylim(-20,20)
|
||||
fig.suptitle('tf: iqCmd->iqVolts', fontsize=16)
|
||||
plt.show(block=False)
|
||||
save_figs(os.path.join(self.baseDir,'iqCmd_TF'))
|
||||
|
||||
|
||||
if mode&256: #generater code
|
||||
#before this can be done, the observer controller has to be designed with matlab:
|
||||
#s.a.ESB_MX/matlab/Readme.md
|
||||
#clear;
|
||||
@@ -501,9 +576,10 @@ EXPORT_SYMBOL(obsvr_servo_ctrl_{motid});'''.format(motid=motid)
|
||||
fh.close()
|
||||
print(fnc+' generated.')
|
||||
print('now compile it looking at PBTools/pbtools/usr_servo_phase/usrServoSample')
|
||||
|
||||
print('done')
|
||||
plt.show()
|
||||
plt.show(block=False)
|
||||
raw_input('press return')
|
||||
|
||||
|
||||
def save_figs(fn):
|
||||
figures = [manager.canvas.figure
|
||||
@@ -524,14 +600,14 @@ def bode(mdl):
|
||||
w,mag,phase = signal.bode(mdl,1000)
|
||||
f=w/(2*np.pi)
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(2, 1, 1)
|
||||
ax.semilogx(f,mag,'-') # Bode magnitude plot
|
||||
ax.yaxis.set_label_text('dB ampl')
|
||||
ax1 = fig.add_subplot(2, 1, 1)
|
||||
ax1.semilogx(f,mag,'-') # Bode magnitude plot
|
||||
ax1.yaxis.set_label_text('dB ampl')
|
||||
plt.grid(True)
|
||||
ax = fig.add_subplot(2, 1, 2)
|
||||
ax.semilogx(f,phase,'-') # Bode magnitude plot
|
||||
ax.yaxis.set_label_text('phase')
|
||||
ax.xaxis.set_label_text('frequency [Hz]')
|
||||
ax2 = fig.add_subplot(2, 1, 2, sharex = ax1)
|
||||
ax2.semilogx(f,phase,'-') # Bode magnitude plot
|
||||
ax2.yaxis.set_label_text('phase')
|
||||
ax2.xaxis.set_label_text('frequency [Hz]')
|
||||
plt.grid(True)
|
||||
#plt.show()
|
||||
|
||||
@@ -577,6 +653,7 @@ Examples:'''+''.join(map(lambda s:cmd+s, exampleCmd))+'\n '
|
||||
tune.baseDir=args.dir
|
||||
assert(os.path.exists(tune.baseDir))
|
||||
tune.run(args.mode)
|
||||
|
||||
#------------------ Main Code ----------------------------------
|
||||
#ssh_test()'/tmp/usrcode.c'
|
||||
ret=parse_args()
|
||||
|
||||
Reference in New Issue
Block a user