-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrackedRobot.c
163 lines (159 loc) · 4.31 KB
/
TrackedRobot.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//REMOTE ET SERIAL READING
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x60);
Adafruit_DCMotor *myMotorGauche = AFMS.getMotor(1);
Adafruit_DCMotor *myMotorDroite = AFMS.getMotor(2);
int inByte, Token;
//GPS
#include <Adafruit_GPS.h>
#define GPSSerial Serial3
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false
uint32_t timer = millis();
//ultrasonic sensor
#include <HCSR04.h>
HCSR04 hc(13, 12);
//Sharp Infrared Sensor
const int InfraSensorPin = A0;
//infrared line tracking sensor
const int IR1PIN = 27, IR2PIN = 26, IR3PIN = 29, IR4PIN = 28, IR5PIN = 31;
void setup() {
Serial.begin(115200);
Serial2.begin(115200);
AFMS.begin();
//movement
myMotorGauche->setSpeed(150);
myMotorGauche->run(FORWARD);
myMotorGauche->run(RELEASE);
myMotorDroite->setSpeed(150);
myMotorDroite->run(FORWARD);
myMotorDroite->run(RELEASE);
//GPS
/*GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
delay(1000);
GPSSerial.println(PMTK_Q_RELEASE);*/
//ultrasonic sensor
pinMode(IR1PIN, INPUT);
pinMode(IR2PIN, INPUT);
pinMode(IR3PIN, INPUT);
pinMode(IR4PIN, INPUT);
pinMode(IR5PIN, INPUT);
}
void loop() {
//REMOTE ET SERIAL READING
while (Serial2.available()) {
inByte = Serial2.read();
}
if ((inByte) == 'A') {
Token = 1;
}
else if ((inByte) == 'B') {
Token = 2;
}
else if ((inByte) == 'C') {
Token = 3;
}
else if ((inByte) == 'D') {
Token = 4;
}
else if ((inByte) == 'f') {
Token = 6;
}
switch (Token) {
case 0 :{
myMotorGauche->run(FORWARD);
myMotorGauche->setSpeed(100);
myMotorDroite->run(FORWARD);
myMotorDroite->setSpeed(100);
Token = 6;
}
case 1: { //mapX
while(Token == 1){
myMotorGauche->run(FORWARD);
myMotorGauche->setSpeed(250);
myMotorDroite->run(FORWARD);
myMotorDroite->setSpeed(215);
Token = 6;}
} break;
case 2: { //mapY
myMotorGauche->run(BACKWARD);
myMotorGauche->setSpeed(250);
myMotorDroite->run(BACKWARD);
myMotorDroite->setSpeed(215);
Token = 6;
} break;
case 3: { //mapPot1
myMotorGauche->run(BACKWARD);
myMotorGauche->setSpeed(180);
myMotorDroite->run(FORWARD);
myMotorDroite->setSpeed(190);
Token = 6;
} break;
case 4: { //mapPot2
myMotorGauche->run(FORWARD);
myMotorGauche->setSpeed(180 );
myMotorDroite->run(BACKWARD);
myMotorDroite->setSpeed(190);
Token = 6;
} break;
case 5 :{
myMotorGauche->run(FORWARD);
myMotorGauche->setSpeed(50);
myMotorDroite->run(FORWARD);
myMotorDroite->setSpeed(50);
Token = 6;
}
case 6 :{
myMotorGauche->run(FORWARD);
myMotorGauche->setSpeed(1);
myMotorDroite->run(FORWARD);
myMotorDroite->setSpeed(1);
Token = 6;
}
break;
}
//ultrasonic sensor
//Serial.println( hc.dist());
//Sharp Infrared Sensor
//Serial.print("IRSDIST:");
//Serial.println( 9462 / (analogRead(A0) - 16.92));
//Serial.println(map(analogRead(A0),80,490,140,20));
//infrared line tracking sensor
Serial.print("IR1:");
Serial.println(digitalRead(IR1PIN));
Serial.print("IR2:");
Serial.println(digitalRead(IR2PIN));
Serial.print("IR3:");
Serial.println(digitalRead(IR3PIN));
Serial.print("IR4:");
Serial.println(digitalRead(IR4PIN));
Serial.print("IR5:");
Serial.println(digitalRead(IR5PIN));
//GPS
char c = GPS.read();
if (GPSECHO)
if (c);
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return;
}
Serial.print("QUALITY:"); //ok
Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print("LAT:"); //ok
Serial.print(GPS.latitude, 4);
Serial.println(GPS.lat);
Serial.print("LONG:"); //ok
Serial.print(GPS.longitude, 4);
Serial.println(GPS.lon);
Serial.print("ALT:"); //ok
Serial.println(GPS.altitude);
Serial.print("SATT:"); //ok
Serial.println((int)GPS.satellites);
}
delay(15);
}