MATLAB数值仿真FOC矢量控制
本文通过数值仿真加深对FOC矢量控制的理解。状态空间方程本质上是微分方程,本文的核心之处利用四阶龙格库塔方法求解PMSM状态空间方程。在建模的过程中,整个模型中,忽略了逆变器建模,电机状态方程选择了旋转轴系的状态方程,因此省去了unti-park环节。仿真模型分为三个子模块,电机状态方程求解模块(PMSM模块)、控制环路模块、坐标变换模块,代码基本通过MATLAB-Function模块实现。
Simulink整体截图
PMSM模块1
function [id_now,iq_now,n_now,theta_now,d] = rungekutta_PMSM(uq,ud)
% id_now = id_last+Ts*(ud-R*id_last+omega_e*Ld*iq_last)/Ld;
% iq_now = iq_last+Ts*(uq-R*iq_last-omega_e*Ld*id_last-omega_e*psi_f)/Lq;
persistent iq_last id_last omega_last theta_last j
if isempty(iq_last)
iq_last = 0;
id_last = 0;
omega_last = 0;
theta_last = 2;
j = 5000;
end
% Ld = 0.0028;
% Lq = 0.0028;
% Pn = 4;
% psi_f = 0.109;
% J = 0.000245;
% R = 1.86;
Ld = 0.0068;
Lq = 0.0152;
Pn = 3;
psi_f = 0.24;
J = 0.001;
R = 0.98;
if j<2
load = 2;
else
load = 0;
end
Ts = 0.0001;
% h = Ts/2;
h = Ts;
k=zeros(4,4);
id_last_initial = id_last;
iq_last_initial = iq_last;
omega_last_initial = omega_last;
for i=1:1:3
k(i,1) = (ud-R*id_last+omega_last*Ld*iq_last)/Ld;
k(i,2) = (uq-R*iq_last-omega_last*Ld*id_last-omega_last*psi_f)/Lq;
Te = 1.5*Pn*iq_last*psi_f;
k(i,3) = (Te-load)/J/Pn;
%k(i,4) = omega_last;
id_last = id_last+h;
iq_last = iq_last+h;
omega_last = omega_last+h;
end
id_now = id_last_initial+(k(1,1)+2*k(2,1)+2*k(3,1)+k(4,1))*h/6;
iq_now = iq_last_initial+(k(1,2)+2*k(2,2)+2*k(3,2)+k(4,2))*h/6;
omega_now = omega_last_initial+(k(1,3)+2*k(2,3)+2*k(3,3)+k(4,3))*h/6;
n_now = omega_now*60/2/pi/Pn;
theta_now = theta_last+omega_now*Ts;
id_last = id_now;
iq_last = iq_now;
omega_last = omega_now;
theta_last = theta_now;
j=j-1;
d = j;
控制环路模块2
此模块又分三个子模块,1个速度环和2个电流环模块。
function y = speed_loop(iq_ref,iq_fdb)
persistent error_1 Ui
if isempty(error_1)
error_1=0;
Ui=0;
end
Lq = 0.0152;
R = 0.98;
a = 3000;
Kp = 0.06;
Ki = 0.04*20;
Ts = 0.0001;
error = iq_ref-iq_fdb;
Up = Kp*error;
Ui = Ki*Ts*error+Ui;
y = Up + Ui;
%限幅
max = 2.4;
min = -max;
if y > max
y = max;
elseif y < min
y =min;
else
y = y;
end
function uq = current_loop_iq(iq_ref,iq_fdb)
persistent error_1 Ui
if isempty(error_1)
error_1=0;
Ui=0;
end
Lq = 0.0152;
R = 0.98;
a = 3000;
Kp = Lq*a;
Ki = R*a;
Ts = 0.0001;
error = iq_ref-iq_fdb;
Up = Kp*error;
Ui = Ki*Ts*error+Ui;
uq = Up + Ui;
Vdc = 60;
max = 0.9*Vdc*sqrt(1/3);
min = -max;
if uq > max
uq = max;
elseif uq < min
uq = min;
else
uq = uq;
end
function ud = current_loop_id(id_ref,id_fdb)
persistent error_1 Ui
if isempty(error_1)
error_1=0;
Ui=0;
end
Ld = 0.0068;
R = 0.98;
a = 3000;
Kp = Ld*a;
Ki = R*a;
Ts = 0.0001;
error = id_ref-id_fdb;
Up = Kp*error;
Ui = Ki*Ts*error+Ui;
ud = Up + Ui;
Vdc = 60;
max = 0.9*Vdc*sqrt(1/3);
min = -max;
if ud > max
ud = max;
elseif ud < min
ud =min;
else
ud = ud;
end
坐标变换模块3
可以观察两相静止轴系、三相静止轴系的电流信息
function [alpha,beta] = anti_park(d,q,theta)
alpha = d*cos(theta)-q*sin(theta);
beta = d*sin(theta)+q*cos(theta);
function [a,b,c] = anti_clarke(alpha,beta)
a = alpha;
b = -1/2*alpha+sqrt(3)/2*beta;
c = -1/2*alpha-sqrt(3)/2*beta;