/* Model terminate function */ void Crane_terminate(void) { /* S-Function Block: <S10>/Block#1 */ { if (rt_mech_visited_Crane_63fd34a2 == 1) { _rtMech_PWORK *mechWork = (_rtMech_PWORK *) Crane_DWork.Block1_PWORK; if (mechWork->mechanism->destroyEngine != NULL) { (mechWork->mechanism->destroyEngine)(mechWork->mechanism); } } if ((--rt_mech_visited_Crane_63fd34a2) == 0 ) { rt_mech_visited_loc_Crane_63fd34a2 = 0; } } /* S-Function Block: Crane/Falcon (falcon_block) */ { t_error result; result = falcon_close(Crane_DWork.Falcon_Falcon); if (result < 0) { msg_get_error_messageA(NULL, result, _rt_error_message, sizeof (_rt_error_message)); rtmSetErrorStatus(Crane_M, _rt_error_message); return; } } /* External mode */ rtExtModeShutdown(2); }
/* Model terminate function */ void omni_interface_terminate(void) { /* S-Function Block: omni_interface/HIL Initialize (hil_initialize_block) */ { t_boolean is_switching; t_int result; hil_task_stop_all(omni_interface_DWork.HILInitialize_Card); hil_task_delete_all(omni_interface_DWork.HILInitialize_Card); is_switching = false; if ((omni_interface_P.HILInitialize_POTerminate && !is_switching) || (omni_interface_P.HILInitialize_POExit && is_switching)) { omni_interface_DWork.HILInitialize_POValues[0] = omni_interface_P.HILInitialize_POFinal; omni_interface_DWork.HILInitialize_POValues[1] = omni_interface_P.HILInitialize_POFinal; omni_interface_DWork.HILInitialize_POValues[2] = omni_interface_P.HILInitialize_POFinal; result = hil_write_pwm(omni_interface_DWork.HILInitialize_Card, &omni_interface_P.HILInitialize_POChannels[0], 3U, &omni_interface_DWork.HILInitialize_POValues[0]); if (result < 0) { msg_get_error_messageA(NULL, result, _rt_error_message, sizeof (_rt_error_message)); rtmSetErrorStatus(omni_interface_M, _rt_error_message); } } hil_close(omni_interface_DWork.HILInitialize_Card); omni_interface_DWork.HILInitialize_Card = NULL; } /* S-Function Block: omni_interface/Stream Answer (stream_answer_block) */ { if (omni_interface_DWork.StreamAnswer_Client != NULL) { stream_close(omni_interface_DWork.StreamAnswer_Client); omni_interface_DWork.StreamAnswer_Client = NULL; } if (omni_interface_DWork.StreamAnswer_Listener != NULL) { stream_close(omni_interface_DWork.StreamAnswer_Listener); omni_interface_DWork.StreamAnswer_Listener = NULL; } } /* S-Function Block: omni_interface/Stream Answer1 (stream_answer_block) */ { if (omni_interface_DWork.StreamAnswer1_Client != NULL) { stream_close(omni_interface_DWork.StreamAnswer1_Client); omni_interface_DWork.StreamAnswer1_Client = NULL; } if (omni_interface_DWork.StreamAnswer1_Listener != NULL) { stream_close(omni_interface_DWork.StreamAnswer1_Listener); omni_interface_DWork.StreamAnswer1_Listener = NULL; } } /* External mode */ rtExtModeShutdown(1); }
int main(void) { volatile boolean_T runModel = 1; float modelBaseRate = 2.0; float systemClock = 0; init(); MW_Arduino_Init(); rtmSetErrorStatus(test_motor_M, 0); /* initialize external mode */ rtParseArgsForExtMode(0, NULL); test_motor_initialize(); sei(); /* External mode */ rtSetTFinalForExtMode(&rtmGetTFinal(test_motor_M)); rtExtModeCheckInit(1); { boolean_T rtmStopReq = false; rtExtModeWaitForStartPkt(test_motor_M->extModeInfo, 1, &rtmStopReq); if (rtmStopReq) { rtmSetStopRequested(test_motor_M, true); } } rtERTExtModeStartMsg(); cli(); configureArduinoAVRTimer(); runModel = (rtmGetErrorStatus(test_motor_M) == (NULL)) && !rtmGetStopRequested (test_motor_M); sei(); sei(); while (runModel) { /* External mode */ { boolean_T rtmStopReq = false; rtExtModeOneStep(test_motor_M->extModeInfo, 1, &rtmStopReq); if (rtmStopReq) { rtmSetStopRequested(test_motor_M, true); } } runModel = (rtmGetErrorStatus(test_motor_M) == (NULL)) && !rtmGetStopRequested (test_motor_M); } rtExtModeShutdown(1); /* Disable rt_OneStep() here */ /* Terminate model */ test_motor_terminate(); cli(); return 0; }
//////////////////////////////////////////////////////////////////////////////// // Destructor BonebrakerController::~BonebrakerController() { event::Events::DisconnectWorldUpdateBegin(updateConnection); //Close matlab model rtExtModeShutdown(1); quadrotor_controller_terminate(); node_handle_->shutdown(); delete node_handle_; }
/* Model terminate function */ void client_terminate(void) { /* S-Function Block: client/Stream Connect (stream_connect_block) */ { if (client_DWork.StreamConnect_Stream != NULL) { stream_close(client_DWork.StreamConnect_Stream); client_DWork.StreamConnect_Stream = NULL; } } /* External mode */ rtExtModeShutdown(2); }
/* Model terminate function */ void arbeitspunkt_terminate(void) { /* S-Function Block: <Root>/Analog Output */ { { ANALOGIOPARM parm; parm.mode = (RANGEMODE) arbeitspunkt_P.AnalogOutput_RangeMode; parm.rangeidx = arbeitspunkt_P.AnalogOutput_VoltRange; RTBIO_DriverIO(0, ANALOGOUTPUT, IOWRITE, 1, &arbeitspunkt_P.AnalogOutput_Channels, &arbeitspunkt_P.AnalogOutput_FinalValue, &parm); } } /* External mode */ rtExtModeShutdown(2); }
/* Model terminate function */ void Maglev_PD_terminate(void) { /* S-Function Block: <S4>/Analog Output */ { { ANALOGIOPARM parm; parm.mode = (RANGEMODE) Maglev_PD_P.AnalogOutput_RangeMode; parm.rangeidx = Maglev_PD_P.AnalogOutput_VoltRange; RTBIO_DriverIO(0, ANALOGOUTPUT, IOWRITE, 1, &Maglev_PD_P.AnalogOutput_Channels, &Maglev_PD_P.AnalogOutput_FinalValue, &parm); } } /* External mode */ rtExtModeShutdown(3); }
/* Model terminate function */ void Server_terminate(void) { /* S-Function Block: Server/Stream Answer (stream_answer_block) */ { if (Server_DWork.StreamAnswer_Client != NULL) { stream_close(Server_DWork.StreamAnswer_Client); Server_DWork.StreamAnswer_Client = NULL; } if (Server_DWork.StreamAnswer_Listener != NULL) { stream_close(Server_DWork.StreamAnswer_Listener); Server_DWork.StreamAnswer_Listener = NULL; } } /* External mode */ rtExtModeShutdown(2); }
void BonebrakerController::MatlabUpdate() {//Matlab Autogenerated code static boolean_T OverrunFlag = 0; if (OverrunFlag) { rtmSetErrorStatus(quadrotor_controller_M, "Overrun"); return; } OverrunFlag = TRUE; quadrotor_controller_step(); OverrunFlag = FALSE; if((rtmGetErrorStatus(quadrotor_controller_M) == (NULL)) && !rtmGetStopRequested(quadrotor_controller_M)) { rtExtModeCheckEndTrigger(); }else { rtExtModeShutdown(1); } }
void terminateTask(void *arg) { terminatingmodel = 1; printf("**terminating the model**\n"); fflush(stdout); { int ret; runModel = 0; /* Wait for background task to complete */ ret = mw_osThreadJoin(backgroundThread, (void *)&threadJoinStatus); CHECK_STATUS(ret, 0, "mw_osThreadJoin"); } rtExtModeShutdown(1); /* Disable rt_OneStep() here */ /* Terminate model */ Model_terminate(); mw_osSemaphoreRelease(&stopSem); }
int main(int argc, char **argv) { int ret; baseRateInfo_t info; pthread_attr_t attr; pthread_t baseRateThread; size_t stackSize; unsigned long cpuMask = 0x1; unsigned int len = sizeof(cpuMask); printf("**starting the model**\n"); fflush(stdout); rtmSetErrorStatus(raspberrypi_audioequalizer_M, 0); rtExtModeParseArgs(argc, (const char_T **)argv, NULL); /* All threads created by this process must run on a single CPU */ ret = sched_setaffinity(0, len, (cpu_set_t *) &cpuMask); CHECK_STATUS(ret, "sched_setaffinity"); /* Initialize semaphore used for thread synchronization */ ret = sem_init(&stopSem, 0, 0); CHECK_STATUS(ret, "sem_init:stopSem"); /* Create threads executing the Simulink model */ pthread_attr_init(&attr); ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); CHECK_STATUS(ret, "pthread_attr_setinheritsched"); ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); CHECK_STATUS(ret, "pthread_attr_setdetachstate"); /* PTHREAD_STACK_MIN is the minimum stack size required to start a thread */ stackSize = 64000 + PTHREAD_STACK_MIN; ret = pthread_attr_setstacksize(&attr, stackSize); CHECK_STATUS(ret, "pthread_attr_setstacksize"); /* Block signal used for timer notification */ info.period = 0.1; info.signo = SIGRTMIN; sigemptyset(&info.sigMask); MW_blockSignal(info.signo, &info.sigMask); signal(SIGTERM, MW_exitHandler); /* kill */ signal(SIGHUP, MW_exitHandler); /* kill -HUP */ signal(SIGINT, MW_exitHandler); /* Interrupt from keyboard */ signal(SIGQUIT, MW_exitHandler); /* Quit from keyboard */ raspberrypi_audioequalizer_initialize(); /* External mode */ rtSetTFinalForExtMode(&rtmGetTFinal(raspberrypi_audioequalizer_M)); rtExtModeCheckInit(1); { boolean_T rtmStopReq = FALSE; rtExtModeWaitForStartPkt(raspberrypi_audioequalizer_M->extModeInfo, 1, &rtmStopReq); if (rtmStopReq) { rtmSetStopRequested(raspberrypi_audioequalizer_M, TRUE); } } rtERTExtModeStartMsg(); /* Create base rate task */ ret = pthread_create(&baseRateThread, &attr, (void *) baseRateTask, (void *) &info); CHECK_STATUS(ret, "pthread_create"); pthread_attr_destroy(&attr); /* Wait for a stopping condition. */ MW_sem_wait(&stopSem); /* Received stop signal */ printf("**stopping the model**\n"); if (rtmGetErrorStatus(raspberrypi_audioequalizer_M) != NULL) { printf("\n**%s**\n", rtmGetErrorStatus(raspberrypi_audioequalizer_M)); } /* External mode shutdown */ rtExtModeShutdown(1); /* Disable rt_OneStep() here */ /* Terminate model */ raspberrypi_audioequalizer_terminate(); return 0; }
int_T main(void) { init(); #ifdef _RTT_USE_SERIAL1_ Serial_begin(1, 9600); #endif #ifdef _RTT_USE_SERIAL2_ Serial_begin(2, 9600); #endif #ifdef _RTT_USE_SERIAL3_ Serial_begin(3, 9600); #endif /* initialize external mode */ rtParseArgsForExtMode(0, NULL); velo_id_gain_initialize(); /* External mode */ rtSetTFinalForExtMode(&rtmGetTFinal(velo_id_gain_M)); rtExtModeCheckInit(2); { boolean_T rtmStopReq = false; rtExtModeWaitForStartPkt(velo_id_gain_M->extModeInfo, 2, &rtmStopReq); if (rtmStopReq) { rtmSetStopRequested(velo_id_gain_M, true); } } rtERTExtModeStartMsg(); arduino_Timer_Setup(); /* The main step loop */ while ((rtmGetErrorStatus(velo_id_gain_M) == (NULL)) && !rtmGetStopRequested (velo_id_gain_M)) { /* External mode */ { boolean_T rtmStopReq = false; rtExtModeOneStep(velo_id_gain_M->extModeInfo, 2, &rtmStopReq); if (rtmStopReq) { rtmSetStopRequested(velo_id_gain_M, true); } } rtExtModeCheckEndTrigger(); } rtExtModeShutdown(2); delay(1000); velo_id_gain_terminate(); /* Disable Interrupts */ cli(); return 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 */
int main(void) { volatile boolean_T runModel = 1; float modelBaseRate = 0.01; float systemClock = 168; #ifndef USE_RTX __disable_irq(); #endif ; stm32f4xx_init_board(); SystemCoreClockUpdate(); bootloaderInit(); rtmSetErrorStatus(BeschleunigungsAuswertung_M, 0); /* initialize external mode */ rtParseArgsForExtMode(0, NULL); BeschleunigungsAuswertung_initialize(); __enable_irq(); /* External mode */ rtSetTFinalForExtMode(&rtmGetTFinal(BeschleunigungsAuswertung_M)); rtExtModeCheckInit(1); { boolean_T rtmStopReq = false; rtExtModeWaitForStartPkt(BeschleunigungsAuswertung_M->extModeInfo, 1, &rtmStopReq); if (rtmStopReq) { rtmSetStopRequested(BeschleunigungsAuswertung_M, true); } } rtERTExtModeStartMsg(); __disable_irq(); ARMCM_SysTick_Config(modelBaseRate); runModel = (rtmGetErrorStatus(BeschleunigungsAuswertung_M) == (NULL)) && !rtmGetStopRequested(BeschleunigungsAuswertung_M); __enable_irq(); __enable_irq(); while (runModel) { /* External mode */ { boolean_T rtmStopReq = false; rtExtModeOneStep(BeschleunigungsAuswertung_M->extModeInfo, 1, &rtmStopReq); if (rtmStopReq) { rtmSetStopRequested(BeschleunigungsAuswertung_M, true); } } runModel = (rtmGetErrorStatus(BeschleunigungsAuswertung_M) == (NULL)) && !rtmGetStopRequested(BeschleunigungsAuswertung_M); } rtExtModeShutdown(1); #ifndef USE_RTX (void)systemClock; #endif ; /* Disable rt_OneStep() here */ /* Terminate model */ BeschleunigungsAuswertung_terminate(); __disable_irq(); return 0; }
/* Function: main ============================================================= * * Abstract: * Execute model on a generic target such as a workstation. */ int_T main(int_T argc, const char_T *argv[]) { RT_MODEL *S; const char *status; real_T finaltime = -2.0; int_T oldStyle_argc; const char_T *oldStyle_argv[5]; /****************************** * MathError Handling for BC++ * ******************************/ #ifdef BORLAND signal(SIGFPE, (fptr)divideByZero); #endif /******************* * Parse arguments * *******************/ if ((argc > 1) && (argv[1][0] != '-')) { /* old style */ if ( argc > 3 ) { displayUsage(); exit(EXIT_FAILURE); } oldStyle_argc = 1; oldStyle_argv[0] = argv[0]; if (argc >= 2) { oldStyle_argc = 3; oldStyle_argv[1] = "-tf"; oldStyle_argv[2] = argv[1]; } if (argc == 3) { oldStyle_argc = 5; oldStyle_argv[3] = "-port"; oldStyle_argv[4] = argv[2]; } argc = oldStyle_argc; argv = oldStyle_argv; } { /* new style: */ double tmpDouble; char_T tmpStr2[200]; int_T count = 1; int_T parseError = FALSE; /* * Parse the standard RTW parameters. Let all unrecognized parameters * pass through to external mode for parsing. NULL out all args handled * so that the external mode parsing can ignore them. */ while(count < argc) { const char_T *option = argv[count++]; /* final time */ if ((strcmp(option, "-tf") == 0) && (count != argc)) { const char_T *tfStr = argv[count++]; sscanf(tfStr, "%200s", tmpStr2); if (strcmp(tmpStr2, "inf") == 0) { tmpDouble = RUN_FOREVER; } else { char_T tmpstr[2]; if ( (sscanf(tmpStr2,"%lf%1s", &tmpDouble, tmpstr) != 1) || (tmpDouble < 0.0) ) { (void)printf("finaltime must be a positive, real value or inf\n"); parseError = TRUE; break; } } finaltime = (real_T) tmpDouble; argv[count-2] = NULL; argv[count-1] = NULL; } } if (parseError) { (void)printf("\nUsage: %s -option1 val1 -option2 val2 -option3 " "...\n\n", QUOTE(MODEL)); (void)printf("\t-tf 20 - sets final time to 20 seconds\n"); exit(EXIT_FAILURE); } rtExtModeParseArgs(argc, argv, NULL); /* * Check for unprocessed ("unhandled") args. */ { int i; for (i=1; i<argc; i++) { if (argv[i] != NULL) { printf("Unexpected command line argument: %s\n",argv[i]); exit(EXIT_FAILURE); } } } } /**************************** * Initialize global memory * ****************************/ (void)memset(&GBLbuf, 0, sizeof(GBLbuf)); /************************ * Initialize the model * ************************/ rt_InitInfAndNaN(sizeof(real_T)); S = MODEL(); if (rtmGetErrorStatus(S) != NULL) { (void)fprintf(stderr,"Error during model registration: %s\n", rtmGetErrorStatus(S)); exit(EXIT_FAILURE); } if (finaltime >= 0.0 || finaltime == RUN_FOREVER) rtmSetTFinal(S,finaltime); MdlInitializeSizes(); MdlInitializeSampleTimes(); status = rt_SimInitTimingEngine(rtmGetNumSampleTimes(S), rtmGetStepSize(S), rtmGetSampleTimePtr(S), rtmGetOffsetTimePtr(S), rtmGetSampleHitPtr(S), rtmGetSampleTimeTaskIDPtr(S), rtmGetTStart(S), &rtmGetSimTimeStep(S), &rtmGetTimingData(S)); if (status != NULL) { (void)fprintf(stderr, "Failed to initialize sample time engine: %s\n", status); exit(EXIT_FAILURE); } rt_CreateIntegrationData(S); /* #ifdef UseMMIDataLogging rt_FillStateSigInfoFromMMI(rtmGetRTWLogInfo(S),&rtmGetErrorStatus(S)); rt_FillSigLogInfoFromMMI(rtmGetRTWLogInfo(S),&rtmGetErrorStatus(S)); #endif*/ /* GBLbuf.errmsg = rt_StartDataLogging(rtmGetRTWLogInfo(S), rtmGetTFinal(S), rtmGetStepSize(S), &rtmGetErrorStatus(S)); if (GBLbuf.errmsg != NULL) { (void)fprintf(stderr,"Error starting data logging: %s\n",GBLbuf.errmsg); return(EXIT_FAILURE); }*//*removed datalogging*/ rtExtModeCheckInit(rtmGetNumSampleTimes(S)); rtExtModeWaitForStartPkt(rtmGetRTWExtModeInfo(S), rtmGetNumSampleTimes(S), (boolean_T *)&rtmGetStopRequested(S)); (void)printf("\n** starting the model **\n"); MdlStart(); if (rtmGetErrorStatus(S) != NULL) { GBLbuf.stopExecutionFlag = 1; } /************************************************************************* * Execute the model. You may attach rtOneStep to an ISR, if so replace * * the call to rtOneStep (below) with a call to a background task * * application. * *************************************************************************/ if (rtmGetTFinal(S) == RUN_FOREVER) { printf ("\n**May run forever. Model stop time set to infinity.**\n"); } stepTime=(FPS*CLOCKS_PER_SEC)/1000; nextStart = clock(); nextStart+=stepTime; while (!GBLbuf.stopExecutionFlag && (rtmGetTFinal(S) == RUN_FOREVER || rtmGetTFinal(S)-rtmGetT(S) > rtmGetT(S)*DBL_EPSILON)) { rtExtModePauseIfNeeded(rtmGetRTWExtModeInfo(S), rtmGetNumSampleTimes(S), (boolean_T *)&rtmGetStopRequested(S)); if( clock() >= nextStart) { if( stepTime > 0) { printf("***Execution slower than requested rate: Actual speed =%d ms***\n",(1000*(stepTime+clock()-nextStart))/CLOCKS_PER_SEC); nextStart=clock(); } } while (clock() < nextStart) {} nextStart+=stepTime; if (rtmGetStopRequested(S)) break; rt_OneStep(S); } if (!GBLbuf.stopExecutionFlag && !rtmGetStopRequested(S)) { /* Execute model last time step */ rt_OneStep(S); } /******************** * Cleanup and exit * ********************/ /* #ifdef UseMMIDataLogging rt_CleanUpForStateLogWithMMI(rtmGetRTWLogInfo(S)); rt_CleanUpForSigLogWithMMI(rtmGetRTWLogInfo(S)); #endif rt_StopDataLogging(MATFILE,rtmGetRTWLogInfo(S));*/ rtExtModeShutdown(rtmGetNumSampleTimes(S)); if (GBLbuf.errmsg) { (void)fprintf(stderr,"%s\n",GBLbuf.errmsg); exit(EXIT_FAILURE); } if (rtmGetErrorStatus(S) != NULL) { (void)fprintf(stderr,"ErrorStatus set: \"%s\"\n", rtmGetErrorStatus(S)); exit(EXIT_FAILURE); } if (GBLbuf.isrOverrun) { (void)fprintf(stderr, "%s: ISR overrun - base sampling rate is too fast\n", QUOTE(MODEL)); exit(EXIT_FAILURE); } #ifdef MULTITASKING else { int_T i; for (i=1; i<NUMST; i++) { if (GBLbuf.overrunFlags[i]) { (void)fprintf(stderr, "%s ISR overrun - sampling rate is too fast for " "sample time index %d\n", QUOTE(MODEL), i); exit(EXIT_FAILURE); } } } #endif MdlTerminate(); return(EXIT_SUCCESS); } /* end main */