Not enough input arguments on setup function of Level 2 S Function

1 visualizzazione (ultimi 30 giorni)
Hello,
I am trying to construct a Level 2 S-Function that accepts the following inputs:
  • nx1 array of positions
  • nx1 array of velocities
  • nx1 array of accelerations
  • 1 external force (for now)
also, it accepts an input argument TEST that is a structure with many different fields and substructures of various data types. this structure defines all the characteristics of the system and is created in the model workspace upon initialization of the model.
outputs are:
  • nx1 array of calculated 'new' accelerations
  • nxn array of calculated internal forces
I am new to Level 2 S-functions but have stripped down (i.e. commented out) the template to what I believe is the necessary code to achieve what I need.
function dynamicCalculations(block, TEST)
setup(block, TEST);
%endfunction
function setup(block, TEST)
% Register the number of ports.
block.NumInputPorts = 4;
block.NumOutputPorts = 2;
% Set up the port properties to be inherited or dynamic.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override the input port properties.
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).SamplingMode = 'Sample';
block.InputPort(1).Dimensions = [TEST.nTotalElements 1];
block.InputPort(2).DatatypeID = 0; % double
block.InputPort(2).Complexity = 'Real';
block.InputPort(2).SamplingMode = 'Sample';
block.InputPort(2).Dimensions = [TEST.nTotalElements 1];
block.InputPort(3).DatatypeID = 0; % double
block.InputPort(3).Complexity = 'Real';
block.InputPort(3).SamplingMode = 'Sample';
block.InputPort(3).Dimensions = [TEST.nTotalElements 1];
block.InputPort(4).DatatypeID = 0; % double
block.InputPort(4).Complexity = 'Real';
block.InputPort(4).SamplingMode = 'Sample';
block.InputPort(4).Dimensions = [1 1];
% Override the output port properties.
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.OutputPort(1).SamplingMode = 'Sample';
block.OutputPort(1).Dimensions = [TEST.nTotalElements 1];
block.OutputPort(2).DatatypeID = 0; % double
block.OutputPort(2).Complexity = 'Real';
block.OutputPort(2).SamplingMode = 'Sample';
block.OutputPort(2).Dimensions = [TEST.nTotalElements TEST.nTotalElements];
% Register the parameters.
block.NumDialogPrms = 1;
%block.DialogPrmsTunable = {'Tunable','Nontunable','SimOnlyTunable'};
% Set up the continuous states.
block.NumContStates = 1;
block.SampleTimes = [-1 0];
block.SetAccelRunOnTLC(false);
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Outputs', @Outputs);
block.RegBlockMethod('Update', @Update);
%endfunction
I deleted all of the code that was commented out and excluded all of the other non-'setup' functions to make it easier to read... I can add those in if needed to solve this issue
When I run, I get the error: 'Not enough input arguments' on the setup function call line, i.e. setup(block,TEST)
I have included TEST on the Arguments line of the block parameters.
Anything obvious I have done wrong here?
Thanks,
Greg Szkilnyk

Risposte (1)

Archit Dhanani
Archit Dhanani il 31 Lug 2019
The internal architecture calls the setup function with one argument while compiling the SFunction.
setup(block)
Since we have two arguments defined in the SFunction here, we get an error saying not enough argument.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by