Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Add runSync to Context for symmetry with startAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
rcahoon committed Mar 11, 2024
1 parent 9ab8b67 commit e62c5f2
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/team766/framework/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ public LaunchedContext startAsync(final Runnable func) {
return new Context(func, this);
}

/**
* Run the given Procedure synchronously (the calling Procedure will not resume until this one
* has finished).
*/
public void runSync(final RunnableWithContext func) {
func.run(this);
}

/**
* Interrupt the running of this Context and force it to terminate.
*
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/team766/robot/gatorade/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public void run(Context context) {
* ControlConstants.MAX_VEL_ROT; // For steer

if (leftJoystick.getButtonPressed(InputConstants.INTAKE_OUT)) {
new IntakeOut().run(context);
context.runSync(new IntakeOut());
} else if (leftJoystick.getButtonReleased(InputConstants.INTAKE_OUT)) {
new IntakeStop().run(context);
context.runSync(new IntakeStop());
}

if (leftJoystick.getButtonPressed(InputConstants.RESET_GYRO)) {
Expand Down Expand Up @@ -122,11 +122,11 @@ public void run(Context context) {

// first, check if the boxop is making a cone or cube selection
if (boxopGamepad.getPOV() == InputConstants.POV_UP) {
new GoForCones().run(context);
context.runSync(new GoForCones());
setLightsForGamePiece();
SmartDashboard.putBoolean("Game Piece", true);
} else if (boxopGamepad.getPOV() == InputConstants.POV_DOWN) {
new GoForCubes().run(context);
context.runSync(new GoForCubes());
setLightsForGamePiece();
SmartDashboard.putBoolean("Game Piece", false);
}
Expand All @@ -151,11 +151,11 @@ public void run(Context context) {

// look for button hold to start intake, release to idle intake
if (boxopGamepad.getButtonPressed(InputConstants.BUTTON_INTAKE_IN)) {
new IntakeIn().run(context);
context.runSync(new IntakeIn());
} else if (boxopGamepad.getButtonReleased(InputConstants.BUTTON_INTAKE_IN)) {
new IntakeIdle().run(context);
context.runSync(new IntakeIdle());
} else if (boxopGamepad.getButton(InputConstants.BUTTON_INTAKE_STOP)) {
new IntakeStop().run(context);
context.runSync(new IntakeStop());
}

// look for button hold to extend intake/wrist/elevator superstructure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void run(Context context) {
context.takeOwnership(Robot.wrist);
context.takeOwnership(Robot.elevator);

new IntakeIn().run(context);
new ExtendWristvatorToHuman(gamePieceType).run(context);
context.runSync(new IntakeIn());
context.runSync(new ExtendWristvatorToHuman(gamePieceType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void run(Context context) {
double driveSpeed = 1;

// extend wristvator to put CG in a place where robot can climb ramp
new ExtendWristvatorToMid().run(context);
context.runSync(new ExtendWristvatorToMid());

// Sets movement direction ground state if on ground
setDir(curY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void run(Context context) {
double startY = Robot.drive.getCurrentPosition().getY();
// robot gyro is offset 90º from how we want, so we reset it to 90º to account for this
Robot.drive.resetGyro();
// new IntakeRelease().run(context);
// context.runSync(new IntakeRelease());
Robot.drive.controlFieldOriented(0, -FollowPointsInputConstants.SPEED, 0);
context.waitFor(() -> Math.abs(Robot.drive.getCurrentPosition().getY() - startY) > DIST);
Robot.drive.stopDrive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void run(Context context) {
log("invalid alliance");
return;
}
new ScoreHigh(type).run(context);
new GyroBalance(alliance.get()).run(context);
context.runSync(new ScoreHigh(type));
context.runSync(new GyroBalance(alliance.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void run(Context context) {
return;
}
log("exiting");
new ScoreHigh(type).run(context);
new RetractWristvator().run(context);
new ExitCommunity().run(context);
context.runSync(new ScoreHigh(type));
context.runSync(new RetractWristvator());
context.runSync(new ExitCommunity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void run(Context context) {
return;
}
log("exiting");
new ScoreHigh(type).run(context);
new ExitCommunity().run(context);
context.runSync(new ScoreHigh(type));
context.runSync(new ExitCommunity());
log("Transitioning");
new GyroBalance(alliance.get()).run(context);
context.runSync(new GyroBalance(alliance.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class RetractWristvatorIdleIntake extends Procedure {
public void run(Context context) {
new RetractWristvator().run(context);
new IntakeIdle().run(context);
context.runSync(new RetractWristvator());
context.runSync(new IntakeIdle());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void run(Context context) {
context.takeOwnership(Robot.intake);
Robot.intake.setGamePieceType(type);
context.releaseOwnership(Robot.intake);
new ExtendWristvatorToHigh().run(context);
new IntakeOut().run(context);
context.runSync(new ExtendWristvatorToHigh());
context.runSync(new IntakeOut());
context.waitForSeconds(1);
new IntakeStop().run(context);
context.runSync(new IntakeStop());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public void run(Context context) {
context.waitFor(Robot.shooter::isCloseToExpectedSpeed);
log("SUIIII");

new IntakeIn().run(context);
context.runSync(new IntakeIn());
context.waitForSeconds(1.5);

new IntakeStop().run(context);
context.runSync(new IntakeStop());
Robot.shooter.shoot(0);
}
}

0 comments on commit e62c5f2

Please sign in to comment.