Download What Is an S
Transcript
S-Function Examples • If this method is compiled as a MEX-file, ssGetSFcnParamsCount determines how many parameters the user actually entered into the S-function dialog. If the number of user-specified parameters matches the number returned by ssGetNumSFcnParams, the method calls mdlCheckParameters to check the validity of the user-entered data. Otherwise, the S-function errors out. • If the parameter check passes, the S-function specifies the number of continuous and discrete states using ssSetNumContStates and ssSetNumDiscStates, respectively. In this example, there are no discrete states. The number of continuous states is set based on the number of coefficients in the transfer function’s denominator. • Next, ssSetNumInputPorts specifies that the S-function has a single input port whose width is set by ssSetInputPortWidth to be two times the length of the denominator plus one. The input port’s sample time is then set to the value provided by the third S-function dialog parameter and indicates the rate at which the transfer function will be modified. The input port’s offset time is set to zero. Note that the input port is also set to have direct feedthrough by passing a value of 1 to ssSetInputPortDirectFeedThrough. • ssSetNumOutputPorts specifies that the S-function has a single output port. The width of this output port is set to one using ssSetOutputPortWidth. ssSetOutputPortSampleTime specifies that the output port has a continuous sample time and ssSetOutputPortOffsetTime sets the offset time to zero. • ssSetNumSampleTimes then specifies that there are two sample times, which will be configured later in the mdlInitializeSampleTimes function. • A value of four times the number of denominator coefficients is passed to ssSetNumRWork to set the length of the floating-point work vector. ssSetNumIWork then sets the length of the integer work vector to two. The RWork vectors is used to storetwo banks of transfer function coefficients, while the IWork vector is used to indicate which bank in the RWork vector is currently in use. The other work vectors are initialized with lengths of zero to indicate that these work vectors are not used by this S-function. Note that these lines could be omitted since zero is the default value for all of these macros. For clarity, it is preferable to explicitly set the number of work vectors. • Lastly, any applicable options are set using ssSetOptions. In this case, SS_OPTION_EXCEPTION_FREE_CODE stipulates that the code is exception free. 7-105
Related documents
Writing S-Functions
MATLAB SIMULINK 7 - DEVELOPING S-FUNCTIONS User`s guide
Developement Of An Instrument Landing Simulation Using MATLAB
An Integrated, Modular Simulation System for Education and
MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER User`s guide
Simulink User's Guide
Motion Control of Industrial Printers
7.0 User`s Manual - Opal-RT