-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
314 lines (287 loc) · 8.36 KB
/
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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// VIVA LA GANESHA 17 Goes to Trinity
// Jagalah Kebersihan dan kerapihan codingan
// File name : main.cpp
// author/editor : Hansen EL14 /Babang EL13
// edited on : 23 November 2016
// Desc : pengetesan seluruh library
#include "mbed.h"
#include "ObjectVariabel.h"
// jangan lupa tambahkan 4 Ticker
// ticker untuk servo
Ticker timer;
// ticker untuk sensor jarak Infrared
Ticker _IR;
// pembaca keadaan tombol dan led
Ticker tombol;
Ticker ping;
int main() {
//int batasPutih =8000;
// int sudutNow;
Mode = SETAWAL;
// nyala bentar kipasnya dan LED
ENKipas = 0;
LEDPadamkanApi = 1;
wait(0.1);
//ENKipas = 1;
LEDPadamkanApi = 0;
// posisi awal
Posisi = HOME;
while (true) {
switch(Mode){
case SETAWAL:
DisplaySETAWAL();
// interrupt untuk infrared dan sensor garis
_IR.attach_us(&IF, &Infrared::update_ADC, 20*us_ms);
wait(0.1);
// mengatur servo
GaitSelect(4);
SetBodyHeight(65);
SetLegLiftHeight(18);
// GetReady(70,350);
GetReady(55,350);
wait(0.1);
HadapNormal();
SetGlobalSpeed(45);
SetTravelSpeed(50);
timer.attach(&attime,0.001*FrameTime);
// pengaturan servo selesai
//pengecekan semua LED, extinguisher, motor
tombol.attach_us(&CekTombol, 100*us_ms);
// mode ini selesai, langsung pindah state
InOut = true;
ping.attach_us(&UpdatePing, 100*us_ms);
// Pintu = KeluarR4A;
Mode = DEBUG;
wait(0.1);
break;
case INISIASI:
wait(0.1);
DisplayINIT();
while(!Suara);
while(Suara);
// mulai jika sudah ada suara
if (Suara == 0){
LEDBiru = 1;
wait (0.3);
if (Suara == 0)
wait (0.3);
if (Suara == 0)
Mode = JELAJAH;
}
// if (TombolReset == 0)
// Mode = JELAJAH;
// wait(7);
// Mode = MULAI;
break;
case MULAI:
//wait(0.5);
DisplayMULAI();
// tombol.attach_us(&CekTombol, 100*us_ms);
while (!Suara)
wait(0.1);
while (Suara);
Mode = DEBUG;
wait(0.2);
break;
case JELAJAH:
// ENKipas=1;
// wait(10);
//QuickStop();
//wait(2);
//LorongTimurkeR4();
// dor {
// wallKananApi(11,25,10);
// wait(0.1);
// } while (!ApiSekitar(75));
// QuickStop();
// wait(1);
// putarkeApiCoba(140);
// ENKipas=1;
// while (UV2.Flag==1){
// for(int ii=1;ii<=2;ii++){
// TengokKanan(ii*30);
// wait(0.01);
// }
// for(int ii=1;ii<=2;ii++){
// TengokKiri(ii*30);
// wait(0.01);
// }
// HadapNormal();
// }
// ENKipas=1;
// wait(10);
//wait(2);
DisplayJELAJAH();
//wait(0.1);
SetTravelSpeed(40);
//PadamkanApiR3();
//PadamkanApiR1();
//PutarSampaiArah(UTARA,KANAN,KompasToleransiKecil);
//MajuLurus(40);
// wait(0.1);
LEDBiru = 0;
keluarRuangan(true);
CariRuangan();
QuickStop();
wait(0.1);
break;
case PADAMKANAPI:
DisplayPADAMKANAPI();
PadamkanApi();
wait(0.1);
Mode=BACKHOME;
break;
case BACKHOME:
DisplayBACKHOME();
LEDPadamkanApi = 0;
backHome();
break;
case SELESAI:
DisplayFINISH();
wait(0.1);
break;
case DEBUG:
// update ruangan
//wait(0.2);
// UpdatePintu();
// if(GarisDepan == HITAM && GarisBelakang == PUTIH){
// UpdatePintu();
// }
//do{
//} while(TombolKalKompas==1);
// kompas.Kalibrasi();
//if(TombolKalKompas == 0){
//ENKipas = 0;
// kompas.Kalibrasi();
//}
//else if (TombolKalKompas == 1){
// ENKipas = 1;
//}
// DisplayClear();
// DisplayPintu();
DisplayDEBUG();
DisplaySound();
LCD.locate(0,1);
LCD.printf("%d",kompas.readBearing());
// LCD.printf("%d %d %d %d ", TombolKalKompas, ApiUjungKiri(90),ApiUjungKanan(90),ApiUjung(90));
LCD.locate (9,1);
if(UV2.Flag){
LCD.printf("API");
}
else{
LCD.printf("NOT_API");
}
DisplayKompas();
//DisplayGaris();
DisplayTotal_PC();
//TombolDepanKanan = _switch_depan_kanan.read();
//PC.printf("Tombol depan : %d",TombolDepanKanan);
wait(1);
//Mode = DEBUG;
break;
case BACKUP:
break;
case KALIBRASI:
DisplayLCD("Kalibrasi");
// tombol.attach_us(&CekTombol, 100*us_ms);
while (TombolKalKompas == 0);
while (TombolKalKompas == 1);
kompas.Reset();
kompas.Kalibrasi();
Mode = DEBUG;
wait(0.2);
break;
case COBA:
LEDBiru = 1;
LEDPadamkanApi = 1;
wait(3);
ResetArah();
DisplayLCD("Ke TIMUR");
PutarSampaiArah(TIMUR);
QuickStop();
wait(5);
ResetArah();
DisplayLCD("Ke SELATAN");
PutarSampaiArah(SELATAN);
QuickStop();
wait(5);
ResetArah();
DisplayLCD("Ke UTARA");
PutarSampaiArah(UTARA);
QuickStop();
wait(5);
ResetArah();
DisplayLCD("Ke BARAT");
PutarSampaiArah(BARAT);
QuickStop();
wait(5);
// do {
// PutarKanan(150);
// wait(0.1);
// GetArah(150);
// }while (ARAH!= UTARA);
// DisplayLCD("udah UTARA");
wait(3);
//ENKipas = 1;
// LorongTimurkeR4();
// QuickStop();
// do {
// wallKiriSlow(15,25,10);
// wait(0.1);
// } while (GarisTengah == HITAM);
//
// pintu.push_back(MasukR4A);
//
// CariApiR4A();
//
// Mode = PADAMKANAPI;
// DisplayLCD("COBA");
// //LorongTimurkeR4();
// ENKipas=1;
// wait(5);
// ENKipas=0;
// wait(5);
// UpdatePing();
//PC.printf("Jarak ping depan: %d\r\n", JarakPingDepan);
//wait(0.5);
// //DisplayLCD("MAJU LURUS");
// //MajuLurus(30);
// //wait(5);
// //QuickStop();
// //wait(0.1);
// DisplayLCD("Wall ROOM");
// for(int i =1; i<200;i++){
// wallKananSlow(14,25,10);
// wait(0.1);
// }
// QuickStop();
// wait(0.1);
// DisplayLCD("Wall LORONG");
// for(int i =1; i<200;i++){
// wallKananSlow(14,25,10);
// wait(0.1);
// }
//// wallKanan(18,25,10);
//// wait(20);
// QuickStop();
// wait(0.1);
// DisplayLCD("50");
// TengokBawah(50);
// wait(1);
// HadapNormal();
// wait(2);
//
// DisplayLCD("60");
// TengokBawah(60);
// wait(1);
// HadapNormal();
// wait(2);
//
// DisplayLCD("70");
// TengokBawah(70);
// wait(1);
// HadapNormal();
// wait(2);
}
}
}