-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavoid_boundaries.c
75 lines (75 loc) · 1.81 KB
/
avoid_boundaries.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
void avoid_boundaries(BoundarySide line_sensor_number)
{
if (line_sensor_number == FRONT_LEFT)
{
writeDebugStreamLine("%s", "front left line sensor activated");
clearTimer(T2);
while (time1(T2) < 1000)
{
// move backward
control_motor(-45, -45);
}
clearTimer(T2);
while (time1(T2) < 1200)
{
// rotate CW
control_motor(60, -60);
}
stop_motor();
return;
}
else if (line_sensor_number == BACK_LEFT)
{
writeDebugStreamLine("%s", "back left line sensor activated");
clearTimer(T2);
while (time1(T2) < 1000)
{
// move forward
control_motor(60, 60);
}
clearTimer(T2);
while (time1(T2) < 1200)
{
// rotate CCW
control_motor(-60, 60);
}
stop_motor();
return;
}
else if (line_sensor_number == FRONT_RIGHT)
{
writeDebugStreamLine("%s", "front right line sensor activated");
clearTimer(T2);
while (time1(T2) < 1000)
{
// move backward
control_motor(-45, -45);
}
clearTimer(T2);
while (time1(T2) < 1200)
{
// rotate CCW
control_motor(-60, 60);
}
stop_motor();
return;
}
else if (line_sensor_number == BACK_RIGHT)
{
writeDebugStreamLine("%s", "back right line sensor activated");
clearTimer(T2);
while (time1(T2) < 1000)
{
// move forward
control_motor(60, 60);
}
clearTimer(T2);
while (time1(T2) < 1200)
{
// rotate CW
control_motor(60, -60);
}
stop_motor();
return;
}
}