-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (49 loc) · 931 Bytes
/
main.cpp
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
#include "engine/Engine.hpp"
#include "sonar/Sonar.hpp"
#include "buzzer/Buzzer.hpp"
#include "defines.hpp"
#include <iostream>
using namespace std;
int main(void)
{
if( wiringPiSetup() == -1 )
{
cout << ("WiringPiSetup FAIL !!\n");
return -1;
}
Sonar s;
s.init(TRIGGER, ECHO);
cout << s.distance(30000)<<endl;
Engine left(LEFT_1, LEFT_2),
right(RIGHT_1, RIGHT_2);
Buzzer buzz(BUZZER);
long start=0, now=0;
bool stuck = false;
while(1)
{
start = micros();
while( s.distance(30000) < 15.0 ) // too close to an obstacle -> TURN LEFT
{
left.Drive(Direction::BWD);
right.Drive(Direction::FWD);
cout << "TO THE LEFT ! \n";
now = micros();
cout << now << "-> "<<start<<"\n";
if( ( now - start ) > 15000000 )
{
stuck = true;
cout << "STUCK!! \n";
break;
}
}
if(stuck)
{
buzz.PlaySong();
}
else
{
left.Drive();
right.Drive();
}
}
}