Subversion Repositories svnkaklik

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 1

/roboti/callis/sumo_bumper.bak
0,0 → 1,152
#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_3
#define RED SENSOR_2
#define BBUMPER SENSOR_1
#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_CFG(SENSOR_TYPE_LIGHT, SENSOR_MODE_RAW)); // 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);
SetTxPower(TX_POWER_HI); // aby daleko videl
 
OnFwd (MLEFT); // cuknuti na shozeni radlic
OnFwd (MRIGHT);
Wait(50);
OnRev (MLEFT);
OnRev (MRIGHT);
Wait(50); // popojed kus
Off(MLEFT);
Off(MRIGHT);
 
start blue_bumper;
start 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 Obrat()
{
OnRev (MLEFT);
OnFwd (MRIGHT);
Wait(150); // popojed kus
Off(MLEFT);
Off(MRIGHT);
}
 
void Zatoc()
{
switch (Random(1))
{
case 0:
OnRev (MLEFT);
OnFwd (MRIGHT);
Wait(50);
break;
case 1:
OnFwd (MLEFT);
OnRev (MRIGHT);
Wait(50);
break;
case 2:
OnRev (MLEFT);
OnRev (MRIGHT);
Wait(70);
break;
case 3:
OnFwd (MLEFT);
OnFwd (MRIGHT);
Wait(70);
break;
}
}
 
task blue_bumper() // naraznik na modre strane
{
while(true)
{
if (1 == BBUMPER) // utoc, kdyz neco narazi do narazniku
{
stop stochastika;
PlaySound (SOUND_FAST_UP);
OnFwd (MLEFT);
OnFwd (MRIGHT);
Wait(50);
}
}
}
 
task cervena() // dalkovy sensor
{
int lastlevel;
 
lastlevel = 0;
while(true)
{
SendMessage(0);
if(lastlevel > SENSOR_2)
{
// Close to something
PlaySound(SOUND_FAST_UP);
stop stochastika;
Obrat();
start stochastika;
}
lastlevel = SENSOR_2;
lastlevel -= THRESHOLD;
}
}
 
task cara_modra() // hlidani cary
{
while(true)
{
if (BLUE < THRESHOLD) // cekej na caru
{
PlaySound (SOUND_DOUBLE_BEEP);
stop blue_bumper;
stop stochastika;
GoRed();
start blue_bumper;
start stochastika;
}
}
}