Esempio n. 1
0
/* Model initialize function */
void model1_initialize(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* initialize real-time model */
  (void) memset((void *)model1_M, 0,
                sizeof(RT_MODEL_model1_T));
  rtmSetTFinal(model1_M, 2.0);
  model1_M->Timing.stepSize0 = 5.0E-5;

  /* Setup for data logging */
  {
    static RTWLogInfo rt_DataLoggingInfo;
    model1_M->rtwLogInfo = &rt_DataLoggingInfo;
  }

  /* Setup for data logging */
  {
    rtliSetLogXSignalInfo(model1_M->rtwLogInfo, (NULL));
    rtliSetLogXSignalPtrs(model1_M->rtwLogInfo, (NULL));
    rtliSetLogT(model1_M->rtwLogInfo, "tout");
    rtliSetLogX(model1_M->rtwLogInfo, "");
    rtliSetLogXFinal(model1_M->rtwLogInfo, "");
    rtliSetLogVarNameModifier(model1_M->rtwLogInfo, "rt_");
    rtliSetLogFormat(model1_M->rtwLogInfo, 0);
    rtliSetLogMaxRows(model1_M->rtwLogInfo, 1000);
    rtliSetLogDecimation(model1_M->rtwLogInfo, 1);
    rtliSetLogY(model1_M->rtwLogInfo, "");
    rtliSetLogYSignalInfo(model1_M->rtwLogInfo, (NULL));
    rtliSetLogYSignalPtrs(model1_M->rtwLogInfo, (NULL));
  }

  /* states (dwork) */
  (void) memset((void *)&model1_DW, 0,
                sizeof(DW_model1_T));

  /* Matfile logging */
  rt_StartDataLoggingWithStartTime(model1_M->rtwLogInfo, 0.0, rtmGetTFinal
    (model1_M), model1_M->Timing.stepSize0, (&rtmGetErrorStatus(model1_M)));

  /* Enable for Sin: '<S11>/Sine Wave A' */
  model1_DW.systemEnable = 1;

  /* Enable for Sin: '<S11>/Sine Wave B' */
  model1_DW.systemEnable_i = 1;

  /* Enable for Sin: '<S11>/Sine Wave C' */
  model1_DW.systemEnable_g = 1;
}
Esempio n. 2
0
/* Model initialize function */
void HConstfolding_initialize(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* initialize real-time model */
  (void) memset((void *)HConstfolding_M, 0,
                sizeof(RT_MODEL_HConstfolding));

  /* Initialize timing info */
  {
    int_T *mdlTsMap = HConstfolding_M->Timing.sampleTimeTaskIDArray;
    mdlTsMap[0] = 0;
    HConstfolding_M->Timing.sampleTimeTaskIDPtr = (&mdlTsMap[0]);
    HConstfolding_M->Timing.sampleTimes =
      (&HConstfolding_M->Timing.sampleTimesArray[0]);
    HConstfolding_M->Timing.offsetTimes =
      (&HConstfolding_M->Timing.offsetTimesArray[0]);

    /* task periods */
    HConstfolding_M->Timing.sampleTimes[0] = (1.0);

    /* task offsets */
    HConstfolding_M->Timing.offsetTimes[0] = (0.0);
  }

  rtmSetTPtr(HConstfolding_M, &HConstfolding_M->Timing.tArray[0]);

  {
    int_T *mdlSampleHits = HConstfolding_M->Timing.sampleHitArray;
    mdlSampleHits[0] = 1;
    HConstfolding_M->Timing.sampleHits = (&mdlSampleHits[0]);
  }

  rtmSetTFinal(HConstfolding_M, 1.0E+8);
  HConstfolding_M->Timing.stepSize0 = 1.0;

  /* Setup for data logging */
  {
    static RTWLogInfo rt_DataLoggingInfo;
    HConstfolding_M->rtwLogInfo = &rt_DataLoggingInfo;
  }

  /* Setup for data logging */
  {
    rtliSetLogXSignalInfo(HConstfolding_M->rtwLogInfo, (NULL));
    rtliSetLogXSignalPtrs(HConstfolding_M->rtwLogInfo, (NULL));
    rtliSetLogT(HConstfolding_M->rtwLogInfo, "tout");
    rtliSetLogX(HConstfolding_M->rtwLogInfo, "");
    rtliSetLogXFinal(HConstfolding_M->rtwLogInfo, "");
    rtliSetSigLog(HConstfolding_M->rtwLogInfo, "");
    rtliSetLogVarNameModifier(HConstfolding_M->rtwLogInfo, "rt_");
    rtliSetLogFormat(HConstfolding_M->rtwLogInfo, 0);
    rtliSetLogMaxRows(HConstfolding_M->rtwLogInfo, 1000);
    rtliSetLogDecimation(HConstfolding_M->rtwLogInfo, 1);

    /*
     * Set pointers to the data and signal info for each output
     */
    {
      static void * rt_LoggedOutputSignalPtrs[] = {
        &HConstfolding_Y.Out1
      };

      rtliSetLogYSignalPtrs(HConstfolding_M->rtwLogInfo, ((LogSignalPtrsType)
        rt_LoggedOutputSignalPtrs));
    }

    {
      static int_T rt_LoggedOutputWidths[] = {
        1
      };

      static int_T rt_LoggedOutputNumDimensions[] = {
        1
      };

      static int_T rt_LoggedOutputDimensions[] = {
        1
      };

      static boolean_T rt_LoggedOutputIsVarDims[] = {
        0
      };

      static void* rt_LoggedCurrentSignalDimensions[] = {
        (NULL)
      };

      static int_T rt_LoggedCurrentSignalDimensionsSize[] = {
        4
      };

      static BuiltInDTypeId rt_LoggedOutputDataTypeIds[] = {
        SS_DOUBLE
      };

      static int_T rt_LoggedOutputComplexSignals[] = {
        0
      };

      static const char_T *rt_LoggedOutputLabels[] = {
        "" };

      static const char_T *rt_LoggedOutputBlockNames[] = {
        "HConstfolding/Out1" };

      static RTWLogDataTypeConvert rt_RTWLogDataTypeConvert[] = {
        { 0, SS_DOUBLE, SS_DOUBLE, 0, 0, 0, 1.0, 0, 0.0 }
      };

      static RTWLogSignalInfo rt_LoggedOutputSignalInfo[] = {
        {
          1,
          rt_LoggedOutputWidths,
          rt_LoggedOutputNumDimensions,
          rt_LoggedOutputDimensions,
          rt_LoggedOutputIsVarDims,
          rt_LoggedCurrentSignalDimensions,
          rt_LoggedCurrentSignalDimensionsSize,
          rt_LoggedOutputDataTypeIds,
          rt_LoggedOutputComplexSignals,
          (NULL),

          { rt_LoggedOutputLabels },
          (NULL),
          (NULL),
          (NULL),

          { rt_LoggedOutputBlockNames },

          { (NULL) },
          (NULL),
          rt_RTWLogDataTypeConvert
        }
      };

      rtliSetLogYSignalInfo(HConstfolding_M->rtwLogInfo,
                            rt_LoggedOutputSignalInfo);

      /* set currSigDims field */
      rt_LoggedCurrentSignalDimensions[0] = &rt_LoggedOutputWidths[0];
    }

    rtliSetLogY(HConstfolding_M->rtwLogInfo, "yout");
  }

  HConstfolding_M->solverInfoPtr = (&HConstfolding_M->solverInfo);
  HConstfolding_M->Timing.stepSize = (1.0);
  rtsiSetFixedStepSize(&HConstfolding_M->solverInfo, 1.0);
  rtsiSetSolverMode(&HConstfolding_M->solverInfo, SOLVER_MODE_SINGLETASKING);

  /* states (dwork) */
  (void) memset((void *)&HConstfolding_DWork, 0,
                sizeof(D_Work_HConstfolding));

  /* external outputs */
  HConstfolding_Y.Out1 = 0.0;

  /* Matfile logging */
  rt_StartDataLoggingWithStartTime(HConstfolding_M->rtwLogInfo, 0.0,
    rtmGetTFinal(HConstfolding_M), HConstfolding_M->Timing.stepSize0,
    (&rtmGetErrorStatus(HConstfolding_M)));

  /* Initialize Sizes */
  HConstfolding_M->Sizes.numContStates = (0);/* Number of continuous states */
  HConstfolding_M->Sizes.numY = (1);   /* Number of model outputs */
  HConstfolding_M->Sizes.numU = (0);   /* Number of model inputs */
  HConstfolding_M->Sizes.sysDirFeedThru = (0);/* The model is not direct feedthrough */
  HConstfolding_M->Sizes.numSampTimes = (1);/* Number of sample times */
  HConstfolding_M->Sizes.numBlocks = (14);/* Number of blocks */
  HConstfolding_M->Sizes.numBlockIO = (0);/* Number of block outputs */
  HConstfolding_M->Sizes.numBlockPrms = (10);/* Sum of parameter "widths" */

  /* InitializeConditions for UnitDelay: '<Root>/Unit Delay' */
  HConstfolding_DWork.UnitDelay_DSTATE = HConstfolding_P.UnitDelay_X0;

  /* InitializeConditions for UnitDelay: '<Root>/Unit Delay1' */
  HConstfolding_DWork.UnitDelay1_DSTATE = HConstfolding_P.UnitDelay1_X0;
}
Esempio n. 3
0
/* Model initialize function */
void Koordinatentransfer3_initialize(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* initialize real-time model */
  (void) memset((void *)Koordinatentransfer3_M, 0,
                sizeof(RT_MODEL_Koordinatentransfer3_T));
  rtmSetTFinal(Koordinatentransfer3_M, 0.1);
  Koordinatentransfer3_M->Timing.stepSize0 = 0.02;

  /* Setup for data logging */
  {
    static RTWLogInfo rt_DataLoggingInfo;
    Koordinatentransfer3_M->rtwLogInfo = &rt_DataLoggingInfo;
  }

  /* Setup for data logging */
  {
    rtliSetLogXSignalInfo(Koordinatentransfer3_M->rtwLogInfo, (NULL));
    rtliSetLogXSignalPtrs(Koordinatentransfer3_M->rtwLogInfo, (NULL));
    rtliSetLogT(Koordinatentransfer3_M->rtwLogInfo, "tout");
    rtliSetLogX(Koordinatentransfer3_M->rtwLogInfo, "");
    rtliSetLogXFinal(Koordinatentransfer3_M->rtwLogInfo, "");
    rtliSetLogVarNameModifier(Koordinatentransfer3_M->rtwLogInfo, "rt_");
    rtliSetLogFormat(Koordinatentransfer3_M->rtwLogInfo, 0);
    rtliSetLogMaxRows(Koordinatentransfer3_M->rtwLogInfo, 1000);
    rtliSetLogDecimation(Koordinatentransfer3_M->rtwLogInfo, 1);

    /*
     * Set pointers to the data and signal info for each output
     */
    {
      static void * rt_LoggedOutputSignalPtrs[] = {
        &Koordinatentransfer3_Y.a,
        &Koordinatentransfer3_Y.b,
        &Koordinatentransfer3_Y.c
      };

      rtliSetLogYSignalPtrs(Koordinatentransfer3_M->rtwLogInfo,
                            ((LogSignalPtrsType)rt_LoggedOutputSignalPtrs));
    }

    {
      static int_T rt_LoggedOutputWidths[] = {
        1,
        1,
        1
      };

      static int_T rt_LoggedOutputNumDimensions[] = {
        1,
        1,
        1
      };

      static int_T rt_LoggedOutputDimensions[] = {
        1,
        1,
        1
      };

      static boolean_T rt_LoggedOutputIsVarDims[] = {
        0,
        0,
        0
      };

      static void* rt_LoggedCurrentSignalDimensions[] = {
        (NULL),
        (NULL),
        (NULL)
      };

      static int_T rt_LoggedCurrentSignalDimensionsSize[] = {
        2,
        2,
        2
      };

      static BuiltInDTypeId rt_LoggedOutputDataTypeIds[] = {
        SS_DOUBLE,
        SS_DOUBLE,
        SS_DOUBLE
      };

      static int_T rt_LoggedOutputComplexSignals[] = {
        0,
        0,
        0
      };

      static const char_T *rt_LoggedOutputLabels[] = {
        "",
        "",
        "" };

      static const char_T *rt_LoggedOutputBlockNames[] = {
        "Koordinatentransfer3/a",
        "Koordinatentransfer3/b",
        "Koordinatentransfer3/c" };

      static RTWLogDataTypeConvert rt_RTWLogDataTypeConvert[] = {
        { 0, SS_DOUBLE, SS_DOUBLE, 0, 0, 0, 1.0, 0, 0.0 },

        { 0, SS_DOUBLE, SS_DOUBLE, 0, 0, 0, 1.0, 0, 0.0 },

        { 0, SS_DOUBLE, SS_DOUBLE, 0, 0, 0, 1.0, 0, 0.0 }
      };

      static RTWLogSignalInfo rt_LoggedOutputSignalInfo[] = {
        {
          3,
          rt_LoggedOutputWidths,
          rt_LoggedOutputNumDimensions,
          rt_LoggedOutputDimensions,
          rt_LoggedOutputIsVarDims,
          rt_LoggedCurrentSignalDimensions,
          rt_LoggedCurrentSignalDimensionsSize,
          rt_LoggedOutputDataTypeIds,
          rt_LoggedOutputComplexSignals,
          (NULL),

          { rt_LoggedOutputLabels },
          (NULL),
          (NULL),
          (NULL),

          { rt_LoggedOutputBlockNames },

          { (NULL) },
          (NULL),
          rt_RTWLogDataTypeConvert
        }
      };

      rtliSetLogYSignalInfo(Koordinatentransfer3_M->rtwLogInfo,
                            rt_LoggedOutputSignalInfo);

      /* set currSigDims field */
      rt_LoggedCurrentSignalDimensions[0] = &rt_LoggedOutputWidths[0];
      rt_LoggedCurrentSignalDimensions[1] = &rt_LoggedOutputWidths[1];
      rt_LoggedCurrentSignalDimensions[2] = &rt_LoggedOutputWidths[2];
    }

    rtliSetLogY(Koordinatentransfer3_M->rtwLogInfo, "yout");
  }

  /* external inputs */
  (void) memset((void *)&Koordinatentransfer3_U, 0,
                sizeof(ExtU_Koordinatentransfer3_T));

  /* external outputs */
  (void) memset((void *)&Koordinatentransfer3_Y, 0,
                sizeof(ExtY_Koordinatentransfer3_T));

  /* Matfile logging */
  rt_StartDataLoggingWithStartTime(Koordinatentransfer3_M->rtwLogInfo, 0.0,
    rtmGetTFinal(Koordinatentransfer3_M),
    Koordinatentransfer3_M->Timing.stepSize0, (&rtmGetErrorStatus
    (Koordinatentransfer3_M)));
}
/* Model initialize function */
void trajectoryModel_initialize(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* non-finite (run-time) assignments */
  trajectoryModel_P.stopRadius = rtInf;

  /* initialize real-time model */
  (void) memset((void *)trajectoryModel_M, 0,
                sizeof(RT_MODEL_trajectoryModel_T));

  {
    /* Setup solver object */
    rtsiSetSimTimeStepPtr(&trajectoryModel_M->solverInfo,
                          &trajectoryModel_M->Timing.simTimeStep);
    rtsiSetTPtr(&trajectoryModel_M->solverInfo, &rtmGetTPtr(trajectoryModel_M));
    rtsiSetStepSizePtr(&trajectoryModel_M->solverInfo,
                       &trajectoryModel_M->Timing.stepSize0);
    rtsiSetdXPtr(&trajectoryModel_M->solverInfo,
                 &trajectoryModel_M->ModelData.derivs);
    rtsiSetContStatesPtr(&trajectoryModel_M->solverInfo, (real_T **)
                         &trajectoryModel_M->ModelData.contStates);
    rtsiSetNumContStatesPtr(&trajectoryModel_M->solverInfo,
      &trajectoryModel_M->Sizes.numContStates);
    rtsiSetErrorStatusPtr(&trajectoryModel_M->solverInfo, (&rtmGetErrorStatus
      (trajectoryModel_M)));
    rtsiSetRTModelPtr(&trajectoryModel_M->solverInfo, trajectoryModel_M);
  }

  rtsiSetSimTimeStep(&trajectoryModel_M->solverInfo, MAJOR_TIME_STEP);
  trajectoryModel_M->ModelData.intgData.y = trajectoryModel_M->ModelData.odeY;
  trajectoryModel_M->ModelData.intgData.f[0] = trajectoryModel_M->
    ModelData.odeF[0];
  trajectoryModel_M->ModelData.intgData.f[1] = trajectoryModel_M->
    ModelData.odeF[1];
  trajectoryModel_M->ModelData.intgData.f[2] = trajectoryModel_M->
    ModelData.odeF[2];
  trajectoryModel_M->ModelData.contStates = ((X_trajectoryModel_T *)
    &trajectoryModel_X);
  rtsiSetSolverData(&trajectoryModel_M->solverInfo, (void *)
                    &trajectoryModel_M->ModelData.intgData);
  rtsiSetSolverName(&trajectoryModel_M->solverInfo,"ode3");
  rtmSetTPtr(trajectoryModel_M, &trajectoryModel_M->Timing.tArray[0]);
  rtmSetTFinal(trajectoryModel_M, 12.0);
  trajectoryModel_M->Timing.stepSize0 = 0.01;

  /* Setup for data logging */
  {
    static RTWLogInfo rt_DataLoggingInfo;
    trajectoryModel_M->rtwLogInfo = &rt_DataLoggingInfo;
  }

  /* Setup for data logging */
  {
    rtliSetLogXSignalInfo(trajectoryModel_M->rtwLogInfo, (NULL));
    rtliSetLogXSignalPtrs(trajectoryModel_M->rtwLogInfo, (NULL));
    rtliSetLogT(trajectoryModel_M->rtwLogInfo, "tout");
    rtliSetLogX(trajectoryModel_M->rtwLogInfo, "");
    rtliSetLogXFinal(trajectoryModel_M->rtwLogInfo, "");
    rtliSetLogVarNameModifier(trajectoryModel_M->rtwLogInfo, "rt_");
    rtliSetLogFormat(trajectoryModel_M->rtwLogInfo, 0);
    rtliSetLogMaxRows(trajectoryModel_M->rtwLogInfo, 1000);
    rtliSetLogDecimation(trajectoryModel_M->rtwLogInfo, 1);
    rtliSetLogY(trajectoryModel_M->rtwLogInfo, "");
    rtliSetLogYSignalInfo(trajectoryModel_M->rtwLogInfo, (NULL));
    rtliSetLogYSignalPtrs(trajectoryModel_M->rtwLogInfo, (NULL));
  }

  /* block I/O */
  (void) memset(((void *) &trajectoryModel_B), 0,
                sizeof(B_trajectoryModel_T));

  /* states (continuous) */
  {
    (void) memset((void *)&trajectoryModel_X, 0,
                  sizeof(X_trajectoryModel_T));
  }

  /* states (dwork) */
  (void) memset((void *)&trajectoryModel_DW, 0,
                sizeof(DW_trajectoryModel_T));

  /* Matfile logging */
  rt_StartDataLoggingWithStartTime(trajectoryModel_M->rtwLogInfo, 0.0,
    rtmGetTFinal(trajectoryModel_M), trajectoryModel_M->Timing.stepSize0,
    (&rtmGetErrorStatus(trajectoryModel_M)));

  /* Start for If: '<Root>/If' */
  trajectoryModel_DW.If_ActiveSubsystem = -1;

  /* Start for IfAction SubSystem: '<Root>/If Action Subsystem' */
  traject_IfActionSubsystem_Start(&trajectoryModel_B.IfActionSubsystem,
    (P_IfActionSubsystem_trajector_T *)&trajectoryModel_P.IfActionSubsystem);

  /* End of Start for SubSystem: '<Root>/If Action Subsystem' */

  /* Start for IfAction SubSystem: '<Root>/If Action Subsystem1' */
  traject_IfActionSubsystem_Start(&trajectoryModel_B.IfActionSubsystem1,
    (P_IfActionSubsystem_trajector_T *)&trajectoryModel_P.IfActionSubsystem1);

  /* End of Start for SubSystem: '<Root>/If Action Subsystem1' */

  /* InitializeConditions for Integrator: '<Root>/x' */
  trajectoryModel_X.x_CSTATE = trajectoryModel_P.initialConditions[0];

  /* InitializeConditions for Integrator: '<Root>/y ' */
  trajectoryModel_X.y_CSTATE = trajectoryModel_P.initialConditions[2];

  /* InitializeConditions for Integrator: '<Root>/dx' */
  trajectoryModel_X.dx_CSTATE = trajectoryModel_P.initialConditions[1];

  /* InitializeConditions for Integrator: '<Root>/dy' */
  trajectoryModel_X.dy_CSTATE = trajectoryModel_P.initialConditions[3];
}
Esempio n. 5
0
/* Function: main ==============================================================
 *
 *      Execute model on a generic target such as a workstation.
 */
