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

Add runSync to Context for symmetry with startAsync #82

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/com/team766/framework/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public interface Context {
*/
LaunchedContext startAsync(final Runnable func);

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

/**
* Take ownership of the given Mechanism with this Context.
*
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/team766/framework/ContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ public LaunchedContext startAsync(final Runnable func) {
return new ContextImpl<>(func, this);
}

@Override
public void runSync(final RunnableWithContext func) {
func.run(this);
}

/**
* Interrupt the running of this Context and force it to terminate.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public final void run(Context context) {
: initialPosition.getRotation())
.getDegrees());
for (RunnableWithContext pathItem : pathItems) {
pathItem.run(context);
context.runSync(pathItem);
context.yield();
}

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 @@ -65,20 +65,20 @@ public void run(Context context) {
driverOI.handleOI(context);

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());
}

// Respond to boxop commands

// 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 @@ -103,11 +103,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 @@ -109,7 +109,7 @@ public void run(Context context) {
context.waitForConditionOrTimeout(() -> Robot.shoulder.isFinished(), 1);

Robot.lights.signalFinishingShootingProcedure();
new DriverShootVelocityAndIntake().run(context);
context.runSync(new DriverShootVelocityAndIntake());
}

private Transform3d getTransform3dOfRobotToTag() throws AprilTagGeneralCheckedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void run(Context context) {

context.waitForConditionOrTimeout(Robot.shooter::isCloseToExpectedSpeed, 1);

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

// Does not stop intake here so driver can stop when button released
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void run(Context context) {

context.releaseOwnership(Robot.shooter);
context.releaseOwnership(Robot.shoulder);
new ShootVelocityAndIntake(power).run(context);
context.runSync(new ShootVelocityAndIntake(power));

} else {
// context.takeOwnership(Robot.shooter);
Expand All @@ -64,7 +64,7 @@ public void run(Context context) {
// context.releaseOwnership(Robot.shoulder);
// context.releaseOwnership(Robot.shooter);

new ShootVelocityAndIntake(3000).run(context);
context.runSync(new ShootVelocityAndIntake(3000));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public void run(Context context) {
// context.releaseOwnership(Robot.shoulder);
context.releaseOwnership(Robot.drive);
context.releaseOwnership(Robot.shooter);
new ShootVelocityAndIntake().run(context);
context.runSync(new ShootVelocityAndIntake());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public void run(Context context) {
context.takeOwnership(Robot.shoulder);
Robot.shoulder.rotate(ShoulderPosition.SHOOT_LOW);
context.releaseOwnership(Robot.shoulder);
new ShootVelocityAndIntake().run(context);
context.runSync(new ShootVelocityAndIntake());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void run(Context context) {

context.releaseOwnership(Robot.shooter);
Robot.lights.signalFinishingShootingProcedure();
new ShootVelocityAndIntake(power).run(context);
context.runSync(new ShootVelocityAndIntake(power));
context.releaseOwnership(Robot.drive);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public void run(Context context) {
Robot.shooter.shoot(speed);
context.waitForConditionOrTimeout(Robot.shooter::isCloseToExpectedSpeed, 1.5);

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

// FIXME: change this value back to 1.5s if doesn't intake for long enough
context.waitForSeconds(1.2);

new IntakeStop().run(context);
context.runSync(new IntakeStop());
Robot.lights.signalFinishedShootingProcedure();

// Shooter stopped at the end of auton
Expand Down
Loading