Esempio n. 1
0
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;
}
Esempio n. 2
0
void baseRateTask(void *arg)
{
  baseRateInfo_t info = *((baseRateInfo_t *)arg);
  MW_setTaskPeriod(info.period, info.signo);
  while ((rtmGetErrorStatus(motorControlTask_M) == (NULL)) &&
         !rtmGetStopRequested(motorControlTask_M) ) {
    /* Wait for the next timer interrupt */
    if (MW_sigWaitWithOverrunDetection(&info.sigMask) == 1) {
      printf("Overrun - rate for base rate task too fast.\n");
      fflush(stdout);
    }

    /* External mode */
    {
      boolean_T rtmStopReq = false;
      rtExtModePauseIfNeeded(motorControlTask_M->extModeInfo, 2, &rtmStopReq);
      if (rtmStopReq) {
        rtmSetStopRequested(motorControlTask_M, true);
      }

      if (rtmGetStopRequested(motorControlTask_M) == true) {
        rtmSetErrorStatus(motorControlTask_M, "Simulation finished");
        break;
      }
    }

    /* External mode */
    {
      boolean_T rtmStopReq = false;
      rtExtModeOneStep(motorControlTask_M->extModeInfo, 2, &rtmStopReq);
      if (rtmStopReq) {
        rtmSetStopRequested(motorControlTask_M, true);
      }
    }

    motorControlTask_output();

    /* Get model outputs here */

    /* External mode */
    rtExtModeUploadCheckTrigger(2);

    {                                  /* Sample time: [0.0s, 0.0s] */
      rtExtModeUpload(0, motorControlTask_M->Timing.t[0]);
    }

    {                                  /* Sample time: [0.02s, 0.0s] */
      rtExtModeUpload(1, ((motorControlTask_M->Timing.clockTick1) * 0.02));
    }

    motorControlTask_update();
    rtExtModeCheckEndTrigger();
  }                                    /* while */

  sem_post(&stopSem);
}
Esempio n. 3
0
void baseRateTask(void *arg)
{
  baseRateInfo_t info = *((baseRateInfo_t *)arg);
  MW_setTaskPeriod(info.period, info.signo);
  while ((rtmGetErrorStatus(Serial_M) == (NULL)) && !rtmGetStopRequested
         (Serial_M) ) {
    /* Wait for the next timer interrupt */
    MW_sigWait(&info.sigMask);

    /* External mode */
    {
      boolean_T rtmStopReq = false;
      rtExtModePauseIfNeeded(Serial_M->extModeInfo, 2, &rtmStopReq);
      if (rtmStopReq) {
        rtmSetStopRequested(Serial_M, true);
      }

      if (rtmGetStopRequested(Serial_M) == true) {
        rtmSetErrorStatus(Serial_M, "Simulation finished");
        break;
      }
    }

    /* External mode */
    {
      boolean_T rtmStopReq = false;
      rtExtModeOneStep(Serial_M->extModeInfo, 2, &rtmStopReq);
      if (rtmStopReq) {
        rtmSetStopRequested(Serial_M, true);
      }
    }

    Serial_output();

    /* Get model outputs here */

    /* External mode */
    rtExtModeUploadCheckTrigger(2);

    {                                  /* Sample time: [0.0s, 0.0s] */
      rtExtModeUpload(0, Serial_M->Timing.t[0]);
    }

    {                                  /* Sample time: [0.05s, 0.0s] */
      rtExtModeUpload(1, ((Serial_M->Timing.clockTick1) * 0.05));
    }

    Serial_update();
    rtExtModeCheckEndTrigger();
  }                                    /* while */

  sem_post(&stopSem);
}
void backgroundTask(int sig)
{
  while (runModel) {
    /* External mode */
    {
      boolean_T rtmStopReq = false;
      rtExtModeOneStep(Model_M->extModeInfo, 1, &rtmStopReq);
      if (rtmStopReq) {
        rtmSetStopRequested(Model_M, true);
      }
    }
  }
}
Esempio n. 5
0
void baseRateTask(void *arg)
{
  baseRateInfo_t info = *((baseRateInfo_t *)arg);
  MW_setTaskPeriod(info.period, info.signo);
  while ((rtmGetErrorStatus(raspberrypi_audioequalizer_M) == (NULL)) &&
         !rtmGetStopRequested(raspberrypi_audioequalizer_M) ) {
    /* Wait for the next timer interrupt */
    MW_sigWait(&info.sigMask);

    /* External mode */
    {
      boolean_T rtmStopReq = FALSE;
      rtExtModePauseIfNeeded(raspberrypi_audioequalizer_M->extModeInfo, 1,
        &rtmStopReq);
      if (rtmStopReq) {
        rtmSetStopRequested(raspberrypi_audioequalizer_M, TRUE);
      }

      if (rtmGetStopRequested(raspberrypi_audioequalizer_M) == TRUE) {
        rtmSetErrorStatus(raspberrypi_audioequalizer_M, "Simulation finished");
        break;
      }
    }

    /* External mode */
    {
      boolean_T rtmStopReq = FALSE;
      rtExtModeOneStep(raspberrypi_audioequalizer_M->extModeInfo, 1, &rtmStopReq);
      if (rtmStopReq) {
        rtmSetStopRequested(raspberrypi_audioequalizer_M, TRUE);
      }
    }

    raspberrypi_audioequalizer_output();

    /* Get model outputs here */

    /* External mode */
    rtExtModeUploadCheckTrigger(1);

    {                                  /* Sample time: [0.1s, 0.0s] */
      rtExtModeUpload(0, raspberrypi_audioequalizer_M->Timing.taskTime0);
    }

    raspberrypi_audioequalizer_update();
    rtExtModeCheckEndTrigger();
  }                                    /* while */

  sem_post(&stopSem);
}
Esempio n. 6
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;
}
Esempio n. 7
0
/* Function: rsimOneStepMT =====================================================
 *
 *      Perform one step of the model.
 *      Errors are set in the SimStruct's ErrorStatus, NULL means no errors.
 */
