-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonar.c
36 lines (32 loc) · 1006 Bytes
/
sonar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef SONAR_C
#define SONAR_C
#include "config.c"
#include "movement.c"
task avoidObstacles() {
struct Config const* c = NULL;
getConfig(&c);
while (true) {
wait1Msec(20);
#ifdef sensorFront
bool obstacleFront = SensorValue[sensorFront] * 10 < c->securityDistance;
#else
bool obstacleFront = false;
#endif
#ifdef sensorFront2
obstacleFront |= SensorValue[sensorFront2] * 10 < c->securityDistance;
#endif
#ifdef sensorBack
bool obstacleBack = SensorValue[sensorBack] * 10 < c->securityDistance;
#else
bool obstacleBack = false;
#endif
if ((getMovementType() == MOVETO_FORWARD && obstacleFront)
|| (getMovementType() == MOVETO_BACKWARD && obstacleBack))
{ pauseMovement(); displayTextLine(7, "obstacle"); }
else if ((!obstacleFront && !obstacleBack)
|| (getMovementType() == MOVETO_FORWARD && !obstacleFront)
|| (getMovementType() == MOVETO_BACKWARD && !obstacleBack))
{ resumeMovement(); displayTextLine(7, "OK");}
}
}
#endif