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_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
  OnRev (MLEFT);
29
  OnRev (MRIGHT);
30
  Wait(100);              // popojed kus
31
  Off(MLEFT);
32
  Off(MRIGHT);
33
 
34
  start red_bumper;
35
  start blue_bumper;
36
  start cara_cervena;
37
  start cara_modra;
38
  start stochastika;
39
}
40
 
41
task stochastika()
42
{
43
  while(true) Zatoc();
44
}
45
 
46
 
47
void GoBlue()
48
{
49
  OnFwd (MLEFT);
50
  OnFwd (MRIGHT);
51
  Wait(300);              // popojed kus
52
  Off(MLEFT);
53
  Off(MRIGHT);
54
}
55
 
56
void GoRed()
57
{
58
  OnRev (MLEFT);
59
  OnRev (MRIGHT);
60
  Wait(300);              // popojed kus
61
  Off(MLEFT);
62
  Off(MRIGHT);
63
}
64
 
65
void Zatoc()
66
{
67
  switch (Random(3))
68
  {
69
    case 0:
70
     OnRev (MLEFT);
71
     OnFwd (MRIGHT);
72
     Wait(20);
73
     break;
74
    case 1:
75
     OnFwd (MLEFT);
76
     OnRev (MRIGHT);
77
     Wait(20);
78
     break;
79
    case 2:
80
     OnRev (MLEFT);
81
     OnRev (MRIGHT);
82
     Wait(70);
83
     break;
84
    case 3:
85
     OnFwd (MLEFT);
86
     OnFwd (MRIGHT);
87
     Wait(70);
88
     break;
89
  }
90
}
91
 
92
task red_bumper()
93
{
94
  while(true)
95
  {
96
    if (100 == RED) // utoc, kdyz neco narazi do narazniku
97
    {
98
      PlaySound (SOUND_FAST_UP);
99
      stop stochastika;
100
      OnRev (MLEFT);
101
      OnRev (MRIGHT);
102
      Wait(50);
103
    }
104
  }
105
}
106
 
107
task blue_bumper()
108
{
109
  while(true)
110
  {
111
    if (1 == BBUMPER) // utoc, kdyz neco narazi do narazniku
112
    {
113
      PlaySound (SOUND_FAST_UP);
114
      stop stochastika;
115
      OnFwd (MLEFT);
116
      OnFwd (MRIGHT);
117
      Wait(50);
118
    }
119
  }
120
}
121
 
122
task cara_cervena() // hlidani natlaceni na caru
123
{
124
  while(true)
125
  {
126
    if ((RED > THRESHOLD) && (RED < RED_WHITE))
127
    {
128
      Wait(2);
129
      if ((RED > THRESHOLD) && (RED < RED_WHITE))
130
      {
131
        PlaySound (SOUND_DOUBLE_BEEP);
132
        stop red_bumper;
133
        GoBlue();
134
        start red_bumper;
135
        start stochastika;
136
      }
137
    }
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
        GoRed();
150
        start blue_bumper;
151
        start stochastika;
152
     }
153
  }
154
}
155