Simulink: There is no solver registered as 14.

6 views (last 30 days)
Hello,
Im trying to write nonlinear model for simuling using by Level-2 MATLAB S-Functions. But when i tried to run it in simuling a received error:
  • There is no solver registered as 14.
Solver was choosed as auto with variable step size. With fixed step size i get error:
  • There is no solver registered as 15.
I tried combinations of solvers and fixed step size, but result was on of the two errors.
Simulink model:
Code of the model:
function SotaModel(block)
%MSFUNTMPL_BASIC A Template for a Level-2 MATLAB S-Function
% The MATLAB S-function is written as a MATLAB function with the
% same name as the S-function. Replace 'msfuntmpl_basic' with the
% name of your S-function.
% Copyright 2003-2018 The MathWorks, Inc.
%%
%% The setup method is used to set up the basic attributes of the
%% S-function such as ports, parameters, etc. Do not add any other
%% calls to the main body of the function.
%%
setup(block);
%endfunction
%% Function: setup ===================================================
%% Abstract:
%% Set up the basic characteristics of the S-function block such as:
%% - Input ports
%% - Output ports
%% - Dialog parameters
%% - Options
%%
%% Required : Yes
%% C MEX counterpart: mdlInitializeSizes
%%
function setup(block)
% Register number of ports
block.NumInputPorts = 3;
block.NumOutputPorts = 3;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DirectFeedthrough = true;
block.InputPort(2).Dimensions = 1;
block.InputPort(2).DirectFeedthrough = true;
block.InputPort(3).Dimensions = 1;
block.InputPort(3).DirectFeedthrough = true;
% Override output port properties
block.OutputPort(1).Dimensions = 1;
block.OutputPort(2).Dimensions = 1;
block.OutputPort(3).Dimensions = 1;
% Register parameters
block.NumDialogPrms = 0;
% Register sample times
% [0 offset] : Continuous sample time
% [positive_num offset] : Discrete sample time
%
% [-1, 0] : Inherited sample time
% [-2, 0] : Variable sample time
block.SampleTimes = [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
% 'CustomSimState', < Has GetSimState and SetSimState methods
% 'DisallowSimState' < Error out when saving or restoring the model sim state
block.SimStateCompliance = 'DefaultSimState';
%% -----------------------------------------------------------------
%% The MATLAB S-function uses an internal registry for all
%% block methods. You should register all relevant methods
%% (optional and required) as illustrated below. You may choose
%% any suitable name for the methods and implement these methods
%% as local functions within the same file. See comments
%% provided for each function for more information.
%% -----------------------------------------------------------------
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Derivatives', @Derivatives);
block.RegBlockMethod('Terminate', @Terminate); % Required
block.RegBlockMethod('SetInputPortSamplingMode', @SetInputPortSamplingMode); % Required
%end setup
%%
%% PostPropagationSetup:
%% Functionality : Setup work areas and state variables. Can
%% also register run-time methods here
%% Required : No
%% C MEX counterpart: mdlSetWorkWidths
%%
function DoPostPropSetup(block)
block.NumContStates = 6;
%%
%% Start:
%% Functionality : Called once at start of model execution. If you
%% have states that should be initialized once, this
%% is the place to do it.
%% Required : No
%% C MEX counterpart: mdlStart
%%
function Start(block)
block.ContStates.Data(1) = 0;
block.ContStates.Data(2) = pi;
block.ContStates.Data(3) = pi/2;
block.ContStates.Data(4) = 0;
block.ContStates.Data(5) = 0;
block.ContStates.Data(6) = 0;
%end Start
%%
%% Outputs:
%% Functionality : Called to generate block outputs in
%% simulation step
%% Required : Yes
%% C MEX counterpart: mdlOutputs
%%
function Outputs(block)
block.OutputPort(1).Data = block.ContStates.Data(1);
block.OutputPort(2).Data = block.ContStates.Data(2);
block.OutputPort(3).Data = block.ContStates.Data(3);
%end Outputs
%%
%% Derivatives:
%% Functionality : Called to update derivatives of
%% continuous states during simulation step
%% Required : No
%% C MEX counterpart: mdlDerivatives
%%
function Derivatives(block)
x1 = block.ContStates.Data(1);
x2 = block.ContStates.Data(2);
x3 = block.ContStates.Data(3);
x4 = block.ContStates.Data(4);
x5 = block.ContStates.Data(5);
x6 = block.ContStates.Data(6);
tau1 = block.InputPort(1).Data;
tau2 = block.InputPort(2).Data;
taum = block.InputPort(3).Data;
block.Derivatives.Data = [x4;x5; x6; three long equations with x6 x5 x4 x3 x2 x1 variables.]
%end Derivatives
%%
%% Terminate:
%% Functionality : Called at the end of simulation for cleanup
%% Required : Yes
%% C MEX counterpart: mdlTerminate
%%
function Terminate(block)
%end Terminate
function SetInputPortSamplingMode(block, idx, fd)
block.InputPort(idx).SamplingMode = fd;
block.OutputPort(1).SamplingMode = fd;
block.OutputPort(2).SamplingMode = fd;
block.OutputPort(3).SamplingMode = fd;

Answers (1)

Bill Tubbs
Bill Tubbs on 3 May 2021
I don't know exactly what caused this error but I found I could run the msfcn_limintm.m example from the S-functions in the documentation which is a continous-time model and noticed that the following line is in the setup function:
%% Setup Dwork
block.NumContStates = 1;
I had put a similar line in the PostPropagationSetup function and I found that if I moved it to the setup function and deleted the PostPropagationSetup function, the error went away and it runs in Simulink correctly.
Not sure if this will work in your case but it's worth a try since you also put it in the DoPostPropSetup function.

Tags

Community Treasure Hunt

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

Start Hunting!