永磁同步电动机永磁同步电机(S函数搭建)的转子位置动态面跟踪时改变给定频率,当角频率>1时,给定为2sin(2t),转子位置不正确,跟不上给定
我认为是参数问题但不知道如何调。
以下是建模:
以下是S函数代码:
function [sys,x0,str,ts,simStateCompliance] = controller20 (t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);**
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 4;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 4;
sizes.NumInputs = 5;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0,0,0,0];
str = [];
ts = [0 0];
function sys=mdlDerivatives(t,x,u)
%微分函数
%以下系数皆可调
k1=150;%动态面参数(主要调)
k2=150; %动态面参数(主要调)
np=3;%极对数(不可调)
B=0.001158;
J=0.003798;
Rs=0.68;
y=0.1245;
tt2=0.01;
tt3=0.01;
r1=2;
r2=2;
TL=1.5;
p1=0.02;
p2=0.02;
Ld=0.00285;
Lq=0.00315;
%以下a-c为系数,不用管
a1=1.5*np*y;
a2=1.5*np*(Ld-Lq);
b1=-Rs/Lq;
b2=-np*Ld/Lq;
b3=-np*y/Lq;
b4=1/Lq;
c1=-Rs/Ld;
c2=np*Lq/Ld;
c3=1/Ld;
%以下为状态方程
dx(1)=(-k1*u(1)+u(2)-x(1))/tt2;
dx(2)=((-k2-1)*(u(3)-x(1))+x(3)*u(3)+x(4)*(-k1*u(1)+u(2)-x(1))/tt2-a1*x(2))/(a1*tt3);
dx(3)=-r1*((u(3)-x(1))*u(3)+p1*x(3));
dx(4)=-r2*((u(3)-x(1))*(-k1*u(1)+u(2)-x(1))/tt2+p2*x(4));
sys=[dx(1);dx(2);dx(3);dx(4)];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u)
%输出函数
k1=150;%动态面参数(主要调)
k2=150; %动态面参数(主要调)
k3=10;%动态面参数(主要调)
k4=5;%动态面参数(主要调)
np=3;
B=0.001158;
J=0.003798;
Rs=0.68;
y=0.1245;
tt2=0.01;
tt3=0.01;
r1=2;
r2=2;
TL=1.5;
p1=0.02;
p2=0.02;
Ld=0.00285;
Lq=0.00315;
a1=1.5*np*y;
a2=1.5*np*(Ld-Lq);
b1=-Rs/Lq;
b2=-np*Ld/Lq;
b3=-np*y/Lq;
b4=1/Lq;
c1=-Rs/Ld;
c2=np*Lq/Ld;
c3=1/Ld;
f1=b1*u(4)+b2*u(3)*u(5)+b3*u(3);
f2=c1*u(5)+c2*u(3)*u(4)+a2*(u(3)-x(1))*u(4);
a=((-k3-0.5)*(u(4)-x(2))-f1+((-k2-1)*(u(3)-x(1))+x(3)*u(3)+x(4)*(-k1*u(1)+u(2)-x(1))/tt2-a1*x(2))/(a1*tt3))/b4;
b=((-k4-0.5)*u(5)-f2)/c3;
sys=[a;b;f1;f2];