Subversion Repositories svnkaklik

Rev

Rev 1 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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