Subversion Repositories svnkaklik

Rev

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

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