How to solve this error in S-function "Error evaluating registered method 'Start' of MATLAB S-Function" , Caused by: No method 'ContStates' with matching signature found for class 'Simulink.​MSFcnRunTi​meBlock'.

61 Ansichten (letzte 30 Tage)
i am describing a dynamic system with 12 states . the error originates from the Initial conditions part , i have tried both start and Initialize conditions methods . please explain what i am doing wrong!.
note : the error message indicates error in the first line after " function start(block)"
Here is my code :
function MAV_dynamics(block)
setup(block);
%endfunction
function setup(block)
% Register number of dialog parameters
block.NumDialogPrms = 5;
% Register number of input and output ports
block.NumInputPorts = 6;
block.NumOutputPorts = 12;
% Setup functional port properties to dynamically be inherited.
% block.SetPreCompInpPortInfoToDynamic;
% block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DirectFeedthrough = false;
block.InputPort(2).Dimensions = 1;
block.InputPort(2).DirectFeedthrough = false;
block.InputPort(3).Dimensions = 1;
block.InputPort(3).DirectFeedthrough = false;
block.InputPort(4).Dimensions = 1;
block.InputPort(4).DirectFeedthrough = false;
block.InputPort(5).Dimensions = 1;
block.InputPort(5).DirectFeedthrough = false;
block.InputPort(6).Dimensions = 1;
block.InputPort(6).DirectFeedthrough = false;
block.OutputPort(1).Dimensions = 1;
block.OutputPort(2).Dimensions = 1;
block.OutputPort(3).Dimensions = 1;
block.OutputPort(4).Dimensions = 1;
block.OutputPort(5).Dimensions = 1;
block.OutputPort(6).Dimensions = 1;
block.OutputPort(7).Dimensions = 1;
block.OutputPort(8).Dimensions = 1;
block.OutputPort(9).Dimensions = 1;
block.OutputPort(10).Dimensions = 1;
block.OutputPort(11).Dimensions = 1;
block.OutputPort(12).Dimensions = 1;
% Set block sample time to continuous
block.SampleTimes = [0 0];
% Set up the continuous states.
block.NumContStates = 12;
% Set the block simStateCompliance to default (i.e., same as a built-in block)
block.SimStateCompliance = 'DefaultSimState';
% Register block methods
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Derivatives', @Derivatives);
block.RegBlockMethod('SetInputPortSamplingMode', @SetInpPortFrameData);
block.RegBlockMethod('Outputs', @Outputs);
%endfunction
function Start(block)
block.ContStates(1).Data =0; !------------------Error-----------------!
block.ContStates(2).Data =0;
block.ContStates(3).Data =0;
block.ContStates(4).Data =0;
block.ContStates(5).Data =0;
block.ContStates(6).Data =0;
block.ContStates(7).Data =0;
block.ContStates(8).Data =0;
block.ContStates(9).Data =0;
block.ContStates(10).Data =0;
block.ContStates(11).Data =0;
block.ContStates(12).Data =0;
%endfunction
function Derivatives(block)
%-----States definition---------
Pn= block.ContStates(1).Data ;
Pe= block.ContStates(2).Data ;
Pd= block.ContStates(3).Data ;
U= block.ContStates(4).Data ;
V= block.ContStates(5).Data ;
W= block.ContStates(6).Data ;
phi=block.ContStates(7).Data ;
thi=block.ContStates(8).Data ;
psi=block.ContStates(9).Data ;
P= block.ContStates(10).Data;
Q= block.ContStates(11).Data ;
R= block.ContStates(12).Data ;
%-----Inputs definition---------
Fx=block.InputPort(1).Data;
Fy=block.InputPort(2).Data;
Fz=block.InputPort(3).Data;
l =block.InputPort(4).Data;
m =block.InputPort(5).Data;
n =block.InputPort(6).Data;
%-----Block parameters definition---------
M =block.DialogPrm(1).Data;
Ix =block.DialogPrm(2).Data;
Iy =block.DialogPrm(3).Data;
Iz =block.DialogPrm(4).Data;
Ixz=block.DialogPrm(5).Data;
%-----Constants definition---------
G=(Ix*Iz)-(Ixz^2);
G1=(Ixz*(Ix-Iy+Iz))/G;
G2=((Iz*(Iz-Iy))+Ixz^2)/G;
G3=Iz/G;
G4=Ixz/G;
G5=(Iz-Ix)/Iy;
G6=Ixz/Iy;
G7=((Ix*(Ix-Iy))+Ixz^2)/G;
G8=Ix/G;
block.Derivatives(1).Data = (cos(thi)*cos(psi)*U)+(((sin(phi)*sin(thi)*cos(psi))-(cos(phi)*sin(psi)))*V)+(((cos(phi)*sin(thi)*cos(psi))+(sin(phi)*sin(psi)))*W);
block.Derivatives(2).Data = (cos(thi)*cos(psi)*U)+(((sin(phi)*sin(thi)*sin(psi))+(cos(phi)*cos(psi)))*V)+(((cos(phi)*sin(thi)*sin(psi))-(sin(phi)*cos(psi)))*W);
block.Derivatives(3).Data =(-sin(thi)*U)+((sin(phi)*cos(thi))*V)+((cos(phi)*cos(thi))*W);
block.Derivatives(4).Data=((R*V)-(Q*W))+(Fx/M);
block.Derivatives(5).Data=((P*W)-(R*U))+(Fy/M);
block.Derivatives(6).Data=((Q*U)-(P*V))+(Fz/M);
block.Derivatives(7).Data=P+((sin(phi)*tan(thi))*Q)+((cos(phi)*tan(thi))*R);
block.Derivatives(8).Data=(cos(phi)*Q)+(-sin(phi)*R);
block.Derivatives(9).Data=((sin(phi)/cos(thi))*Q)+((cos(phi)/cos(thi))*R);
block.Derivatives(10).Data=(G1*P*Q)-(G2*q*r)+ ((G3*l)+(G4*n));
block.Derivatives(11).Data=(G5*P*R)-(G6*(P^2-R^2))+ (m/Iy);
block.Derivatives(12).Data=(G7*P*Q)-(G1*q*r)+ ((G4*l)+(G8*n));
%endfunction
function SetInpPortFrameData(block, idx, fd)
block.InputPort(idx).SamplingMode = fd;
block.OutputPort(1).SamplingMode = fd;
block.OutputPort(2).SamplingMode = fd;
block.OutputPort(3).SamplingMode = fd;
block.OutputPort(4).SamplingMode = fd;
block.OutputPort(5).SamplingMode = fd;
block.OutputPort(6).SamplingMode = fd;
block.OutputPort(7).SamplingMode = fd;
block.OutputPort(8).SamplingMode = fd;
block.OutputPort(9).SamplingMode = fd;
block.OutputPort(10).SamplingMode = fd;
block.OutputPort(11).SamplingMode = fd;
block.OutputPort(12).SamplingMode = fd;
%endfunction
function Outputs(block)
% y = x
block.OutputPort(1).Data = block.ContStates(1).Data;
block.OutputPort(2).Data = block.ContStates(2).Data;
block.OutputPort(3).Data = block.ContStates(3).Data;
block.OutputPort(4).Data = block.ContStates(4).Data;
block.OutputPort(5).Data = block.ContStates(5).Data;
block.OutputPort(6).Data = block.ContStates(6).Data;
block.OutputPort(7).Data = block.ContStates(7).Data;
block.OutputPort(8).Data = block.ContStates(8).Data;
block.OutputPort(9).Data = block.ContStates(9).Data;
block.OutputPort(10).Data = block.ContStates(10).Data;
block.OutputPort(11).Data = block.ContStates(11).Data;
block.OutputPort(12).Data = block.ContStates(12).Data;
%endfunction
-----------------------------------------------------------------------------------------------
Error message: Error evaluating registered method 'Start' of MATLAB S-Function 'MAV_dynamics' in 'MAV_Simulator/Level-2 MATLAB S-Function'. The following is the MATLAB call stack (file names and line numbers) that produced this error: ['C:\Users\Gk\Desktop\Matlab\training\S-function\MAV_dynamics.m'] [81]
Caused by: No method 'ContStates' with matching signature found for class 'Simulink.MSFcnRunTimeBlock'.
  2 Kommentare
fiza fiza
fiza fiza am 6 Jan. 2017
Hi kemo,
Have you find the solution for this problem? I encountered the same error too.. very frustrated, since I need to solve this simulation ASAP.. Thanks..

Melden Sie sich an, um zu kommentieren.

Antworten (1)

fdb
fdb am 16 Aug. 2017
I believe you cannot use this notation
block.ContStates(1).Data = 0; block.ContStates(2).Data = 0; ...
as the error "No method 'ContStates' with matching signature found..." implies. Rather use
block.ContStates.Data(1) = 0; block.ContStates.Data(2) = 0; ...
or declare a vector right-away block.ContStates.Data = zeros(12,1);
There is only one set of continuous states, whereas you can have multiple input- / output ports as well as disc. states(?) with multiple dimensions, hence the two-fold indexing in these cases.
Maybe not the most intuitive way to restrict the cont. states notation in that way.
BR Franz

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by