Subversion Repositories svnkaklik

Rev

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_1
6
#define RED       SENSOR_2
7
#define BBUMPER   SENSOR_3
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_LIGHT);   // 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
 
25
  OnFwd (MLEFT);         // cuknuti na shozeni radlic
26
  OnFwd (MRIGHT);
27
  Wait(50);
28
  GoRed();
29
 
30
  start red_bumper;
31
  start blue_bumper;
32
  start cara_cervena;
33
  start cara_modra;
34
  start stochastika;
35
}
36
 
37
task stochastika()
38
{
39
  while(true) Zatoc();
40
}
41
 
42
 
43
void GoBlue()
44
{
45
  OnFwd (MLEFT);
46
  OnFwd (MRIGHT);
47
  Wait(300);              // popojed kus
48
  Off(MLEFT);
49
  Off(MRIGHT);
50
}
51
 
52
void GoRed()
53
{
54
  OnRev (MLEFT);
55
  OnRev (MRIGHT);
56
  Wait(300);              // popojed kus
57
  Off(MLEFT);
58
  Off(MRIGHT);
59
}
60
 
61
void Zatoc()
62
{
63
  switch (Random(3))
64
  {
65
    case 0:
66
     OnRev (MLEFT);
67
     OnFwd (MRIGHT);
68
     Wait(200);
69
     break;
70
    case 1:
71
     OnFwd (MLEFT);
72
     OnRev (MRIGHT);
73
     Wait(200);
74
     break;
75
    case 2:
76
     OnRev (MLEFT);
77
     OnRev (MRIGHT);
78
     Wait(20);
79
     break;
80
    case 3:
81
     OnFwd (MLEFT);
82
     OnFwd (MRIGHT);
83
     Wait(20);
84
     break;
85
  }
86
}
87
 
88
void k_care()  // najed do vyckavaci pozice
89
{
90
  OnFwd (MLEFT);                  // dojezd k care
91
  OnFwd (MRIGHT);                  // dojezd k care
92
  while (BLUE > THRESHOLD);
93
  GoRed();
94
  OnRev (MLEFT);
95
  OnRev (MRIGHT);
96
  Wait(100);              // popojed kus
97
  Off(MLEFT);
98
  Off(MRIGHT);
99
}
100
 
101
task red_bumper()
102
{
103
  while(true)
104
  {
105
    if (100 == RED) // utoc, kdyz neco narazi do narazniku
106
    {
107
      PlaySound (SOUND_FAST_UP);
108
      stop stochastika;
109
      OnRev (MLEFT);
110
      OnRev (MRIGHT);
111
      Wait(50);
112
    }
113
  }
114
}
115
 
116
task blue_bumper()
117
{
118
  while(true)
119
  {
120
    if (1 == BBUMPER) // utoc, kdyz neco narazi do narazniku
121
    {
122
      PlaySound (SOUND_FAST_UP);
123
      stop stochastika;
124
      OnFwd (MLEFT);
125
      OnFwd (MRIGHT);
126
      Wait(50);
127
    }
128
  }
129
}
130
 
131
task cara_cervena() // hlidani natlaceni na caru
132
{
133
  while(true)
134
  {
135
    if ((RED > THRESHOLD) && (RED < RED_WHITE))
136
    {
137
      Wait(2);
138
      if ((RED > THRESHOLD) && (RED < RED_WHITE))
139
      {
140
        PlaySound (SOUND_DOUBLE_BEEP);
141
        stop red_bumper;
142
        GoBlue();
143
        start red_bumper;
144
        start stochastika;
145
      }
146
    }
147
  }
148
}
149
 
150
task cara_modra()    // hlidani cary
151
{
152
  while(true)
153
  {
154
     if (BLUE < THRESHOLD)    // cekej na caru
155
     {
156
        PlaySound (SOUND_DOUBLE_BEEP);
157
        stop blue_bumper;
158
        GoRed();
159
        start blue_bumper;
160
        start stochastika;
161
     }
162
  }
163
}
164