/************************************************************************** Description: Программа - упаковщик. Автор: Улитовский Д.И. Дата последнего обновления: 2021.09.23 **************************************************************************/ #define S_FUNCTION_NAME wrapper_inu #define S_FUNCTION_LEVEL 2 #include "simstruc.h" #include "math.h" #include "wrapper_inu.h" #define MDL_UPDATE /* Function: mdlUpdate ==================================================== * Abstract: * This function is called once for every major integration time step. * Discrete states are typically updated here, but this function is useful * for performing any tasks that should only take place once per * integration step. */ static void mdlUpdate(SimStruct *S, int_T tid) { const real_T *u = (const real_T*) ssGetInputPortRealSignal(S,0); real_T *xD = ssGetDiscStates(S); real_T *rW = ssGetRWork(S); int_T *iW = ssGetIWork(S); controller(S, u, xD, rW, iW); }//end mdlUpdate /* Function: mdlCheckParameters =========================================== * Abstract: * mdlCheckParameters verifies new parameter settings whenever parameter * change or are re-evaluated during a simulation. */ #define MDL_CHECK_PARAMETERS /* Change to #undef to remove function */ #if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE) static void mdlCheckParameters(SimStruct *S) { int i; // Проверяем и принимаем параметры и разрешаем или запрещаем их менять // в процессе моделирования for (i=0; i 2) { ssSetErrorStatus(S,"Параметр м.б. только скаляром, вектором или матрицей"); return; } // Parameter not tunable // ssSetSFcnParamTunable(S, i, SS_PRM_NOT_TUNABLE); // Parameter tunable (we must create a corresponding run-time parameter) ssSetSFcnParamTunable(S, i, SS_PRM_TUNABLE); // Parameter tunable only during simulation // ssSetSFcnParamTunable(S, i, SS_PRM_SIM_ONLY_TUNABLE); }//for (i=0; i and are documented in * matlabroot/simulink/include/simstruc.h. The options should be * bitwise or'd together as in * ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_name2)) */ // С помощью опции SS_OPTION_EXCEPTION_FREE_CODE обещаем, что в // нашей программе нет "исключений" ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE)); }//end mdlInitializeSizes /* Function: mdlInitializeSampleTimes ===================================== * Abstract: * This function is used to specify the sample time(s) for your * S-function. You must register the same number of sample times as * specified in ssSetNumSampleTimes. */ static void mdlInitializeSampleTimes(SimStruct *S) { double dt; // Шаг дискретизации dt = mxGetPr(ssGetSFcnParam(S,NPARAMS-1))[0]; // Register one pair for each sample time ssSetSampleTime(S, 0, dt); ssSetOffsetTime(S, 0, 0.0); }//end mdlInitializeSampleTimes #define MDL_START // Change to #undef to remove function #if defined(MDL_START) /* Function: mdlStart ===================================================== * Abstract: * This function is called once at start of model execution. If you * have states that should be initialized once, this is the place * to do it. */ static void mdlStart(SimStruct *S) { int_T *iW = ssGetIWork(S); iW[0] = 1;//processParameters iW[1] = 1;//start } #endif // MDL_START /* Function: mdlOutputs =================================================== * Abstract: * In this function, you compute the outputs of your S-function * block. Generally outputs are placed in the output vector(s), * ssGetOutputPortSignal. */ static void mdlOutputs(SimStruct *S, int_T tid) { real_T *y = ssGetOutputPortRealSignal(S,0); real_T *xD = ssGetDiscStates(S); int i; // OUTPUTS for (i=0; i