-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
70 lines (54 loc) · 1.3 KB
/
main.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
#include <stdlib.h>
#include <wiringPi.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include "motors.h"
#include "linesensor.h"
#include "DistanceSensor.h"
#include "SpeedEncoder.h"
#include "avoidance.h"
#define TRIGGER 21
#define ECHO 22
#define SPEEDENCODER 28
void initMotors();
void initSensors();
int act = 0;
int *actPtr = &act;
_Bool isTrail = TRUE;
_Bool * isTrailPtr = &isTrail;
//---------------------------------cleaning up threads--------------------------------
void handler(int sig)
{
printf("Execption ctrl-c Caught %d", sig);
stopAll();
exit(0);
}
//------------------------------------------------------------------------------------
int main() {
wiringPiSetup();
// threadinf the motors function
signal(SIGINT,handler);
initMotors();
initSensors();
while(isTrail) {
checkLineSensor(isTrailPtr);
checkEchoSensor();
sleep(.5);
}
return 0;
}
void initMotors() {
int m1 = init("motor1", "config2");
int m2 = init("motor2", "config1");
int m3 = init("motor3", "config1");
int m4 = init("motor4", "config2");
}
void initSensors() {
setup_line_sensors(23, 24, 25, 27, 29);
InitDistanceSensor(TRIGGER, ECHO);
InitSpeedEncoder(SPEEDENCODER);
}