static void rsimOneStepMT(SimStruct *S)
{
    int_T  i;
    const int_T FIRST_TID = gbl_raccel_tid01eq ? 1 : 0;
    int_T* sampleHit = ssGetSampleHitPtr(S);

    ssSetSimTimeStep(S, MAJOR_TIME_STEP);
    
    /* Clear the flag that blocks set in their major time step methods (output,
       update, etc.) to flag that they have changed their state. If this flag is
       true then we need to run model outputs again at the first minor step
       (i.e., at the same time as the last major step).*/
    
    ssClearBlkStateChange(S);

#ifdef DEBUG_TIMING
    rsimDisplayTimingData(S,
                          sizeof(struct SimStruct_tag),
                          sizeof(struct _ssMdlInfo));
#endif
    if (gblExtModeEnabled) {
        rtExtModeOneStep(ssGetRTWExtModeInfo(S),
                         ssGetNumSampleTimes(S),
                         (boolean_T*)&ssGetStopRequested(S));
        if (ssGetStopRequested(S)) return;
    }
    /* Setup the task times and sample hit flags for the discrete rates */
    rsimUpdateDiscreteTaskTimesAndSampleHits(S);
    if (ssGetErrorStatus(S) != NULL) return;

    ssSetLogOutput(S,TRUE);

    /* Do output, log, update for the base rate */
    MdlOutputs(FIRST_TID);

    if (gblExtModeEnabled) {
        rtExtModeUploadCheckTrigger(ssGetNumSampleTimes(S));
        rtExtModeUpload(FIRST_TID, ssGetTaskTime(S, FIRST_TID));
    }

    if (ssGetLogOutput(S)) {
        (void)rt_UpdateTXYLogVars(ssGetRTWLogInfo(S), ssGetTPtr(S));
        if (ssGetErrorStatus(S) != NULL) return;
    }

    MdlUpdate(FIRST_TID);
    if (ssGetErrorStatus(S) != NULL) return;

    /* Do not log outputs during minor time steps */
    ssSetLogOutput(S, FALSE);
    ssSetTimeOfLastOutput(S,ssGetT(S));

    /* Call the solver push time forward based on the continuous dynamics */
    if (ssGetSampleTime(S,0) == CONTINUOUS_SAMPLE_TIME &&
        !ssGetStopRequested(S) ) {
        rsimUpdateSolverStopTimeForFixedStepMultiTaskingSim(S);
        if (!ssGetStopRequested(S)) rsimAdvanceSolver(S);
    }

    /* Do output and update for the remaining rates */
    ssSetLogOutput(S, TRUE);
    for (i = FIRST_TID+1; i < gbl_raccel_NumST; i++) {
        if ( !sampleHit[i] ) continue;
        MdlOutputs(i);
        rtExtModeUpload(i, ssGetTaskTime(S,i));
        MdlUpdate(i);
    }
    if (ssGetErrorStatus(S) != NULL) return;
    ssSetLogOutput(S, FALSE);

    if (gblExtModeEnabled) {
        rtExtModeCheckEndTrigger();
    }

    /* Update the timing engine and determine the solver stop time */
    rsimUpdateTimingEngineAndSolverStopTime(S);
    if (ssGetErrorStatus(S) != NULL) return;

} /* rsimOneStepMT */
Esempio n. 8
0
/* Function: rsimOutputLogUpdate ===============================================
 *
 */
