Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
1 kaklik 1
#define THRESHOLD  44     // rozhodovaci uroven mezi cernou a bilou
2
#define RED_WHITE  60     // maximum bile na cervenem senzoru
3
#define MLEFT     OUT_A
4
#define MRIGHT    OUT_C
5
#define BLUE      SENSOR_3
6
#define RED       SENSOR_2
7
#define BBUMPER   SENSOR_1
8
#define START_ALL start blue_bumper; start cara_cervena; start cara_modra;
9
 
10
int semafor;
11
 
12
task main()
13
{
14
  PlaySound (SOUND_DOUBLE_BEEP);
15
  Wait(500); // 5s podle pravidel
16
  SetSensor(BLUE,SENSOR_LIGHT);   // senzor na caru modry
17
  SetSensor(RED,_SENSOR_CFG(SENSOR_TYPE_LIGHT, SENSOR_MODE_RAW)); // senzor na caru cerveny
18
  SetSensor(BBUMPER, SENSOR_TOUCH);  // naraznik modry
19
  SetSensorMode (BBUMPER, SENSOR_MODE_BOOL); // koncak bude ...
20
  SetPower (MLEFT,OUT_FULL);
21
  SetPower (MRIGHT,OUT_FULL);
22
  SetDirection(MLEFT, OUT_FWD);
23
  SetDirection(MRIGHT, OUT_FWD);
24
  SetTxPower(TX_POWER_HI);    // aby daleko videl
25
 
26
  OnFwd (MLEFT);         // cuknuti na shozeni radlic
27
  OnFwd (MRIGHT);
28
  Wait(20);
29
  OnRev (MLEFT);
30
  OnRev (MRIGHT);
31
  Wait(70);
32
  Off(MLEFT);
33
  Off(MRIGHT);
34
 
35
  start blue_bumper;
36
  start cervena;
37
  start cara_modra;
38
  start stochastika;
39
}
40
 
41
task stochastika()        // nahodne otaceni
42
{
43
  while(true) Zatoc();
44
}
45
 
46
void GoBlue()
47
{
48
  OnFwd (MLEFT);
49
  OnFwd (MRIGHT);
50
  Wait(300);              // popojed kus
51
  Off(MLEFT);
52
  Off(MRIGHT);
53
}
54
 
55
void GoRed()
56
{
57
  OnRev (MLEFT);
58
  OnRev (MRIGHT);
59
  Wait(300);              // popojed kus
60
  Off(MLEFT);
61
  Off(MRIGHT);
62
}
63
 
64
void Obrat()
65
{
66
  OnRev (MLEFT);
67
  OnFwd (MRIGHT);
68
  Wait(125);              // popojed kus
69
  Off(MLEFT);
70
  Off(MRIGHT);
71
}
72
 
73
void Zatoc()
74
{
75
  switch (Random(1))
76
  {
77
    case 0:
78
     OnRev (MLEFT);
79
     OnFwd (MRIGHT);
80
     Wait(50);
81
     break;
82
    case 1:
83
     OnFwd (MLEFT);
84
     OnRev (MRIGHT);
85
     Wait(50);
86
     break;
87
    case 2:
88
     OnRev (MLEFT);
89
     OnRev (MRIGHT);
90
     Wait(70);
91
     break;
92
    case 3:
93
     OnFwd (MLEFT);
94
     OnFwd (MRIGHT);
95
     Wait(70);
96
     break;
97
  }
98
}
99
 
100
task blue_bumper() // naraznik na modre strane
101
{
102
  while(true)
103
  {
104
    if (1 == BBUMPER) // utoc, kdyz neco narazi do narazniku
105
    {
106
      stop stochastika;
107
      PlaySound (SOUND_FAST_UP);
108
      OnFwd (MLEFT);
109
      OnFwd (MRIGHT);
110
      Wait(50);
111
    }
112
  }
113
}
114
 
115
task cervena() // dalkovy sensor
116
{
117
  int lastlevel;
118
 
119
  lastlevel = 0;
120
  while(true)
121
  {
122
    SendMessage(0);
123
    if(lastlevel > SENSOR_2)
124
    {
125
      PlaySound(SOUND_FAST_UP);
126
      stop stochastika;
127
      OnRev (MLEFT);
128
      OnRev (MRIGHT);
129
      Wait(10);              // popojed kus
130
      Off(MLEFT);
131
      Off(MRIGHT);
132
      Obrat();
133
      GoBlue();
134
      start stochastika;
135
    }
136
    lastlevel = SENSOR_2;
137
    lastlevel -= THRESHOLD;
138
  }
139
}
140
 
141
task cara_modra()    // hlidani cary
142
{
143
  while(true)
144
  {
145
     if (BLUE < THRESHOLD)    // cekej na caru
146
     {
147
        PlaySound (SOUND_DOUBLE_BEEP);
148
        stop blue_bumper;
149
        stop stochastika;
150
        stop cervena;
151
        GoRed();
152
        start cervena;
153
        start blue_bumper;
154
        start stochastika;
155
     }
156
  }
157
}
158