Dummy-Output-S-Function für Simulink
Diese minimale S-Function implementiert eine Dummy-Output-Funktion. Sie empfängt ein Double-Eingangssignal und ignoriert es vollständig. Sie führt keine weitere Aktion aus.
Diese S-Function kann verwendet werden, um zu verhindern, dass Simulink Blöcke wegoptimiert, die keine Auswirkung auf den Modell-Output haben. Wenn Sie beispielsweise einen Block haben, der einige Berechnungen durchführt, aber dessen Output nirgendwo verwendet wird, könnte Simulink ihn während der Codegenerierung wegoptimieren. Indem Sie den Output eines solchen Blocks mit dieser Dummy-Output-S-Function verbinden, können Sie sicherstellen, dass der Block im Modell verbleibt, da Simulink nicht feststellen kann, ob der Output verwendet wird oder nicht.
dummy_output.cpp
dummy_output.cpp
#define S_FUNCTION_NAME dummy_output
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#include <cstdio> // For file handling
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0); // No parameters
ssSetNumContStates(S, 0); // No continuous states
ssSetNumDiscStates(S, 0); // No discrete states
// 1 input port with 1 element
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1); // Input port width = 1
ssSetInputPortDataType(S, 0, SS_DOUBLE);
ssSetInputPortComplexSignal(S, 0, COMPLEX_NO);
ssSetInputPortRequiredContiguous(S, 0, 1); // Require contiguous input port memory
// ssSetInputPortDirectFeedThrough(S, 0, 1); // Direct feedthrough
// No output ports
if (!ssSetNumOutputPorts(S, 0)) return;
// Sample times
ssSetNumSampleTimes(S, 1); // Single sample time
// Work vectors
ssSetNumRWork(S, 0); // Real work vector
ssSetNumIWork(S, 0); // Integer work vector
ssSetNumPWork(S, 0); // Pointer work vector for file pointer
ssSetNumModes(S, 0); // Mode vector
ssSetNumNonsampledZCs(S, 0); // Zero crossings
// Make the S-function block capable of being used in a Real-Time Workshop-generated model
ssSetOptions(S, 0);
}
#define MDL_START
static void mdlStart(SimStruct *S) {
}
// Function: mdlInitializeSampleTimes =========================================
// Abstract:
// Initialize the sample times to be 1ms (1kHz)
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetInputPortSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
// Not needed for this example
static void mdlOutputs(SimStruct *S, int_T tid) {
// Do nothing
}
#define MDL_UPDATE
static void mdlUpdate(SimStruct *S, int_T tid)
{
// Ignore value - this is just a dummy output
}
static void mdlTerminate(SimStruct *S)
{
}
// Required S-function trailer
#ifdef MATLAB_MEX_FILE
#include "simulink.c" // MEX-file interface mechanism
#else
#include "cg_sfun.h" // Code generation interface
#endifKompilieren
compile_dummy_output.sh
mex dummy_output.cppCheck out similar posts by category:
Matlab/Simulink
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow