void mdlInitializeSizes(SimStruct *S) /* ======================================================================== */ { /* parameters */ ssSetNumSFcnParams(S, NUM_PARAMS); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) return; } else return; #endif ssSetSFcnParamTunable(S, FREQUENCY, SS_PRM_SIM_ONLY_TUNABLE); ssSetSFcnParamTunable(S, BANDWIDTH, SS_PRM_NOT_TUNABLE); ssSetSFcnParamTunable(S, TXVGA_GAIN, SS_PRM_SIM_ONLY_TUNABLE); /* ports */ ssSetNumSampleTimes(S, 1); if (!ssSetNumOutputPorts(S, 0) || !ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED); ssSetInputPortComplexSignal(S, 0, COMPLEX_YES); ssSetInputPortDataType(S, 0, SS_INT8); ssSetInputPortDirectFeedThrough(S, 0, true); ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL); /* work Vectors */ ssSetNumPWork(S, P_WORK_LENGTH); ssSetNumIWork(S, 0); ssSetNumRWork(S, NUM_PARAMS); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }
/*=====================================* * Configuration and execution methods * *=====================================*/ static void mdlInitializeSizes(SimStruct *S) { #ifdef DEBUG debug("mdlInitializeSizes entered.\n"); #endif ssSetNumSFcnParams(S, NPAR); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) return; } ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, NI); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, NO); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); #ifdef DEBUG debug("mdlInitializeSizes left.\n"); #endif } /* mdlInitializeSizes */
static void mdlInitializeSizes( SimStruct *S ) /* ======================================================================== */ { int_T port; /* set number of expected parameters and check for a mismatch. */ ssSetNumSFcnParams( S, NUM_PARAMS ); #if defined(MATLAB_MEX_FILE) if ( ssGetNumSFcnParams( S ) == ssGetSFcnParamsCount( S ) ) { mdlCheckParameters( S ); if ( ssGetErrorStatus( S ) != NULL ) return; }else { return; } #endif /* sampling */ ssSetNumSampleTimes( S, PORT_BASED_SAMPLE_TIMES ); /* Set number of input ports and tunability */ ssSetSFcnParamTunable( S, DEVICE_INDEX, SS_PRM_NOT_TUNABLE ); /* set the resulting number of ports */ if ( !ssSetNumInputPorts( S, 1 ) ) return; port = 0; { const Frame_T inputsFrames = ( (double) mxGetScalar( ssGetSFcnParam( S, USE_FRAMES ) ) > 0.0) ? FRAME_YES : FRAME_NO; double sample_time = 1 / mxGetScalar( ssGetSFcnParam( S, SAMPLE_RATE ) ); const int_T buf_length = (int_T) (double) mxGetScalar( ssGetSFcnParam( S, FRAME_LENGTH ) ); const time_T period = (time_T) (sample_time * buf_length); ssSetInputPortMatrixDimensions( S, port, buf_length, 1 ); ssSetInputPortComplexSignal( S, port, COMPLEX_YES ); ssSetInputPortDataType( S, port, SS_DOUBLE ); ssSetInputPortFrameData( S, port, inputsFrames ); ssSetInputPortDirectFeedThrough( S, port, 1 ); ssSetInputPortSampleTime( S, port, period ); ssSetInputPortOffsetTime( S, port, 0.0 ); } /* Set number of output ports */ if ( !ssSetNumOutputPorts( S, 0 ) ) return; /* data port properties */ /* Prepare work Vectors */ ssSetNumPWork( S, P_WORK_LENGTH ); ssSetNumIWork( S, I_WORK_LENGTH ); ssSetNumRWork( S, R_WORK_LENGTH ); ssSetNumModes( S, 0 ); ssSetNumNonsampledZCs( S, 0 ); /* Specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance( S, USE_DEFAULT_SIM_STATE ); ssSetOptions( S, 0 ); }
static void mdlInitializeSizes(SimStruct *S) { uint_T i; ssSetNumSFcnParams(S, NUMBER_OF_PARAMS); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; } #endif for (i = 0; i < NUMBER_OF_PARAMS; i++) { ssSetSFcnParamNotTunable(S, i); } ssSetNumInputPorts(S, 0); ssSetNumOutputPorts(S, 1); ssSetOutputPortWidth(S, 0, 1); ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); ssSetNumSampleTimes(S, 1); ssSetNumPWork(S,1); ssSetNumIWork(S,1); ssSetNumRWork(S,2); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { /* See sfuntmpl_doc.c for more details on the macros below */ ssSetNumSFcnParams(S, NUM_PARAMS); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) /* Return if number of expected != number of actual parameters */ return; } else return; ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); ssSetNumInputPorts(S, 0); ssSetNumOutputPorts(S, 0); ssSetNumSampleTimes(S, 1); ssSetSFcnParamTunable(S, 0, 0); ssSetSFcnParamTunable(S, 1, 0); ssSetSFcnParamTunable(S, 2, 0); ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_CAN_BE_CALLED_CONDITIONALLY); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { /* See sfuntmpl_doc.c for more details on the macros below */ ssSetNumSFcnParams(S, 5); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink. */ } #endif int_T nRobots = mxGetNumberOfElements(ssGetSFcnParam(S,2)); ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 0)) return; //ssSetInputPortWidth(S, 0, 1); //ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/ /* * Set direct feedthrough flag (1=yes, 0=no). * A port has direct feedthrough if the input is used in either * the mdlOutputs or mdlGetTimeOfNextVarHit functions. * See matlabroot/simulink/src/sfuntmpl_directfeed.txt. */ //ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 4)) return; const int_T nDofs = *((mxChar*)mxGetData(ssGetSFcnParam(S, 4))); ssSetOutputPortMatrixDimensions(S, 0, nDofs, nRobots); // position ssSetOutputPortMatrixDimensions(S, 1, nDofs, nRobots); // velocity ssSetOutputPortMatrixDimensions(S, 2, nDofs, nRobots); // effort ssSetOutputPortMatrixDimensions(S, 3, 1, nRobots); // SentTime in s; ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 2); // nRobots, nDofs ssSetNumPWork(S, nRobots + 1); //nRobots x GenericSub, AsyncSpinner ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* Specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { /* See sfuntmpl_doc.c for more details on the macros below */ ssSetNumSFcnParams(S, 2); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink. */ } #endif ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 2)) return; ssSetInputPortMatrixDimensions(S, 0, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED); // triangles ssSetInputPortDataType(S, 0, SS_UINT32); ssSetInputPortMatrixDimensions(S, 1, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED); // vertices for (int_T i = 0; i < ssGetNumInputPorts(S); ++i) { /*direct input signal access*/ ssSetInputPortRequiredContiguous(S, i, true); /* * Set direct feedthrough flag (1=yes, 0=no). * A port has direct feedthrough if the input is used in either * the mdlOutputs or mdlGetTimeOfNextVarHit functions. * See matlabroot/simulink/src/sfuntmpl_directfeed.txt. */ ssSetInputPortDirectFeedThrough(S, i, 1); } if (!ssSetNumOutputPorts(S, 0)) return; ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 2); //GenericPub and frame id ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* Specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }
// Function: mdlInitializeSizes =============================================== // Abstract: // The sizes information is used by Simulink to determine the S-function // block's characteristics (number of inputs, s, states, etc.). static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, NPARAMS); #if defined(MATLAB_MEX_FILE) if(ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)){ mdlCheckParameters(S); if(ssGetErrorStatus(S)!=NULL){ return; } else{ cout<<"All parameters have been checked and passed correctly"<<endl; } } else{ return; // Parameter mismatch reported by Simulink } #endif // Parameter mismatch will be reported by Simulink if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; } // Specify I/O // INPUTS if(!ssSetNumInputPorts(S,0)) return; // OUTPUTS if (!ssSetNumOutputPorts(S,SIZE_READING_PORT)) return; for (int i = 0; i < SIZE_READING_PORT; i++) { ssSetOutputPortWidth (S, i, 1); ssSetOutputPortDataType(S, i, 0); } ssSetNumSampleTimes(S, 1); // Reserve place for C++ object ssSetNumPWork(S, 1); // DWork vectors ssSetNumDWork(S, 1); ssSetDWorkWidth(S, 0, 1); ssSetDWorkDataType(S, 0, SS_DOUBLE); ssSetSimStateCompliance(S, USE_CUSTOM_SIM_STATE); ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE | SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_ALLOW_INPUT_SCALAR_EXPANSION | SS_OPTION_USE_TLC_WITH_ACCELERATOR); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif { int iParam = 0; int nParam = ssGetNumSFcnParams(S); for ( iParam = 0; iParam < nParam; iParam++ ) { ssSetSFcnParamTunable( S, iParam, SS_PRM_SIM_ONLY_TUNABLE ); } } ssSetNumContStates(S, NSTATES); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, NINPUTS)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 0, TRUE); ssSetInputPortWidth(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 1, TRUE); ssSetInputPortWidth(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 2, TRUE); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; //ssSetOutputPortWidth(S, 0, NOUTPUTS); { ssSetOutputPortWidth(S, 0, 1); } ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * Setup sizes of the various vectors. */ static void mdlInitializeSizes(SimStruct *S) { DECL_AND_INIT_DIMSINFO(inputDimsInfo); DECL_AND_INIT_DIMSINFO(outputDimsInfo); ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif ssSetNumContStates(S, NUM_CONT_STATES); ssSetNumDiscStates(S, NUM_DISC_STATES); if (!ssSetNumInputPorts(S, NUM_INPUTS)) return; inputDimsInfo.width = INPUT_0_WIDTH; ssSetInputPortDimensionInfo(S, 0, &inputDimsInfo); ssSetInputPortFrameData(S, 0, IN_0_FRAME_BASED); ssSetInputPortDataType(S, 0, SS_UINT32); ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX); ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH); ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/ if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return; outputDimsInfo.width = OUTPUT_0_WIDTH; ssSetOutputPortDimensionInfo(S, 0, &outputDimsInfo); ssSetOutputPortFrameData(S, 0, OUT_0_FRAME_BASED); ssSetOutputPortDataType(S, 0, SS_DOUBLE); ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX); ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_WORKS_WITH_CODE_REUSE)); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { /* See sfuntmpl_doc.c for more details on the macros below */ ssSetNumSFcnParams(S, 5); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink. */ } #endif ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 0)) return; if (!ssSetNumOutputPorts(S, 0)) return; ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 1); // nWaitTopic size_t wait_buflen = mxGetN((ssGetSFcnParam(S, 2)))*sizeof(mxChar)+1; char* wait_name = (char*)mxMalloc(wait_buflen); mxGetString((ssGetSFcnParam(S, 2)), wait_name, wait_buflen); char * topic = strtok(wait_name, TOPIC_SEPARATORS); unsigned int nWaitTopic = 0; while (topic != NULL){ nWaitTopic++; topic = strtok(NULL, TOPIC_SEPARATORS); } mxFree(wait_name); ssSetNumPWork(S, 4+nWaitTopic+1); //Start + Stop + Synchronous + Trigger services + wait_topic Subscriber(s) + AsyncSpinner ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* Specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }