Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
1 kaklik 1
/*
2
 * Ping
3
 * ====
4
 * Adapted from a program by Dave Chen and Simen Svale Skogsrud
5
 * 
6
 * This program assumes that the light sensor is on IN_2 and
7
 * that it points in the same direction as the infrared connection
8
 * on the robot. It beeps when the robot gets close to an obstacle.
9
 * This is done by repeatedly sending IR messages. These cause a
10
 * large fluctuation in light intensity.
11
 * 
12
 * This is a nice mechanism to find a close by wall without bumping
13
 * in to it.
14
 */
15
 
16
#define THRESHOLD 100    // Making this larger decreases the distance
17
 
18
int lastlevel;
19
 
20
task Ping()
21
// Constantly test whether there is a high fluctuation 
22
{
23
  SetSensor(SENSOR_2,_SENSOR_CFG(SENSOR_TYPE_LIGHT, SENSOR_MODE_RAW));
24
  lastlevel = 0;
25
  while(true)
26
  {
27
    SendMessage(0);
28
    if(lastlevel > SENSOR_2)
29
    {
30
      // Close to something
31
      PlaySound(1);
32
      Wait(30);
33
    }
34
    lastlevel = SENSOR_2;
35
    lastlevel -= THRESHOLD;
36
  }
37
}
38
 
39
task main()
40
{
41
  start Ping;
42
}
43