using level 1 S-function with simulink in simulink about motor parameter identification.

5 visualizzazioni (ultimi 30 giorni)
I am modeling a simulink model with S-functions with motor parameters,id,iq,ud,uq,wr,5 variables.
| |
function [sys,xO,str,ts]=mysystemident(t,x,u,flag,p,lam)
switch flag,
case 0, % 初始化
[sys,xO,str,ts]=mdlInitia1izeSizes(p);
case 2, %离散状态更新
sys=mdlUpdate(t,x,u,lam);
case 3, %计算输出量,亦即控制率和权值
sys=dlOutputs(t,x,u,3);
case {1 4 9} %未 定义的 flag值
sys=[];
otherwise %错误处理
error(['Unhanded flag =',num2str(flag)]);
end
%初始化程序
function [sys,x0,str,ts]=mdlInitializeSizes(p)
sizes=simsizes;
sizes.NumContStates=0; %无连续状态
sizes.NumDiscStates=12;% 系统里的状态变量个数
sizes.NumOutputs=3; %设置 3路输出,受控对象待辨识参数
sizes.Numlnputs=5; %设置 5路输入,输入、输出信号及其 以往值
sizes.DirFeedthrough=O; % 输入信号直接不在输出中反映 出来
sizes.NumSampieTimes=1; %单采样速率系统
sys=simsizes(sizes); %设置系统模型变量
p0=p*eye(3);
x0=[[0.1 0.1 0.1]';p0(:)]; %初始状态变量 (权值 )
str=[];
ts=[-t O];%继承输入信号的采样周期
function u = f(error) %differential
persistent e1
ts = 5e-5;
e = error;
u = ( e - e1) /ts;%微分
e1 = e;%将前一个e记录下来
%离散状态更新函数
function sys=mdlUpdate(t,x,u,lam)
y=[u(2);u(3)-0.175];
psi=[u(4) -u(1)*u(5) f(u(4)); u(5) f(u(5)) u(1)*u(4)]';% psi:2*3; psi': 3*2
% u1 u2 u3 u4 u5 is seperately wr,ud,uq,id,iq
PN=reshape(x(4:end), 3,3); %p:3*3;
K=PN*psi/(lam*eye(2)+psi'*PN*psi);% K:3*2;
PN1=(PN-K*psi'*PN)/lam;
sys=[x(1:3)+K*(y-psi'*x(1:3));PN1(:)];
%输 出计算 函数
function sys=mdl0utputs(t,x,u,M)
sys=x(1:M);%输出为前 M=r+m+1个状态,即系统参数 向量 theta| |
when I used the level-1 s-function in a simulink with 5 inputs and 3 outputs, it reports the same error:
Error1:
in 'sysmodel_newSfun/S-Function' while executing MATLAB S-function 'mysystemident', flag = 0 (initialize), at start of simulation.
Error 2:
Not enough input arguments.
having no idea after looking up books, I need ur help.Please help, thanks in advance.

Risposte (1)

Kaustubha Govind
Kaustubha Govind il 20 Mar 2014
The expected prototype for mdlInitializeSizes is:
[sys,x0,str,ts] = mdlInitializeSizes;
Simulink does pass in any input arguments for flag=0.
Note that it looks like what you need may not be possible with Level-1 S-functions (which have been deprecated for a very long time now). Please consider re-writing this as a Level-2 S-function instead.

Community

Più risposte nel  Power Electronics Control

Categorie

Scopri di più su Block and Blockset Authoring in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by