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);
// k_care();
OnFwd (MLEFT); // dojezd k care
OnFwd (MRIGHT); // dojezd k care
Wait(50);
GoRed();
start red_bumper;
start blue_bumper;
start cara_cervena;
start cara_modra;
semafor = false;
ClearTimer (0);
start stochastika;
}
task stochastika()
{
while (true)
{
Wait(500);
if (semafor) start blue_bumper;
PlaySound (SOUND_CLICK);
OnFwd (MLEFT); // dojezd k care
OnFwd (MRIGHT); // dojezd k care
while (BLUE > THRESHOLD);
GoRed();
OnRev (MLEFT);
OnRev (MRIGHT);
Wait(100); // popojed kus
Zatoc();
ClearTimer (0);
}
}
void GoBlue()
{
OnFwd (MLEFT);
OnFwd (MRIGHT);
Wait(100); // popojed kus
Off(MLEFT);
Off(MRIGHT);
}
void GoRed()
{
OnRev (MLEFT);
OnRev (MRIGHT);
Wait(100); // popojed kus
Off(MLEFT);
Off(MRIGHT);
}
void Zatoc()
{
switch (Random(2))
{
case 0:
OnRev (MLEFT);
OnFwd (MRIGHT);
break;
case 1:
OnFwd (MLEFT);
OnRev (MRIGHT);
break;
case 2:
OnRev (MLEFT);
OnRev (MRIGHT);
}
Wait(100); // popojed kus
Off(MLEFT);
Off(MRIGHT);
}
void k_care() // najed do vyckavaci pozice
{
OnFwd (MLEFT); // dojezd k care
OnFwd (MRIGHT); // dojezd k care
while (BLUE > THRESHOLD);
GoRed();
OnRev (MLEFT);
OnRev (MRIGHT);
Wait(100); // popojed kus
Off(MLEFT);
Off(MRIGHT);
}
task red_bumper()
{
while(true)
{
while (100 != RED); // utoc, kdyz neco narazi do narazniku
PlaySound (SOUND_FAST_UP);
stop stochastika;
GoRed();
//!!! Zatoc();
start stochastika;
if (semafor) start blue_bumper;
}
}
task blue_bumper()
{
semafor = false;
while (0 == BBUMPER); // utoc, kdyz neco narazi do narazniku
PlaySound (SOUND_FAST_UP);
OnFwd (MLEFT);
OnFwd (MRIGHT);
semafor = true;
}
task cara_cervena() // hlidani natlaceni na caru
{
while(true)
{
while (RED < THRESHOLD || RED > RED_WHITE); // utoc, kdyz nas neco dotlaci k care
Wait(2); // kontrola za 20ms, aby se to nespletlo s naraznikem
if (RED > THRESHOLD && RED < RED_WHITE)
{
PlaySound (SOUND_DOUBLE_BEEP);
GoBlue();
}
}
}
task cara_modra() // hlidani cary
{
while(true)
{
while (BLUE > THRESHOLD); // cekej na caru
stop cara_cervena;
PlaySound (SOUND_DOUBLE_BEEP);
GoRed();
if (semafor) start blue_bumper;
start cara_cervena;
}
}