Skip to content

Commit b50ab28

Browse files
author
glingy
committed
Merge branch 'WIP'
2 parents e6ede6a + 8dd8e1e commit b50ab28

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

Vuforia/VuforiaView.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@
4848
public class VuforiaView extends LinearOpMode {
4949

5050
// whether or not to save the cropped image
51-
private boolean SAVE_CROPPED = false;
51+
private final boolean SAVE_CROPPED = false;
5252

5353
// 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;
5558

5659
@Override
5760
public void runOpMode() throws InterruptedException {
@@ -133,7 +136,7 @@ public void runOpMode() throws InterruptedException {
133136

134137
/* ************SETUP VARS FOR RUN!************* */
135138
//Suspected pictograph codes
136-
int[] pictographCodes = new int[5];
139+
int[] pictographCodes = new int[NUM_OF_TAKES];
137140

138141
//Final pictograph code --> 0: L, 1: C, 2: R, 3: N
139142
int finalPictographCode = 3;
@@ -192,7 +195,7 @@ public void runOpMode() throws InterruptedException {
192195
/* ************DECIDE WHICH PICTOGRAPH WE ARE LOOKING AT************* */
193196

194197
// calculate on first 5 runs through to have more resilience to shaking
195-
if (runCount < 5) {
198+
if (runCount < NUM_OF_TAKES) {
196199

197200
//Get vuforia's raw Pose data to be converted to OpenCV
198201
OpenGLMatrix rawPoseV = ((VuforiaTrackableDefaultListener) item.getListener()).getRawPose();
@@ -368,13 +371,14 @@ public void runOpMode() throws InterruptedException {
368371
//increase inARow
369372
inARow++;
370373

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
372375
if (inARow > 13) {
373-
onFirstHex = false; // if both black hexes are touching, reset in center
376+
onFirstHex = false;
374377
inARow = 0;
375378
}
376379
if (inARow > 4 && !onFirstHex) {
377380
onFirstHex = true;
381+
//If past halfway, lasthex, else firsthex
378382
if (ch > 15) {
379383
lasthex = 'B';
380384
} else {
@@ -388,6 +392,7 @@ public void runOpMode() throws InterruptedException {
388392
}
389393
}
390394

395+
//Decide based on first and second hex
391396
if (firsthex == 'B') {
392397
if (lasthex == 'O') {
393398
pictographCode = 0;
@@ -402,11 +407,14 @@ public void runOpMode() throws InterruptedException {
402407
}
403408
}
404409
}
410+
411+
//Both hexes orange... increase blackOff and go to beginning of loop
405412
if (pictographCode == 3) {
406413
blackOff += blackOff > 10 ? 7 : 15;
407414
}
408415
} while (pictographCode == 3);
409416

417+
//save current code to array for later
410418
pictographCodes[runCount] = pictographCode;
411419

412420

@@ -417,20 +425,26 @@ public void runOpMode() throws InterruptedException {
417425

418426
}
419427
}
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) {
421430
int[] codes = new int[3];
422431
for (int code : pictographCodes) {
432+
433+
//increase the code
423434
if (code != 3) {
424435
codes[code]++;
425436
}
426437
}
427438

428439
String finalColumn = "RIGHT";
440+
finalPictographCode = 2;
429441

430442
if (codes[0] > codes[1] && codes[0] > codes[2]) {
431443
finalColumn = "LEFT!";
444+
finalPictographCode = 0;
432445
} else if (codes[1] > codes[0] && codes[1] > codes[2]){
433446
finalColumn = "CENTER!";
447+
finalPictographCode = 1;
434448
}
435449

436450
telemetry.addLine(finalColumn);

0 commit comments

Comments
 (0)