Skip to content

Commit

Permalink
"Smart-Auto Bug Fix V1.9"
Browse files Browse the repository at this point in the history
SmartXXXX# - Fix bug with thread not working sometimes.
  • Loading branch information
acastellar committed Feb 19, 2022
1 parent 22a1bf4 commit 2a8166d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.openftc.easyopencv.OpenCvCameraRotation;
import org.openftc.easyopencv.OpenCvPipeline;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


@Autonomous(name = "Blue Side #1 - Smart")
public class SmartBlue1 extends LinearOpMode {
Expand Down Expand Up @@ -72,10 +76,6 @@ public class SmartBlue1 extends LinearOpMode {
private int heightStartEncoder = -1;
private int distanceStartEncoder = -1;

// Used for multi-threading
private static boolean finishedScoring = false;
private static boolean finishedDriving1 = false;

@Override
public void runOpMode() throws InterruptedException {
/// IMPORT AND CONFIGURE ALL HARDWARE ///
Expand Down Expand Up @@ -184,30 +184,24 @@ public void runOpMode() throws InterruptedException {
final double levelHeight = levelHeightSetter; //15.85 top level (level 2)
final double levelDistance = levelDistanceSetter; //3 top level (level 2)

finishedScoring = false;
finishedDriving1 = false;
new Thread(() -> {
setArm(1, levelHeight,2);
sleep(250);
while (!finishedDriving1) {
ExecutorService executor = Executors.newSingleThreadExecutor();

}
moveForward(0.2,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);
finishedScoring = true;
}).start();
Future armThread1 = executor.submit(() -> {
telemetry.addData("Running", "Arm Thread");
telemetry.update();
setArm(1, levelHeight,2);
});
moveForward(0.2,4);
strafeLeft(0.125, 10);
rotate(0.25,25);
moveForward(0.25,17);
finishedDriving1 = true;

runtime.reset();
while(!finishedScoring && (runtime.seconds() < 11)) {
while(!armThread1.isDone() && opModeIsActive()) {

}
runtime.reset();
executor.shutdown();
moveForward(0.2,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);

// Move it back and prepare for next step
setArm(1, levelHeight,0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.openftc.easyopencv.OpenCvCameraRotation;
import org.openftc.easyopencv.OpenCvPipeline;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


@Autonomous(name = "Blue Side #2 - Smart")
public class SmartBlue2 extends LinearOpMode {
Expand Down Expand Up @@ -184,30 +188,22 @@ public void runOpMode() throws InterruptedException {
final double levelHeight = levelHeightSetter; //15.85 top level (level 2)
final double levelDistance = levelDistanceSetter; //3 top level (level 2)

finishedScoring = false;
finishedDriving1 = false;
new Thread(() -> {
setArm(1, levelHeight,2);
while (!finishedDriving1) {
ExecutorService executor = Executors.newSingleThreadExecutor();

}
telemetry.addData("In", "in");
Future armThread1 = executor.submit(() -> {
telemetry.addData("Running", "Arm Thread");
telemetry.update();
moveForward(0.1,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);
finishedScoring = true;
}).start();
setArm(1, levelHeight,2);
});
moveForward(0.2,4);
rotate(0.1,-30);
moveForward(0.1,17);
finishedDriving1 = true;

runtime.reset();
while(!finishedScoring && (runtime.seconds() < 11)) {

while(!armThread1.isDone() && opModeIsActive()) {
}
runtime.reset();
executor.shutdown();
moveForward(0.1,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);

// Move it back and prepare for next step
setArm(1, levelHeight,0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.openftc.easyopencv.OpenCvCameraRotation;
import org.openftc.easyopencv.OpenCvPipeline;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


@Autonomous(name = "Red Side #1 - Smart")

Expand Down Expand Up @@ -73,10 +77,6 @@ public class SmartRed1 extends LinearOpMode {
private int heightStartEncoder = -1;
private int distanceStartEncoder = -1;

// Used for multi-threading
private static boolean finishedScoring = false;
private static boolean finishedDriving1 = false;

@Override
public void runOpMode() throws InterruptedException {
/// IMPORT AND CONFIGURE ALL HARDWARE ///
Expand Down Expand Up @@ -185,29 +185,24 @@ public void runOpMode() throws InterruptedException {
final double levelHeight = levelHeightSetter; //15.85 top level (level 2)
final double levelDistance = levelDistanceSetter; //3 top level (level 2)

finishedScoring = false;
finishedDriving1 = false;
new Thread(() -> {
setArm(1, levelHeight,2);
sleep(250);
while (!finishedDriving1) {
ExecutorService executor = Executors.newSingleThreadExecutor();

}
moveForward(0.2,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);
finishedScoring = true;
}).start();
Future armThread1 = executor.submit(() -> {
telemetry.addData("Running", "Arm Thread");
telemetry.update();
setArm(1, levelHeight,2);
});
moveForward(0.2,4);
rotate(0.25,-35);
moveForward(0.25,16);
finishedDriving1 = true;

runtime.reset();
while(!finishedScoring && (runtime.seconds() < 11)) {
while(!armThread1.isDone() && opModeIsActive()) {

}
runtime.reset();
executor.shutdown();
moveForward(0.2,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);


// Move it back and prepare for next step
setArm(1, levelHeight-2,0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import org.openftc.easyopencv.OpenCvCameraFactory;
import org.openftc.easyopencv.OpenCvCameraRotation;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


@Autonomous(name = "Red Side #2 - Smart")
public class SmartRed2 extends LinearOpMode {
Expand Down Expand Up @@ -65,10 +69,6 @@ public class SmartRed2 extends LinearOpMode {
private int heightStartEncoder = -1;
private int distanceStartEncoder = -1;

// Used for multi-threading
private static boolean finishedScoring = false;
private static boolean finishedDriving1 = false;

@Override
public void runOpMode() throws InterruptedException {
/// IMPORT AND CONFIGURE ALL HARDWARE ///
Expand Down Expand Up @@ -177,30 +177,22 @@ public void runOpMode() throws InterruptedException {
final double levelHeight = levelHeightSetter; //15.85 top level (level 2)
final double levelDistance = levelDistanceSetter; //3 top level (level 2)

finishedScoring = false;
finishedDriving1 = false;
new Thread(() -> {
setArm(1, levelHeight,2);
while (!finishedDriving1) {
ExecutorService executor = Executors.newSingleThreadExecutor();

}
telemetry.addData("In", "in");
Future armThread1 = executor.submit(() -> {
telemetry.addData("Running", "Arm Thread");
telemetry.update();
moveForward(0.1,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);
finishedScoring = true;
}).start();
setArm(1, levelHeight,2);
});
moveForward(0.1,4);
rotate(0.1,50);
moveForward(0.2,17);
finishedDriving1 = true;

runtime.reset();
while(!finishedScoring && (runtime.seconds() < 11)) {

while(!armThread1.isDone() && opModeIsActive()) {
}
runtime.reset();
executor.shutdown();
moveForward(0.1,6);
setArm(1, levelHeight,levelDistance);
moveClaws(false, 1000);

// Move it back and prepare for next step
setArm(1, levelHeight,0.5);
Expand Down

0 comments on commit 2a8166d

Please sign in to comment.