Matlab Simulink start --------------------- ``` [gfa-lc6-64 ~] [-bash INSTBASE=/prod]$ cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/matlab module load matlab/2018a matlab& or start directly: /afs/psi.ch/sys/psi.x86_64_slp6/Programming/matlab/2018a/bin/matlab& this works also on my linux computers ``` Files overview -------------- ``` identifyFxFyStage.m: read python data and build motor objects. plot bode simFxFyStage.m: build a pb structure which contains current Okt 2018) Powerbrick controller settings StateSpaceControlDesign.m: design a discrete observer for Fx,Fy stages ``` important calls --------------- ``` clear; clear global; close all; [mot1,mot2]=identifyFxFyStage(); [pb]=simFxFyStage(mot1);sim('stage_closed_loop'); close all;[ssc]=StateSpaceControlDesign(mot1);sim('observer'); [pb]=simFxFyStage(mot2);sim('stage_closed_loop'); close all;[ssc]=StateSpaceControlDesign(mot2);sim('observer'); mögliche tf: iqCmd---->iqMeas iqVolts-->iqMeas iqMeas--->actPos ``` Optimizing params ----------------- ``` %Kaff = 1/(Ts*Ts*K) = 1/((11.84*2*np.pi)**2/5000**2) = 4517.278506241803 %Kfff=100 pb.Kp=25;pb.Kvfb=350;pb.Ki=0.02;pb.Kvff=350;pb.Kaff=1/(1.548e04*(pb.Ts^2));pb.MaxInt=1000; %19.8Hz 0dB K=(19.8*2*np.pi)**2=15477.1 Ts=5kHz=.2ms %Kaff = 1/(Ts*Ts*K) = 1/((19.8*2*np.pi)**2/5000**2) = 1615.2877200403302 /opt/gfa/python-2.7/2018.12/bin/python -c 'import wx' OTHER VERSION DO NOT YET HAVE WX ********** ORIG ************** motion average error x 1.54099 um, y 1.04259 um, 2.0391 um shot average error x 1.68984 um, y 1.42837 um, 2.47304 um Motor[1].Servo.Kp=25 Motor[1].Servo.Kvfb=400 Motor[1].Servo.Ki=0.02 Motor[1].Servo.Kvff=350 Motor[1].Servo.Kaff=5000 Motor[1].Servo.MaxInt=1000 Motor[1].Servo.Kfff=0 Motor[2].Servo.Kp=22 Motor[2].Servo.Kvfb=350 Motor[2].Servo.Ki=0.02 Motor[2].Servo.Kvff=240 Motor[2].Servo.Kaff=1500 Motor[2].Servo.MaxInt=1000 Motor[2].Servo.Kfff=0 ********** OPTIMIZED ************** motion average error x 0.663518 um, y 0.585719 um, 1.01806 um shot average error x 0.865708 um, y 0.965126 um, 1.49323 um Motor[1].Servo.Kp=25 Motor[1].Servo.Kvfb=350 Motor[1].Servo.Ki=0.02 Motor[1].Servo.Kvff=350 Motor[1].Servo.Kaff=1615. // 1/(1.548e04*(pb.Ts^2)) Motor[1].Servo.MaxInt=1000 Motor[1].Servo.Kfff=10 //try on real system to optimize Motor[2].Servo.Kp=22 Motor[2].Servo.Kvfb=450 Motor[2].Servo.Ki=0.02 Motor[2].Servo.Kvff=450 Motor[2].Servo.Kaff=4517 Motor[2].Servo.MaxInt=1000 Motor[2].Servo.Kfff=10 //try on real system to optimize OLD STUFF ========= Matlab Simulink up to 11.7.2018 ------------------------------- ``` Open and run ESB_stage.m (takes very long to open simulink...) // default frq: 20 kHz Phase, 5 kHz Servo, 6.25MHz AdcAmp Values for current loop: PwmSf-> User MAnual page 245 PwmSf=15134.8909 # =.95*16384. PMAC3-style DSPGATE3 ASIC is being used for the output, the counter moves between +/- 16384. PwmSf is typically set to 95% of 16384 scale = 1 for 2 phase motors = cos(30)=0.866 for 3 phase motors Amplifier specs (Power Brick LV User Manual.pdf p.19) 5A_rms continous current 15A_rms peak current 14 bit ADC resolution 2us PWM deadBand 33.85A Maximum ADC Current (corresponds to a DAC Value 32737 ==2^15) Tested values from IDE: 3 Phase, 1A_rms -> MaxDac=1184.895 = np.sqrt(2)*np.sqrt(3)/2*32767/33.850 3 Phase, 1A_peak -> MaxDac=837.8478 = np.sqrt(3)/2*32767/33.850 A_peak=A_rms*sqrt(2) np.sqrt(3)/2 because of 3 phase (the coil has not always current) A_peak is used. (A_rms is more dangerous to burn the motor) if not kw.has_key('IdCmd'): kw['IdCmd'] = dirCur*scale kw['MaxDac'] = peakCur*scale; gpasciiCommander --host MOTTEST-CPPM-CRM0573 -i $$$*** !common() !encoder_inc(enc=1,tbl=9,mot=9) !encoder_sim(enc=1) !motor(mot=1,dirCur=200,JogSpeed=1024,invDir=False,InPosBand=1) Defaut: IiGain=.2 IpfGain=6 IpbGain=6 Current loop: -> Monitor idMead, idVolts idVolts: -32768..32,767 Value that goes to the PWM out{constant} specifying the output magnitude as a percentage of the maximum output parameter for the motor: Motor[x].MaxDac. Motor[1].MaxDac=580.80603 #1out1 -> 1 % of 580.8 -> Motor[1].ServoOut=5.808 -> idVolts= 1500 -> idMeas = 155 https://ch.mathworks.com/de/products/simcontrol.html https://ch.mathworks.com/help/slcontrol/ug/design-compensator-in-simulink-using-automated-pid-tuning.html#responsive_offcanvas https://ch.mathworks.com/help/slcontrol/ug/analyze-designs-using-response-plots.html https://ch.mathworks.com/help/control/ug/bode-diagram-design.html https://ch.mathworks.com/help/control/ug/edit-compensator-dynamics.html https://ch.mathworks.com/help/control/ug/root-locus-design.html controlSystemDesigner(1,sys); controlSystemDesigner('bode',sys); ```