|
Autor |
Simulation, S-Function |
|
Nadia97
Neu  Dabei seit: 27.10.2019 Mitteilungen: 1
 | Themenstart: 2019-10-27
|
Hallo Leute,
ich arbeite zur Zeit an einer permanenterregten Synchronmaschine und werde diese mit S-function Level 1 simulieren. Allerdings wird jedes Mal ein „Error" angezeigt und ich verstehe nicht, woher der kommt.
Also es sind 3 Eingänge (Ud, Uq, ML) und 4 Ausgänge (Wele, id, iq, theta).
\sourceon Matlab
\numberson
function [sys,x0,str,ts] = Testcsfunc(t,x,u,flag)
Rs=0.2 % Widerstand
Ld=8.5e-3 % Induktivität in d-Achse
Lq=8.5e-3 % Induktivität in q-Achse
F=0.175 % Polradfluss
J=0.0027 % Massenträgheitsmoment
P=4 % Polpaar
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,x,u),
case 3,
sys=mdlOutputs(t,x,u);
case { 2, 4, 9 }
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 4;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 4;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = zeros (4,1);
27/10/19 13:20 C:\Users\lenovo\Desktop\B...\Testcsfunc.m 2 of 3
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [0 0];
% Specify the block simStateCompliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'DisallowSimState' < Error out when saving or restoring the model sim state
simStateCompliance = 'UnknownSimState';
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
x1dot= -(Rs/Ld)*x(1)+(Lq/Ld)*x(3)*x(2)+(1/Ld)*u(1);
x2dot= -(Ld/Lq)*x(3)*x(1)-(Rs/Lq)*x(2)+(1/Lq)*u(2)-x(3)*(F/Lq);
x3dot= (3*P^2/2*J)*(Ld-Lq)*x(2)*x(1)+(3*P^2/2*J)*F*x(2)-(P/J)*u(3);
x4dot= x(3);
sys= [x1dot x2dot x3dot x4dot];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
sys = [x(1) x(2) x(3) x(4)];
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block. Note that the result is
% absolute time. Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys=mdlTerminate(t,x,u)
sys = [];
% end mdlTerminate
\sourceoff
Der Error lautet:
Not enough input arguments.
Error in Testcsfunc (line 3)
switch flag,
Falls mir jemand helfen kann, würde ich mich sehr freuen.
Vielen Dank im Voraus
https://matheplanet.com/matheplanet/nuke/html/uploads/b/52122_gleichungen.png
|
Profil
| Folgende Antworten hat der Fragensteller vermutlich noch nicht gesehen. Er/sie war noch nicht wieder auf dem Matheplaneten |
majoka
Senior  Dabei seit: 25.02.2014 Mitteilungen: 814
 | Beitrag No.1, eingetragen 2019-10-28
|
Hallo Nadia97,
willkommen im Forum.
Ich kenne mich mit dem Thema nicht besonders gut aus. Die S-Function ist doch aber dafür gedacht in Simulink ausgeführt zu werden. Wie sieht bei Dir die Einbindung in Simulink aus?
Bei mir läuft Dein Code in Simulink, wenn ich noch zusätzlich die physikalischen Parameter in die Unterfunktion "mdlDerivatives" schreibe:
\sourceon Matlab
function sys=mdlDerivatives(t,x,u)
Rs=0.2; % Widerstand
Ld=8.5e-3; % Induktivität in d-Achse
Lq=8.5e-3; % Induktivität in q-Achse
F=0.175; % Polradfluss
J=0.0027; % Massenträgheitsmoment
P=4; % Polpaar
x1dot= -(Rs/Ld)*x(1)+(Lq/Ld)*x(3)*x(2)+(1/Ld)*u(1);
x2dot= -(Ld/Lq)*x(3)*x(1)-(Rs/Lq)*x(2)+(1/Lq)*u(2)-x(3)*(F/Lq);
x3dot= (3*P^2/2*J)*(Ld-Lq)*x(2)*x(1)+(3*P^2/2*J)*F*x(2)-(P/J)*u(3);
x4dot= x(3);
sys= [x1dot x2dot x3dot x4dot];
\sourceoff
Mit dem Befehl
\sourceon Matlab
sfundemos
\sourceoff
kann man auch Demos für solche Funktionen finden.
Gruß
majoka
|
Profil
|
Nadia97 wird per Mail über neue Antworten informiert. |
|
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest © 2001-2023 by Matroids Matheplanet
This web site was originally made with PHP-Nuke, a former web portal system written in PHP that seems no longer to be maintained nor supported. PHP-Nuke is Free Software released under the GNU/GPL license.
Ich distanziere mich von rechtswidrigen oder anstößigen Inhalten, die sich trotz aufmerksamer Prüfung hinter hier verwendeten Links verbergen mögen. Lesen Sie die
Nutzungsbedingungen,
die Distanzierung,
die Datenschutzerklärung und das Impressum.
[Seitenanfang]
|