48
48
public class VuforiaView extends LinearOpMode {
49
49
50
50
// whether or not to save the cropped image
51
- private boolean SAVE_CROPPED = false ;
51
+ private final boolean SAVE_CROPPED = false ;
52
52
53
53
// display textual representation of image and wait one second or not
54
- private boolean SHOW_TEXT_IMAGE = false ;
54
+ private final boolean SHOW_TEXT_IMAGE = false ;
55
+
56
+ //How many times to run through? Suggested: 7
57
+ private final int NUM_OF_TAKES = 7 ;
55
58
56
59
@ Override
57
60
public void runOpMode () throws InterruptedException {
@@ -133,7 +136,7 @@ public void runOpMode() throws InterruptedException {
133
136
134
137
/* ************SETUP VARS FOR RUN!************* */
135
138
//Suspected pictograph codes
136
- int [] pictographCodes = new int [5 ];
139
+ int [] pictographCodes = new int [NUM_OF_TAKES ];
137
140
138
141
//Final pictograph code --> 0: L, 1: C, 2: R, 3: N
139
142
int finalPictographCode = 3 ;
@@ -192,7 +195,7 @@ public void runOpMode() throws InterruptedException {
192
195
/* ************DECIDE WHICH PICTOGRAPH WE ARE LOOKING AT************* */
193
196
194
197
// calculate on first 5 runs through to have more resilience to shaking
195
- if (runCount < 5 ) {
198
+ if (runCount < NUM_OF_TAKES ) {
196
199
197
200
//Get vuforia's raw Pose data to be converted to OpenCV
198
201
OpenGLMatrix rawPoseV = ((VuforiaTrackableDefaultListener ) item .getListener ()).getRawPose ();
@@ -368,13 +371,14 @@ public void runOpMode() throws InterruptedException {
368
371
//increase inARow
369
372
inARow ++;
370
373
371
- //if more than 13 in a row... (Committing before further changes...)
374
+ //if more than 13 in a row, reset counters as if interrupted because this is the end/past the end of the first hex
372
375
if (inARow > 13 ) {
373
- onFirstHex = false ; // if both black hexes are touching, reset in center
376
+ onFirstHex = false ;
374
377
inARow = 0 ;
375
378
}
376
379
if (inARow > 4 && !onFirstHex ) {
377
380
onFirstHex = true ;
381
+ //If past halfway, lasthex, else firsthex
378
382
if (ch > 15 ) {
379
383
lasthex = 'B' ;
380
384
} else {
@@ -388,6 +392,7 @@ public void runOpMode() throws InterruptedException {
388
392
}
389
393
}
390
394
395
+ //Decide based on first and second hex
391
396
if (firsthex == 'B' ) {
392
397
if (lasthex == 'O' ) {
393
398
pictographCode = 0 ;
@@ -402,11 +407,14 @@ public void runOpMode() throws InterruptedException {
402
407
}
403
408
}
404
409
}
410
+
411
+ //Both hexes orange... increase blackOff and go to beginning of loop
405
412
if (pictographCode == 3 ) {
406
413
blackOff += blackOff > 10 ? 7 : 15 ;
407
414
}
408
415
} while (pictographCode == 3 );
409
416
417
+ //save current code to array for later
410
418
pictographCodes [runCount ] = pictographCode ;
411
419
412
420
@@ -417,20 +425,26 @@ public void runOpMode() throws InterruptedException {
417
425
418
426
}
419
427
}
420
- } else if (runCount == 5 ) {
428
+ //When finished with enough tries, find most common answer (sometimes 1+ is different...)
429
+ } else if (runCount == NUM_OF_TAKES ) {
421
430
int [] codes = new int [3 ];
422
431
for (int code : pictographCodes ) {
432
+
433
+ //increase the code
423
434
if (code != 3 ) {
424
435
codes [code ]++;
425
436
}
426
437
}
427
438
428
439
String finalColumn = "RIGHT" ;
440
+ finalPictographCode = 2 ;
429
441
430
442
if (codes [0 ] > codes [1 ] && codes [0 ] > codes [2 ]) {
431
443
finalColumn = "LEFT!" ;
444
+ finalPictographCode = 0 ;
432
445
} else if (codes [1 ] > codes [0 ] && codes [1 ] > codes [2 ]){
433
446
finalColumn = "CENTER!" ;
447
+ finalPictographCode = 1 ;
434
448
}
435
449
436
450
telemetry .addLine (finalColumn );
0 commit comments