int_T main(int_T argc, char_T *argv[])
{
    SimStruct  *S                 = NULL;
    boolean_T  calledMdlStart     = FALSE;
    boolean_T  dataLoggingActive  = FALSE;
    boolean_T  initializedExtMode = FALSE;
    const char *result;
    const char *program;
    time_t     now;
    int matFileFormat;
    const char *errorPrefix       = NULL;
    void *parforSchedulerInit     = NULL;

    program = argv[0];
    gblInstalledSigHandlers = FALSE;
    /* No re-defining of data types allowed. */
    if ((sizeof(real_T)   != 8) ||
        (sizeof(real32_T) != 4) ||
        (sizeof(int8_T)   != 1) ||
        (sizeof(uint8_T)  != 1) ||
        (sizeof(int16_T)  != 2) ||
        (sizeof(uint16_T) != 2) ||
        (sizeof(int32_T)  != 4) ||
        (sizeof(uint32_T) != 4) ||
        (sizeof(boolean_T)!= 1)) {
        ERROR_EXIT("Error: %s\n", "Re-defining data types such as REAL_T is not supported by RSIM");
    }

    rt_InitInfAndNaN(sizeof(real_T));


    /* Parse arguments */
    gblErrorStatus = ParseArgs(argc, argv);
    ERROR_EXIT("Error parsing input arguments: %s\n", gblErrorStatus);

    /* Initialize the model */
    S = raccel_register_model();
    ERROR_EXIT("Error during model registration: %s\n", ssGetErrorStatus(S));

    ssClearFirstInitCondCalled(S);
    /* Override StopTime */
    if (gblFinalTimeChanged) ssSetTFinal(S,gblFinalTime);

    MdlInitializeSizes();
    MdlInitializeSampleTimes();

    /* We don't have GOTO_EXIT_IF_ERROR here as engine is not initialized 
       via rsimInitializeEngine */
    rt_RapidReadMatFileAndUpdateParams(S);
    ERROR_EXIT("Error reading parameter data from mat-file: %s\n",
              ssGetErrorStatus(S));

    /* load solver options */
    rsimLoadSolverOpts(S);
    ERROR_EXIT("Error loading solver options: %s\n", ssGetErrorStatus(S));

# if defined(DEBUG_SOLVER)
    rsimEnableDebugOutput(sizeof(struct SimStruct_tag),
                          sizeof(struct _ssMdlInfo));
# endif

#ifdef RACCEL_PARALLEL_FOREACH
    parforSchedulerInit = rt_ParallelForEachInitScheduler(S, RACCEL_PARFOREACH_NUM_THREADS, RACCEL_NUM_PARFOREACH_SS);
#endif

    rsimInitializeEngine(S);
    ERROR_EXIT("Error initializing RSIM engine: %s\n", ssGetErrorStatus(S));

    /* initialize external model */
    if (gblExtModeEnabled) {
        rtExtModeCheckInit(ssGetNumSampleTimes(S));
        initializedExtMode = TRUE;       
    }

    raccel_setup_MMIStateLog(S);

    if (ssIsVariableStepSolver(S)) {
        (void)rt_StartDataLoggingWithStartTime(ssGetRTWLogInfo(S),
                                               ssGetTStart(S),
                                               ssGetTFinal(S),
                                               0.0,
                                               &ssGetErrorStatus(S));
    } else {
        (void)rt_StartDataLoggingWithStartTime(ssGetRTWLogInfo(S),
                                               ssGetTStart(S),
                                               ssGetTFinal(S),
                                               ssGetStepSize(S),
                                               &ssGetErrorStatus(S));
    }
    GOTO_EXIT_IF_ERROR("Error starting data logging: %s\n", 
                       ssGetErrorStatus(S));
    dataLoggingActive = TRUE;

    if (gblExtModeEnabled) {
        /* If -w flag is specified wait here for connect signal from host */
        rtExtModeWaitForStartPkt(ssGetRTWExtModeInfo(S),
                                 ssGetNumSampleTimes(S),
                                 (boolean_T *)&ssGetStopRequested(S));
        if (ssGetStopRequested(S)) goto EXIT_POINT;
    }

    /* Start the model */
    now = time(NULL);
    if(gblVerboseFlag) {
        (void)printf("\n** Starting model @ %s", ctime(&now));
        }

    /* Enable logging in the MdlStart method */
    ssSetLogOutput(S,TRUE);

    /* Enable -i option to load inport data file */
    result = rt_RapidReadInportsMatFile(gblInportFileName, &matFileFormat);
    if (result!= NULL) {
        ssSetErrorStatus(S,result);
        GOTO_EXIT_IF_ERROR("Error starting model: %s\n",  ssGetErrorStatus(S));
    }

    MdlStart();
    ssSetLogOutput(S,FALSE);

    calledMdlStart = TRUE;
    GOTO_EXIT_IF_ERROR("Error starting model: %s\n", ssGetErrorStatus(S));

    result = rt_RapidCheckRemappings();
    ssSetErrorStatus(S,result);
    GOTO_EXIT_IF_ERROR("Error: %s\n", ssGetErrorStatus(S));

    /* Create solver data */
    rsimCreateSolverData(S, gblSlvrJacPatternFileName);
    GOTO_EXIT_IF_ERROR("Error creating solver data: %s\n", ssGetErrorStatus(S));

    ssSetFirstInitCondCalled(S);

    /*********************
     * Execute the model *
     *********************/

    /* Install Signal and Run time limit handlers */
    
    rsimInstallAllHandlers(S,WriteResultsToMatFile,gblTimeLimit);
    

    gblInstalledSigHandlers = TRUE;
    GOTO_EXIT_IF_ERROR("Error: %s\n", ssGetErrorStatus(S));

    while ( ((ssGetTFinal(S)-ssGetT(S)) > (fabs(ssGetT(S))*DBL_EPSILON)) ) {

        if (gblExtModeEnabled) {
            rtExtModePauseIfNeeded(ssGetRTWExtModeInfo(S),
                                   ssGetNumSampleTimes(S),
                                   (boolean_T *)&ssGetStopRequested(S));
        }
        if (ssGetStopRequested(S)) break;

        if (gbl_raccel_isMultitasking) {
            rsimOneStepMT(S);
        } else {
            rsimOneStepST(S);
        }
        if (ssGetErrorStatus(S)) break;
    }
    if (ssGetErrorStatus(S) == NULL && !ssGetStopRequested(S)) {
        /* Do a major step at the final time */
        if (gbl_raccel_isMultitasking) {
            rsimOneStepMT(S);
        } else { 
            rsimOutputLogUpdate(S);
        }
    }

  EXIT_POINT:
    /********************
     * Cleanup and exit *
     ********************/
    if (ssGetErrorStatus(S) != NULL) {
        if (errorPrefix) {
            (void)fprintf(stderr, errorPrefix, ssGetErrorStatus(S));
        } else {
            (void)fprintf(stderr, "Error: %s\n", ssGetErrorStatus(S));
        }
    }
    if (gblInstalledSigHandlers) {
        rsimUninstallNonfatalHandlers();
        gblInstalledSigHandlers = FALSE;
    }
    if (dataLoggingActive){
        WriteResultsToMatFile(S);
    }

    
    rsimTerminateEngine(S,0);
    
        
    if (initializedExtMode) {
        rtExtModeShutdown(ssGetNumSampleTimes(S));
    }
    if (calledMdlStart) {
        MdlTerminate();
    }

#ifdef RACCEL_PARALLEL_FOREACH
    rt_ParallelForEachClearScheduler(parforSchedulerInit);
#endif

    rt_RapidFreeGbls(matFileFormat);
    return ssGetErrorStatus(S) ? EXIT_FAILURE : EXIT_SUCCESS;

} /* end main */
Esempio n. 6
0
/* Model initialize function */
void Hammerstein_initialize(void)
{
  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* initialize real-time model */
  (void) memset((void *)Hammerstein_M, 0,
                sizeof(RT_MODEL_Hammerstein));
  rtsiSetSolverName(&Hammerstein_M->solverInfo,"FixedStepDiscrete");
  Hammerstein_M->solverInfoPtr = (&Hammerstein_M->solverInfo);

  /* Initialize timing info */
  {
    int_T *mdlTsMap = Hammerstein_M->Timing.sampleTimeTaskIDArray;
    mdlTsMap[0] = 0;
    Hammerstein_M->Timing.sampleTimeTaskIDPtr = (&mdlTsMap[0]);
    Hammerstein_M->Timing.sampleTimes = (&Hammerstein_M->
      Timing.sampleTimesArray[0]);
    Hammerstein_M->Timing.offsetTimes = (&Hammerstein_M->
      Timing.offsetTimesArray[0]);

    /* task periods */
    Hammerstein_M->Timing.sampleTimes[0] = (0.06);

    /* task offsets */
    Hammerstein_M->Timing.offsetTimes[0] = (0.0);
  }

  rtmSetTPtr(Hammerstein_M, &Hammerstein_M->Timing.tArray[0]);

  {
    int_T *mdlSampleHits = Hammerstein_M->Timing.sampleHitArray;
    mdlSampleHits[0] = 1;
    Hammerstein_M->Timing.sampleHits = (&mdlSampleHits[0]);
  }

  rtmSetTFinal(Hammerstein_M, 9.9599999999999991);
  Hammerstein_M->Timing.stepSize0 = 0.06;

  /* Setup for data logging */
  {
    static RTWLogInfo rt_DataLoggingInfo;
    Hammerstein_M->rtwLogInfo = &rt_DataLoggingInfo;
  }

  /* Setup for data logging */
  {
    rtliSetLogXSignalInfo(Hammerstein_M->rtwLogInfo, (NULL));
    rtliSetLogXSignalPtrs(Hammerstein_M->rtwLogInfo, (NULL));
    rtliSetLogT(Hammerstein_M->rtwLogInfo, "tout");
    rtliSetLogX(Hammerstein_M->rtwLogInfo, "");
    rtliSetLogXFinal(Hammerstein_M->rtwLogInfo, "");
    rtliSetSigLog(Hammerstein_M->rtwLogInfo, "");
    rtliSetLogVarNameModifier(Hammerstein_M->rtwLogInfo, "rt_");
    rtliSetLogFormat(Hammerstein_M->rtwLogInfo, 0);
    rtliSetLogMaxRows(Hammerstein_M->rtwLogInfo, 1000);
    rtliSetLogDecimation(Hammerstein_M->rtwLogInfo, 1);

    /*
     * Set pointers to the data and signal info for each output
     */
    {
      static void * rt_LoggedOutputSignalPtrs[] = {
        &Hammerstein_Y.Out1
      };

      rtliSetLogYSignalPtrs(Hammerstein_M->rtwLogInfo, ((LogSignalPtrsType)
        rt_LoggedOutputSignalPtrs));
    }

    {
      static int_T rt_LoggedOutputWidths[] = {
        1
      };

      static int_T rt_LoggedOutputNumDimensions[] = {
        1
      };

      static int_T rt_LoggedOutputDimensions[] = {
        1
      };

      static boolean_T rt_LoggedOutputIsVarDims[] = {
        0
      };

      static void* rt_LoggedCurrentSignalDimensions[] = {
        (NULL)
      };

      static int_T rt_LoggedCurrentSignalDimensionsSize[] = {
        4
      };

      static BuiltInDTypeId rt_LoggedOutputDataTypeIds[] = {
        SS_DOUBLE
      };

      static int_T rt_LoggedOutputComplexSignals[] = {
        0
      };

      static const char_T *rt_LoggedOutputLabels[] = {
        "" };

      static const char_T *rt_LoggedOutputBlockNames[] = {
        "Hammerstein/Out1" };

      static RTWLogDataTypeConvert rt_RTWLogDataTypeConvert[] = {
        { 0, SS_DOUBLE, SS_DOUBLE, 0, 0, 0, 1.0, 0, 0.0 }
      };

      static RTWLogSignalInfo rt_LoggedOutputSignalInfo[] = {
        {
          1,
          rt_LoggedOutputWidths,
          rt_LoggedOutputNumDimensions,
          rt_LoggedOutputDimensions,
          rt_LoggedOutputIsVarDims,
          rt_LoggedCurrentSignalDimensions,
          rt_LoggedCurrentSignalDimensionsSize,
          rt_LoggedOutputDataTypeIds,
          rt_LoggedOutputComplexSignals,
          (NULL),

          { rt_LoggedOutputLabels },
          (NULL),
          (NULL),
          (NULL),

          { rt_LoggedOutputBlockNames },

          { (NULL) },
          (NULL),
          rt_RTWLogDataTypeConvert
        }
      };

      rtliSetLogYSignalInfo(Hammerstein_M->rtwLogInfo, rt_LoggedOutputSignalInfo);

      /* set currSigDims field */
      rt_LoggedCurrentSignalDimensions[0] = &rt_LoggedOutputWidths[0];
    }

    rtliSetLogY(Hammerstein_M->rtwLogInfo, "yout");
  }

  Hammerstein_M->solverInfoPtr = (&Hammerstein_M->solverInfo);
  Hammerstein_M->Timing.stepSize = (0.06);
  rtsiSetFixedStepSize(&Hammerstein_M->solverInfo, 0.06);
  rtsiSetSolverMode(&Hammerstein_M->solverInfo, SOLVER_MODE_SINGLETASKING);

  /* block I/O */
  (void) memset(((void *) &Hammerstein_B), 0,
                sizeof(BlockIO_Hammerstein));

  /* states (dwork) */
  (void) memset((void *)&Hammerstein_DWork, 0,
                sizeof(D_Work_Hammerstein));

  /* external inputs */
  Hammerstein_U.In1 = 0.0;

  /* external outputs */
  Hammerstein_Y.Out1 = 0.0;

  /* child S-Function registration */
  {
    RTWSfcnInfo *sfcnInfo = &Hammerstein_M->NonInlinedSFcns.sfcnInfo;
    Hammerstein_M->sfcnInfo = (sfcnInfo);
    rtssSetErrorStatusPtr(sfcnInfo, (&rtmGetErrorStatus(Hammerstein_M)));
    rtssSetNumRootSampTimesPtr(sfcnInfo, &Hammerstein_M->Sizes.numSampTimes);
    Hammerstein_M->NonInlinedSFcns.taskTimePtrs[0] = &(rtmGetTPtr(Hammerstein_M)
      [0]);
    rtssSetTPtrPtr(sfcnInfo,Hammerstein_M->NonInlinedSFcns.taskTimePtrs);
    rtssSetTStartPtr(sfcnInfo, &rtmGetTStart(Hammerstein_M));
    rtssSetTFinalPtr(sfcnInfo, &rtmGetTFinal(Hammerstein_M));
    rtssSetTimeOfLastOutputPtr(sfcnInfo, &rtmGetTimeOfLastOutput(Hammerstein_M));
    rtssSetStepSizePtr(sfcnInfo, &Hammerstein_M->Timing.stepSize);
    rtssSetStopRequestedPtr(sfcnInfo, &rtmGetStopRequested(Hammerstein_M));
    rtssSetDerivCacheNeedsResetPtr(sfcnInfo,
      &Hammerstein_M->ModelData.derivCacheNeedsReset);
    rtssSetZCCacheNeedsResetPtr(sfcnInfo,
      &Hammerstein_M->ModelData.zCCacheNeedsReset);
    rtssSetBlkStateChangePtr(sfcnInfo, &Hammerstein_M->ModelData.blkStateChange);
    rtssSetSampleHitsPtr(sfcnInfo, &Hammerstein_M->Timing.sampleHits);
    rtssSetPerTaskSampleHitsPtr(sfcnInfo,
      &Hammerstein_M->Timing.perTaskSampleHits);
    rtssSetSimModePtr(sfcnInfo, &Hammerstein_M->simMode);
    rtssSetSolverInfoPtr(sfcnInfo, &Hammerstein_M->solverInfoPtr);
  }

  Hammerstein_M->Sizes.numSFcns = (2);

  /* register each child */
  {
    (void) memset((void *)&Hammerstein_M->NonInlinedSFcns.childSFunctions[0], 0,
                  2*sizeof(SimStruct));
    Hammerstein_M->childSfunctions =
      (&Hammerstein_M->NonInlinedSFcns.childSFunctionPtrs[0]);
    Hammerstein_M->childSfunctions[0] =
      (&Hammerstein_M->NonInlinedSFcns.childSFunctions[0]);
    Hammerstein_M->childSfunctions[1] =
      (&Hammerstein_M->NonInlinedSFcns.childSFunctions[1]);

    /* Level2 S-Function Block: Hammerstein/<S1>/Pwlinear1 (sfunpwlinear) */
    {
      SimStruct *rts = Hammerstein_M->childSfunctions[0];

      /* timing info */
      time_T *sfcnPeriod = Hammerstein_M->NonInlinedSFcns.Sfcn0.sfcnPeriod;
      time_T *sfcnOffset = Hammerstein_M->NonInlinedSFcns.Sfcn0.sfcnOffset;
      int_T *sfcnTsMap = Hammerstein_M->NonInlinedSFcns.Sfcn0.sfcnTsMap;
      (void) memset((void*)sfcnPeriod, 0,
                    sizeof(time_T)*1);
      (void) memset((void*)sfcnOffset, 0,
                    sizeof(time_T)*1);
      ssSetSampleTimePtr(rts, &sfcnPeriod[0]);
      ssSetOffsetTimePtr(rts, &sfcnOffset[0]);
      ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap);

      /* Set up the mdlInfo pointer */
      {
        ssSetBlkInfo2Ptr(rts, &Hammerstein_M->NonInlinedSFcns.blkInfo2[0]);
      }

      ssSetRTWSfcnInfo(rts, Hammerstein_M->sfcnInfo);

      /* Allocate memory of model methods 2 */
      {
        ssSetModelMethods2(rts, &Hammerstein_M->NonInlinedSFcns.methods2[0]);
      }

      /* Allocate memory of model methods 3 */
      {
        ssSetModelMethods3(rts, &Hammerstein_M->NonInlinedSFcns.methods3[0]);
      }

      /* Allocate memory for states auxilliary information */
      {
        ssSetStatesInfo2(rts, &Hammerstein_M->NonInlinedSFcns.statesInfo2[0]);
      }

      /* inputs */
      {
        _ssSetNumInputPorts(rts, 1);
        ssSetPortInfoForInputs(rts,
          &Hammerstein_M->NonInlinedSFcns.Sfcn0.inputPortInfo[0]);

        /* port 0 */
        {
          ssSetInputPortRequiredContiguous(rts, 0, 1);
          ssSetInputPortSignal(rts, 0, &Hammerstein_B.LinearModel);
          _ssSetInputPortNumDimensions(rts, 0, 1);
          ssSetInputPortWidth(rts, 0, 1);
        }
      }

      /* outputs */
      {
        ssSetPortInfoForOutputs(rts,
          &Hammerstein_M->NonInlinedSFcns.Sfcn0.outputPortInfo[0]);
        _ssSetNumOutputPorts(rts, 1);

        /* port 0 */
        {
          _ssSetOutputPortNumDimensions(rts, 0, 1);
          ssSetOutputPortWidth(rts, 0, 1);
          ssSetOutputPortSignal(rts, 0, ((real_T *) &Hammerstein_Y.Out1));
        }
      }

      /* path info */
      ssSetModelName(rts, "Pwlinear1");
      ssSetPath(rts, "Hammerstein/Hammerstein-Wiener Model1/Pwlinear1");
      ssSetRTModel(rts,Hammerstein_M);
      ssSetParentSS(rts, (NULL));
      ssSetRootSS(rts, rts);
      ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2);

      /* parameters */
      {
        mxArray **sfcnParams = (mxArray **)
          &Hammerstein_M->NonInlinedSFcns.Sfcn0.params;
        ssSetSFcnParamsCount(rts, 7);
        ssSetSFcnParamsPtr(rts, &sfcnParams[0]);
        ssSetSFcnParam(rts, 0, (mxArray*)Hammerstein_P.Pwlinear1_P1_Size);
        ssSetSFcnParam(rts, 1, (mxArray*)Hammerstein_P.Pwlinear1_P2_Size);
        ssSetSFcnParam(rts, 2, (mxArray*)Hammerstein_P.Pwlinear1_P3_Size);
        ssSetSFcnParam(rts, 3, (mxArray*)Hammerstein_P.Pwlinear1_P4_Size);
        ssSetSFcnParam(rts, 4, (mxArray*)Hammerstein_P.Pwlinear1_P5_Size);
        ssSetSFcnParam(rts, 5, (mxArray*)Hammerstein_P.Pwlinear1_P6_Size);
        ssSetSFcnParam(rts, 6, (mxArray*)Hammerstein_P.Pwlinear1_P7_Size);
      }

      /* registration */
      sfunpwlinear(rts);
      sfcnInitializeSizes(rts);
      sfcnInitializeSampleTimes(rts);

      /* adjust sample time */
      ssSetSampleTime(rts, 0, 0.06);
      ssSetOffsetTime(rts, 0, 0.0);
      sfcnTsMap[0] = 0;

      /* set compiled values of dynamic vector attributes */
      ssSetNumNonsampledZCs(rts, 0);

      /* Update connectivity flags for each port */
      _ssSetInputPortConnected(rts, 0, 1);
      _ssSetOutputPortConnected(rts, 0, 1);
      _ssSetOutputPortBeingMerged(rts, 0, 0);

      /* Update the BufferDstPort flags for each input port */
      ssSetInputPortBufferDstPort(rts, 0, -1);
    }

    /* Level2 S-Function Block: Hammerstein/<S1>/Pwlinear (sfunpwlinear) */
    {
      SimStruct *rts = Hammerstein_M->childSfunctions[1];

      /* timing info */
      time_T *sfcnPeriod = Hammerstein_M->NonInlinedSFcns.Sfcn1.sfcnPeriod;
      time_T *sfcnOffset = Hammerstein_M->NonInlinedSFcns.Sfcn1.sfcnOffset;
      int_T *sfcnTsMap = Hammerstein_M->NonInlinedSFcns.Sfcn1.sfcnTsMap;
      (void) memset((void*)sfcnPeriod, 0,
                    sizeof(time_T)*1);
      (void) memset((void*)sfcnOffset, 0,
                    sizeof(time_T)*1);
      ssSetSampleTimePtr(rts, &sfcnPeriod[0]);
      ssSetOffsetTimePtr(rts, &sfcnOffset[0]);
      ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap);

      /* Set up the mdlInfo pointer */
      {
        ssSetBlkInfo2Ptr(rts, &Hammerstein_M->NonInlinedSFcns.blkInfo2[1]);
      }

      ssSetRTWSfcnInfo(rts, Hammerstein_M->sfcnInfo);

      /* Allocate memory of model methods 2 */
      {
        ssSetModelMethods2(rts, &Hammerstein_M->NonInlinedSFcns.methods2[1]);
      }

      /* Allocate memory of model methods 3 */
      {
        ssSetModelMethods3(rts, &Hammerstein_M->NonInlinedSFcns.methods3[1]);
      }

      /* Allocate memory for states auxilliary information */
      {
        ssSetStatesInfo2(rts, &Hammerstein_M->NonInlinedSFcns.statesInfo2[1]);
      }

      /* inputs */
      {
        _ssSetNumInputPorts(rts, 1);
        ssSetPortInfoForInputs(rts,
          &Hammerstein_M->NonInlinedSFcns.Sfcn1.inputPortInfo[0]);

        /* port 0 */
        {
          ssSetInputPortRequiredContiguous(rts, 0, 1);
          ssSetInputPortSignal(rts, 0, &Hammerstein_U.In1);
          _ssSetInputPortNumDimensions(rts, 0, 1);
          ssSetInputPortWidth(rts, 0, 1);
        }
      }

      /* outputs */
      {
        ssSetPortInfoForOutputs(rts,
          &Hammerstein_M->NonInlinedSFcns.Sfcn1.outputPortInfo[0]);
        _ssSetNumOutputPorts(rts, 1);

        /* port 0 */
        {
          _ssSetOutputPortNumDimensions(rts, 0, 1);
          ssSetOutputPortWidth(rts, 0, 1);
          ssSetOutputPortSignal(rts, 0, ((real_T *) &Hammerstein_B.Pwlinear));
        }
      }

      /* path info */
      ssSetModelName(rts, "Pwlinear");
      ssSetPath(rts, "Hammerstein/Hammerstein-Wiener Model1/Pwlinear");
      ssSetRTModel(rts,Hammerstein_M);
      ssSetParentSS(rts, (NULL));
      ssSetRootSS(rts, rts);
      ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2);

      /* parameters */
      {
        mxArray **sfcnParams = (mxArray **)
          &Hammerstein_M->NonInlinedSFcns.Sfcn1.params;
        ssSetSFcnParamsCount(rts, 7);
        ssSetSFcnParamsPtr(rts, &sfcnParams[0]);
        ssSetSFcnParam(rts, 0, (mxArray*)Hammerstein_P.Pwlinear_P1_Size);
        ssSetSFcnParam(rts, 1, (mxArray*)Hammerstein_P.Pwlinear_P2_Size);
        ssSetSFcnParam(rts, 2, (mxArray*)Hammerstein_P.Pwlinear_P3_Size);
        ssSetSFcnParam(rts, 3, (mxArray*)Hammerstein_P.Pwlinear_P4_Size);
        ssSetSFcnParam(rts, 4, (mxArray*)Hammerstein_P.Pwlinear_P5_Size);
        ssSetSFcnParam(rts, 5, (mxArray*)Hammerstein_P.Pwlinear_P6_Size);
        ssSetSFcnParam(rts, 6, (mxArray*)Hammerstein_P.Pwlinear_P7_Size);
      }

      /* registration */
      sfunpwlinear(rts);
      sfcnInitializeSizes(rts);
      sfcnInitializeSampleTimes(rts);

      /* adjust sample time */
      ssSetSampleTime(rts, 0, 0.06);
      ssSetOffsetTime(rts, 0, 0.0);
      sfcnTsMap[0] = 0;

      /* set compiled values of dynamic vector attributes */
      ssSetNumNonsampledZCs(rts, 0);

      /* Update connectivity flags for each port */
      _ssSetInputPortConnected(rts, 0, 1);
      _ssSetOutputPortConnected(rts, 0, 1);
      _ssSetOutputPortBeingMerged(rts, 0, 0);

      /* Update the BufferDstPort flags for each input port */
      ssSetInputPortBufferDstPort(rts, 0, -1);
    }
  }

  /* Matfile logging */
  rt_StartDataLoggingWithStartTime(Hammerstein_M->rtwLogInfo, 0.0, rtmGetTFinal
    (Hammerstein_M), Hammerstein_M->Timing.stepSize0, (&rtmGetErrorStatus
    (Hammerstein_M)));

  /* Level2 S-Function Block: '<S1>/Pwlinear1' (sfunpwlinear) */
  {
    SimStruct *rts = Hammerstein_M->childSfunctions[0];
    sfcnStart(rts);
    if (ssGetErrorStatus(rts) != (NULL))
      return;
  }

  /* Level2 S-Function Block: '<S1>/Pwlinear' (sfunpwlinear) */
  {
    SimStruct *rts = Hammerstein_M->childSfunctions[1];
    sfcnStart(rts);
    if (ssGetErrorStatus(rts) != (NULL))
      return;
  }

  /* InitializeConditions for DiscreteStateSpace: '<S1>/LinearModel' */
  Hammerstein_DWork.LinearModel_DSTATE = Hammerstein_P.LinearModel_X0;

  /* Level2 S-Function Block: '<S1>/Pwlinear1' (sfunpwlinear) */
  {
    SimStruct *rts = Hammerstein_M->childSfunctions[0];
    sfcnInitializeConditions(rts);
    if (ssGetErrorStatus(rts) != (NULL))
      return;
  }

  /* Level2 S-Function Block: '<S1>/Pwlinear' (sfunpwlinear) */
  {
    SimStruct *rts = Hammerstein_M->childSfunctions[1];
    sfcnInitializeConditions(rts);
    if (ssGetErrorStatus(rts) != (NULL))
      return;
  }
}