static void rsimOutputLogUpdate(SimStruct* S)
{
    double currTime  = ssGetT(S);
    bool   logOutput = !ssGetOutputTimesOnly(S);

#ifdef DEBUG_TIMING
    rsimDisplayTimingData(S,
                          sizeof(struct SimStruct_tag),
                          sizeof(struct _ssMdlInfo));
#endif

    if (gblExtModeEnabled) {
        rtExtModeOneStep(ssGetRTWExtModeInfo(S),
                         ssGetNumSampleTimes(S),
                         (boolean_T*)&ssGetStopRequested(S));
        if (ssGetStopRequested(S)) return;
    }

    /* Setup the task times and sample hit flags for the discrete rates */
    rsimUpdateDiscreteTaskTimesAndSampleHits(S);
    if (ssGetErrorStatus(S) != NULL) return;

    /*
     * See if we are at an outputTime, and if so set logOutput to true and
     * increment the next output time index to point to the next entry in
     * the outputTimes array.
     */
    if ( ssGetNumOutputTimes(S) > 0 &&
         ssGetOutputTimesIndex(S) < ssGetNumOutputTimes(S) ) {
        time_T nextOutputTime = ssGetNextOutputTime(S);
        /* utAssert(currTime <= nextOutputTime); */
        if (currTime == nextOutputTime) {
            uint_T idx = ssGetOutputTimesIndex(S);
            ssSetOutputTimesIndex(S, idx+1);
            logOutput = 1; /* this is one of the specified output times */
        }
    }
    ssSetLogOutput(S, logOutput);

    MdlOutputs(0);

    if (gblExtModeEnabled) {
        rtExtModeSingleTaskUpload(S);
    }

    if (ssGetLogOutput(S)) {
        (void)rt_UpdateTXYLogVars(ssGetRTWLogInfo(S), ssGetTPtr(S));
        if (ssGetErrorStatus(S) != NULL) return;
    }

    MdlUpdate(0);
    if (ssGetErrorStatus(S) != NULL) return;

    ssSetLogOutput(S, FALSE);
    ssSetTimeOfLastOutput(S, currTime);

    /* Update the timing engine and determine the solver stop time */
    rsimUpdateTimingEngineAndSolverStopTime(S);
    if (ssGetErrorStatus(S) != NULL) return;

    if (gblExtModeEnabled) {
        rtExtModeCheckEndTrigger();
    }
    return;

} /* rsimOutputLogUpdate */
Esempio n. 9
0
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;
}
Esempio n. 10
0
/* Function: rtOneStep ========================================================
 *
 * Abstract:
 *      Perform one step of the model. This function is modeled such that
 *      it could be called from an interrupt service routine (ISR) with minor
 *      modifications.
 *
 *      This routine is modeled for use in a multitasking environment and
 *	therefore needs to be fully re-entrant when it is called from an
 *	interrupt service routine.
 *
 * Note:
 *      Error checking is provided which will only be used if this routine
 *      is attached to an interrupt.
 *
 */
