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_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(50);
29
  OnRev (MLEFT);
30
  OnRev (MRIGHT);
31
  Wait(50);              // popojed kus
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()
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 Obrat()
66
{
67
  OnRev (MLEFT);
68
  OnFwd (MRIGHT);
69
  Wait(150);              // popojed kus
70
  Off(MLEFT);
71
  Off(MRIGHT);
72
}
73
 
74
void Zatoc()
75
{
76
  switch (Random(1))
77
  {
78
    case 0:
79
     OnRev (MLEFT);
80
     OnFwd (MRIGHT);
81
     Wait(50);
82
     break;
83
    case 1:
84
     OnFwd (MLEFT);
85
     OnRev (MRIGHT);
86
     Wait(50);
87
     break;
88
    case 2:
89
     OnRev (MLEFT);
90
     OnRev (MRIGHT);
91
     Wait(70);
92
     break;
93
    case 3:
94
     OnFwd (MLEFT);
95
     OnFwd (MRIGHT);
96
     Wait(70);
97
     break;
98
  }
99
}
100
 
101
task blue_bumper() // naraznik na modre strane
102
{
103
  while(true)
104
  {
105
    if (1 == BBUMPER) // utoc, kdyz neco narazi do narazniku
106
    {
107
      stop stochastika;
108
      PlaySound (SOUND_FAST_UP);
109
      OnFwd (MLEFT);
110
      OnFwd (MRIGHT);
111
      Wait(50);
112
    }
113
  }
114
}
115
 
116
task cervena() // dalkovy sensor
117
{
118
  int lastlevel;
119
 
120
  lastlevel = 0;
121
  while(true)
122
  {
123
    SendMessage(0);
124
    if(lastlevel > SENSOR_2)
125
    {
126
      // Close to something
127
      PlaySound(SOUND_FAST_UP);
128
      stop stochastika;
129
      Obrat();
130
      Wait(50);
131
      start stochastika;
132
    }
133
    lastlevel = SENSOR_2;
134
    lastlevel -= THRESHOLD;
135
  }
136
}
137
 
138
task cara_modra()    // hlidani cary
139
{
140
  while(true)
141
  {
142
     if (BLUE < THRESHOLD)    // cekej na caru
143
     {
144
        PlaySound (SOUND_DOUBLE_BEEP);
145
        stop blue_bumper;
146
        stop stochastika;
147
        GoRed();
148
        start blue_bumper;
149
        start stochastika;
150
     }
151
  }
152
}
153