Beispiel #1
0
void StayInside(void)
{
  static int nb_recule = 0;
  // Motor Control
  // -------------

  GetPhotoSensor(DOWNWARD, 0);
  str_l2[0] = DownwardPhotoSensor & 1? 'x' : ' ';
  str_l2[3] = DownwardPhotoSensor & 2? 'x' : ' ';
  str_l2[7] = DownwardPhotoSensor & 4? 'x' : ' ';

  switch (DownwardPhotoSensor) {
  case PHOTO_CENTER_LEFT:
    if (timer_complete(TIMER_RECULE)) {
      AVANCE_RIGHT(0, -val_buttons);
      timer_start(TIMER_TURN90, TIMER_TURN90_DELAY);
      nb_recule = 0;
    }
    break;

  case PHOTO_CENTER_RIGHT:
    if (timer_complete(TIMER_RECULE)) {
      AVANCE_LEFT(0, -val_buttons);
      timer_start(TIMER_TURN90, TIMER_TURN90_DELAY);
      nb_recule = 0;
    }
    break;

  case PHOTO_LEFT_CENTER_RIGHT:
    if (timer_complete(TIMER_TURN90)) {
      if (nb_recule >= 5) {
        //Anti deadlock
        AVANCE_LEFT(0, -val_buttons);
        timer_start(TIMER_TURN90, TIMER_TURN90_DELAY);
        nb_recule = 0;
      } else {
        RECULE(MAX_SPEED_SUMO);
        timer_start(TIMER_RECULE, TIMER_RECULE_DELAY);
        nb_recule++;
      }
    }
    break;
  } //end switch
  
  if (timer_complete(TIMER_TURN90) &&
      timer_complete(TIMER_RECULE)) {
    AVANCE(MAX_SPEED_SUMO);
  }
}
 virtual void TearDown() {
   SC_closePort(fdin);
   Shakespeare::log(Shakespeare::NOTICE, PROCESS, ">>>>>>>>>>>>>>>>>>>>>> END TEST <<<<<<<<<<<<<<<<<<<<<<");
   // start timer from call
   timer_t wait_timer = timer_get();
   timer_start(&wait_timer,2,0);
   while (!timer_complete(&wait_timer)) { /* pause */ }
 }
Beispiel #3
0
void DoCarre(void)
{
  static int state_carre = STATE_AVANCE;

  switch (state_carre) {
  case STATE_AVANCE:
    if (timer_complete(TIMER_RECULE)) {
      timer_start(TIMER_TURN90, TIMER_TURN90_DELAY);
      AVANCE_RIGHT(0, -val_buttons);
      state_carre = STATE_TURN;
    }
    break;
  case STATE_TURN:
    if (timer_complete(TIMER_TURN90)) {
      timer_start(TIMER_RECULE, TIMER_RECULE_DELAY);
      AVANCE(MAX_SPEED_SUMO);
      state_carre = STATE_AVANCE;
    }
    break;
  }
}
int main(int argc, const char *argv[])
{
   if(argc < 4){
      fprintf(stderr, "Usage: %s <frequency (ns)> <duration (ms)> <script> [<args>...]\n", argv[0]);
      return -1;
   }

   long frequency = atol(argv[1]);
   if (validateFrequency(frequency) > 0) {
     Shakespeare::log(Shakespeare::ERROR,processName,"Invalid frequency, must be greater than zero");
   } // TODO - more validation
   
   long duration = atol(argv[2]);
   if (validateDuration (duration) > 0) {
     Shakespeare::log(Shakespeare::ERROR,processName,"Invalid duration, must be greater than zero");
   } // TODO - more validation

   // Set up arguments for exec: the path is always the 3th argument
   const char * path = argv[3];

   // All of the rest of the arguments are arguments for the job. The path of
   // the job should also be passed to the job as argument zero.
   // TODO replace with new
   char ** args = (char **) malloc(sizeof(char*) * (argc-2));
   
   // Copy the remaining args into an array of strings. Doing it this way because
   // they're const and need to be non-const. Maybe there's a better way though...
   // TODO do this without malloc
   for(int i = 0; i < (argc-3); ++i){
      args[i] = strcpy(
         (char*) malloc( sizeof(char) * (strlen (argv[i + 3]) + 1) ),
         argv[i + 3]);
   }

   // arg list must be null-terminated for execvp
   args[argc-3] = NULL;

   // Start a timer to track the total duration, as it's the most accurate way to do so I think
   timer_t timer = timer_get();
   timer_start(&timer, duration/1000, duration%1000);

   // just keep forkin
   while(!timer_complete(&timer)){
      fork_and_manage_child(path, args, frequency);
   }
   
   for(int i = 0; i < (argc-3); ++i) {
     free (args[i]);
   }
   free (args);

   return CS1_SUCCESS;
}
Beispiel #5
0
static void timer_handler(){
	if (!running) {
		return;
	}
	remaining -= 1000;
	if (remaining > 0) {
		set_timer();
		display_time();
	}
	else {
		timer_complete();
	}
	
}
Beispiel #6
0
int main(void)
{
  Initialize();		
  timer_start(TIMER_TEMP, TIMER_TEMP_DELAY);
  timer_start(TIMER_LCD, TIMER_LCD_DELAY);
  timer_start(TIMER_TURN90, TIMER_TURN90_DELAY);
  timer_start(TIMER_RECULE, TIMER_RECULE_DELAY);
  
  /*
  u08 tempmic;
  while (!GetMicValLuca(LEVELMIC, &tempmic)) {
    snprintf(str_l1, LCD_SIZE, "%02x - %02x", tempmic, LEVELMIC);
  }*/

  int nb_s = 0;

  while (1) {
    timer_handle();

    //Check switches
    if (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_STARTSTOP)) {
      while (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_STARTSTOP));
      if (!enable) {
        enable = 1;
      } else {
        enable = 0;
      }
    }
    if (enable) {
      if (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_MODESEL)) {
        while (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_MODESEL));
        mode++;
        mode %= 3;
      }
    }
    if (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_VAL)) {
      while (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_VAL));
      val_buttons++;
      val_buttons %= MAX_SPEED;
    }

    if (enable) {
      switch (mode) {
      case MODE_LINE:
        FollowLine();
        break;
      case MODE_SUMO:
        StayInside();
        break;
      case MODE_CARRE:
        DoCarre();
        break;
      }
    } else {
      //Stop
      AVANCE(0);
    }

    //Test the timer
    if (timer_complete(TIMER_TEMP)) {
      timer_start(TIMER_TEMP, 500);
      nb_s ++;
      //snprintf(str_l1, LCD_SIZE, "%d", nb_s);
    }

    if (timer_complete(TIMER_LCD)) {
      if (!enable) {
        snprintf(str_l1, LCD_SIZE, "off");
      } else {
        char mode_str[20];
        switch (mode) {
        case MODE_LINE: snprintf(mode_str, LCD_SIZE, "line"); break;
        case MODE_SUMO: snprintf(mode_str, LCD_SIZE, "sumo"); break;
        case MODE_CARRE: snprintf(mode_str, LCD_SIZE, "carr"); break;
        default: snprintf(mode_str, LCD_SIZE, "????"); break;
        }

        snprintf(str_l1, LCD_SIZE, "%s %02d ", mode_str, val_buttons);
       
      }

      timer_start(TIMER_LCD, TIMER_LCD_DELAY);
      lcd_str_out(1,1, str_l1);
      lcd_str_out(2,1, str_l2);
    }
  }

  return 0;
}