@@ -228,14 +228,22 @@ int p6_get_confident_ir_reading(int IRIndex, int confidenceRequired) {
228
228
bool p6_is_gap () {
229
229
int IRIndex = 5 ;
230
230
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"
232
232
int IRReading = p6_get_confident_ir_reading (IRIndex , CONFIDENCE_REQUIRED );
233
233
234
234
bool isBlocked = IRReading <= DISTANCE_THRESHOLD ; // Blocked when IR closer to 0
235
235
236
236
return !isBlocked ;
237
237
}
238
238
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
+
239
247
bool p6_is_big_gap () {
240
248
int gapStart = p6_get_steps ();
241
249
int MINIMUM_GAP_SIZE = 2000 ;
@@ -298,52 +306,45 @@ void p6_straighten_up(int lastKnownDistanceToWall) {
298
306
}
299
307
300
308
void p6_run (void ) {
301
- // e_activate_agenda(p6_sense, 500);
302
-
303
309
// TODO: Find wall, use straighten up function, then continue
304
310
305
- // p6_drive();
306
-
307
- // e_activate_agenda(p6_sense, 500);
308
-
309
- // TODO: Find wall, use straighten up function, then continue
310
-
311
311
e_activate_agenda (p6_travel_agenda , 10 );
312
312
e_activate_agenda (p6_travel_manager_agenda , 10 );
313
313
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 ();
315
318
316
- while (1 ) {}
317
319
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
+ }
348
349
}
349
350
0 commit comments