Subversion Repositories svnkaklik

Rev

Rev 1 | Blame | Last modification | View Log | Download

#define THRESHOLD  44     // rozhodovaci uroven mezi cernou a bilou
#define RED_WHITE  60     // maximum bile na cervenem senzoru
#define MLEFT     OUT_A
#define MRIGHT    OUT_C
#define BLUE      SENSOR_1
#define RED       SENSOR_2
#define BBUMPER   SENSOR_3
#define START_ALL start blue_bumper; start cara_cervena; start cara_modra;

int semafor;

task main()
{
  PlaySound (SOUND_DOUBLE_BEEP);
  Wait(500); // 5s podle pravidel
  SetSensor(BLUE,SENSOR_LIGHT);   // senzor na caru modry
  SetSensor(RED,SENSOR_LIGHT);   // senzor na caru cerveny
  SetSensor(BBUMPER, SENSOR_TOUCH);  // naraznik modry
  SetSensorMode (BBUMPER, SENSOR_MODE_BOOL); // koncak bude ...
  SetPower (MLEFT,OUT_FULL);
  SetPower (MRIGHT,OUT_FULL);
  SetDirection(MLEFT, OUT_FWD);
  SetDirection(MRIGHT, OUT_FWD);

  OnFwd (MLEFT);         // cuknuti na shozeni radlic
  OnFwd (MRIGHT);
  Wait(50);
  GoRed();

  start red_bumper;
  start blue_bumper;
  start cara_cervena;
  start cara_modra;
  start stochastika;
}

task stochastika()
{
  while(true) Zatoc();
}


void GoBlue()
{
  OnFwd (MLEFT);
  OnFwd (MRIGHT);
  Wait(300);              // popojed kus
  Off(MLEFT);
  Off(MRIGHT);
}

void GoRed()
{
  OnRev (MLEFT);
  OnRev (MRIGHT);
  Wait(300);              // popojed kus
  Off(MLEFT);
  Off(MRIGHT);
}

void Zatoc()
{
  switch (Random(3))
  {
    case 0:
     OnRev (MLEFT);
     OnFwd (MRIGHT);
     Wait(200);
     break;
    case 1:
     OnFwd (MLEFT);
     OnRev (MRIGHT);
     Wait(200);
     break;
    case 2:
     OnRev (MLEFT);
     OnRev (MRIGHT);
     Wait(20);
     break;
    case 3:
     OnFwd (MLEFT);
     OnFwd (MRIGHT);
     Wait(20);
     break;
  }
}

task red_bumper()
{
  while(true)
  {
    if (100 == RED) // utoc, kdyz neco narazi do narazniku
    {
      PlaySound (SOUND_FAST_UP);
      stop stochastika;
      OnRev (MLEFT);
      OnRev (MRIGHT);
      Wait(50);
    }
  }
}

task blue_bumper()
{
  while(true)
  {
    if (1 == BBUMPER) // utoc, kdyz neco narazi do narazniku
    {
      PlaySound (SOUND_FAST_UP);
      stop stochastika;
      OnFwd (MLEFT);
      OnFwd (MRIGHT);
      Wait(50);
    }
  }
}

task cara_cervena() // hlidani natlaceni na caru
{
  while(true)
  {
    if ((RED > THRESHOLD) && (RED < RED_WHITE))
    {
      Wait(2);
      if ((RED > THRESHOLD) && (RED < RED_WHITE))
      {
        PlaySound (SOUND_DOUBLE_BEEP);
        stop red_bumper;
        GoBlue();
        start red_bumper;
        start stochastika;
      }
    }
  }
}

task cara_modra()    // hlidani cary
{
  while(true)
  {
     if (BLUE < THRESHOLD)    // cekej na caru
     {
        PlaySound (SOUND_DOUBLE_BEEP);
        stop blue_bumper;
        GoRed();
        start blue_bumper;
        start stochastika;
     }
  }
}