Skip to content

Commit d13af1a

Browse files
committed
feat: gap finding works and executes manoeuvre afterwards
1 parent 4ebed31 commit d13af1a

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

src/p6.c

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,22 @@ int p6_get_confident_ir_reading(int IRIndex, int confidenceRequired) {
228228
bool p6_is_gap() {
229229
int IRIndex = 5;
230230
int CONFIDENCE_REQUIRED = 3;
231-
int DISTANCE_THRESHOLD = 50; // How far away we should consider "a gap"
231+
int DISTANCE_THRESHOLD = 98; // How far away we should consider "a gap"
232232
int IRReading = p6_get_confident_ir_reading(IRIndex, CONFIDENCE_REQUIRED);
233233

234234
bool isBlocked = IRReading <= DISTANCE_THRESHOLD; // Blocked when IR closer to 0
235235

236236
return !isBlocked;
237237
}
238238

239+
void p6_switch_led(bool shouldToggleOn) {
240+
int i;
241+
242+
for (i = 0; i < 8; i++) {
243+
e_set_led(i, shouldToggleOn ? 1 : 0);
244+
}
245+
}
246+
239247
bool p6_is_big_gap() {
240248
int gapStart = p6_get_steps();
241249
int MINIMUM_GAP_SIZE = 2000;
@@ -298,52 +306,45 @@ void p6_straighten_up(int lastKnownDistanceToWall) {
298306
}
299307

300308
void p6_run(void) {
301-
// e_activate_agenda(p6_sense, 500);
302-
303309
// TODO: Find wall, use straighten up function, then continue
304310

305-
// p6_drive();
306-
307-
// e_activate_agenda(p6_sense, 500);
308-
309-
// TODO: Find wall, use straighten up function, then continue
310-
311311
e_activate_agenda(p6_travel_agenda, 10);
312312
e_activate_agenda(p6_travel_manager_agenda, 10);
313313

314-
p6_parallel_park(1);
314+
// Get the initial distance to the wall, use p6_straighten_up to keep it
315+
// int lastKnownDistanceToWall = p6_get_confident_ir_reading(5, 3);
316+
317+
p6_drive();
315318

316-
while(1) {}
317319

318-
// // Get the initial distance to the wall, use p6_straighten_up to keep it
319-
// int lastKnownDistanceToWall = p6_get_confident_ir_reading(5, 3);
320-
//
321-
// while (1) {
322-
// bool isGap = p6_is_gap();
323-
//
324-
// // If it's the start of an opening
325-
// if (isGap) {
326-
// bool isBigGap = p6_is_big_gap();
327-
//
328-
// // Stop if it's a big enough gap to fit the ePuck
329-
// if (isBigGap) {
330-
// // TODO: Parallel park here, currently just stop.
331-
// // p6_parallel_park();
332-
// p6_stop();
333-
// break;
334-
// }
335-
// } else {
336-
// // TODO: Straighten up here, currently assume user places robot straight;
337-
// // lastKnownDistanceToWall = p6_straighten_up(lastKnownDistanceToWall);
338-
// }
339-
//
340-
// int steps = p6_get_steps();
341-
//
342-
// // If this is taking too long, stop anyway
343-
// if (steps > 5000) {
344-
// p6_stop();
345-
// break;
346-
// }
347-
// }
320+
p6_switch_led(0);
321+
322+
while (1) {
323+
bool isGap = p6_is_gap();
324+
325+
// If it's the start of an opening
326+
if (isGap) {
327+
bool isBigGap = p6_is_big_gap();
328+
329+
// Stop if it's a big enough gap to fit the ePuck
330+
if (isBigGap) {
331+
p6_switch_led(1);
332+
p6_stop();
333+
p6_parallel_park(0);
334+
break;
335+
}
336+
} else {
337+
// TODO: Straighten up here, currently assume user places robot straight;
338+
// lastKnownDistanceToWall = p6_straighten_up(lastKnownDistanceToWall);
339+
}
340+
341+
int steps = p6_get_steps();
342+
343+
// If this is taking too long, stop anyway
344+
if (steps > 5000) {
345+
p6_stop();
346+
break;
347+
}
348+
}
348349
}
349350

0 commit comments

Comments
 (0)