static void rt_OneStep(RT_MODEL *S)
{
    int_T  i;
    real_T tnext;
    int_T  *sampleHit = rtmGetSampleHitPtr(S);

    /***********************************************
     * Check and see if base step time is too fast *
     ***********************************************/
    if (GBLbuf.isrOverrun++) {
        GBLbuf.stopExecutionFlag = 1;
        return;
    }

    /***********************************************
     * Check and see if error status has been set  *
     ***********************************************/
    if (rtmGetErrorStatus(S) != NULL) {
        GBLbuf.stopExecutionFlag = 1;
        return;
    }
    /* enable interrupts here */

    /*
     * In a multi-tasking environment, this would be removed from the base rate
     * and called as a "background" task.
     */
    rtExtModeOneStep(rtmGetRTWExtModeInfo(S),
                     rtmGetNumSampleTimes(S),
                     (boolean_T *)&rtmGetStopRequested(S));

    /***********************************************
     * Update discrete events                      *
     ***********************************************/
    tnext = rt_SimUpdateDiscreteEvents(rtmGetNumSampleTimes(S),
                                       rtmGetTimingData(S),
                                       rtmGetSampleHitPtr(S),
                                       rtmGetPerTaskSampleHitsPtr(S));
    rtsiSetSolverStopTime(rtmGetRTWSolverInfo(S),tnext);
    for (i=FIRST_TID+1; i < NUMST; i++) {
        if (sampleHit[i] && GBLbuf.eventFlags[i]++) {
            GBLbuf.isrOverrun--; 
            GBLbuf.overrunFlags[i]++;    /* Are we sampling too fast for */
            GBLbuf.stopExecutionFlag=1;  /*   sample time "i"?           */
            return;
        }
    }
    /*******************************************
     * Step the model for the base sample time *
     *******************************************/
    MdlOutputs(FIRST_TID);

    rtExtModeUploadCheckTrigger(rtmGetNumSampleTimes(S));
    rtExtModeUpload(FIRST_TID,rtmGetTaskTime(S, FIRST_TID));

   /* GBLbuf.errmsg = rt_UpdateTXYLogVars(rtmGetRTWLogInfo(S),
                                        rtmGetTPtr(S));
    if (GBLbuf.errmsg != NULL) {
        GBLbuf.stopExecutionFlag = 1;
        return;
    }*/

   /* rt_UpdateSigLogVars(rtmGetRTWLogInfo(S), rtmGetTPtr(S));*/

    MdlUpdate(FIRST_TID);

    if (rtmGetSampleTime(S,0) == CONTINUOUS_SAMPLE_TIME) {
        rt_UpdateContinuousStates(S);
    }
     else {
        rt_SimUpdateDiscreteTaskTime(rtmGetTPtr(S), 
                                     rtmGetTimingData(S), 0);
    }

#if FIRST_TID == 1
    rt_SimUpdateDiscreteTaskTime(rtmGetTPtr(S), 
                                 rtmGetTimingData(S),1);
#endif


    /************************************************************************
     * Model step complete for base sample time, now it is okay to          *
     * re-interrupt this ISR.                                               *
     ************************************************************************/

    GBLbuf.isrOverrun--;


    /*********************************************
     * Step the model for any other sample times *
     *********************************************/
    for (i=FIRST_TID+1; i<NUMST; i++) {
        /* If task "i" is running, don't run any lower priority task */
        if (GBLbuf.overrunFlags[i]) return;

        if (GBLbuf.eventFlags[i]) {
            GBLbuf.overrunFlags[i]++;

            MdlOutputs(i);
 
            rtExtModeUpload(i, rtmGetTaskTime(S,i));

            MdlUpdate(i);

            rt_SimUpdateDiscreteTaskTime(rtmGetTPtr(S), 
                                         rtmGetTimingData(S),i);

            /* Indicate task complete for sample time "i" */
            GBLbuf.overrunFlags[i]--;
            GBLbuf.eventFlags[i]--;
        }
    }

    rtExtModeCheckEndTrigger();

} /* end rtOneStep */
Esempio n. 11
0
/* Function: rtOneStep ========================================================
 *
 * Abstract:
 *      Perform one step of the model. This function is modeled such that
 *      it could be called from an interrupt service routine (ISR) with minor
 *      modifications.
 */
static void rt_OneStep(RT_MODEL *S)
{
    real_T tnext;

    /***********************************************
     * Check and see if base step time is too fast *
     ***********************************************/
    if (GBLbuf.isrOverrun++) {
        GBLbuf.stopExecutionFlag = 1;
        return;
    }

    /***********************************************
     * Check and see if error status has been set  *
     ***********************************************/
    if (rtmGetErrorStatus(S) != NULL) {
        GBLbuf.stopExecutionFlag = 1;
        return;
    }

    /* enable interrupts here */

    /*
     * In a multi-tasking environment, this would be removed from the base rate
     * and called as a "background" task.
     */
    rtExtModeOneStep(rtmGetRTWExtModeInfo(S),
                     rtmGetNumSampleTimes(S),
                     (boolean_T *)&rtmGetStopRequested(S));

    tnext = rt_SimGetNextSampleHit();
    rtsiSetSolverStopTime(rtmGetRTWSolverInfo(S),tnext);

    MdlOutputs(0);

    rtExtModeSingleTaskUpload(S);

    /*GBLbuf.errmsg = rt_UpdateTXYLogVars(rtmGetRTWLogInfo(S),
                                        rtmGetTPtr(S));
    if (GBLbuf.errmsg != NULL) {
        GBLbuf.stopExecutionFlag = 1;
        return;
    }*//*removed logging*/

    /*rt_UpdateSigLogVars(rtmGetRTWLogInfo(S), rtmGetTPtr(S));*//*removed logging*/

    MdlUpdate(0);
    rt_SimUpdateDiscreteTaskSampleHits(rtmGetNumSampleTimes(S),
                                       rtmGetTimingData(S),
                                       rtmGetSampleHitPtr(S),
                                       rtmGetTPtr(S));

    if (rtmGetSampleTime(S,0) == CONTINUOUS_SAMPLE_TIME) {
        rt_UpdateContinuousStates(S);
    }

    GBLbuf.isrOverrun--;

    rtExtModeCheckEndTrigger();

} /* end rtOneStep */