diff --git a/build.gradle b/build.gradle index 8fb8e9913..ef86669c8 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { id 'java-library' id 'maven-publish' id "edu.wpi.first.GradleRIO" version "2024.3.2" - id 'com.diffplug.spotless' version "7.0.0.BETA2" + id 'com.diffplug.spotless' version '6.22.0' id 'com.google.protobuf' version '0.8.19' } @@ -244,7 +244,7 @@ spotless { } toggleOffOn() googleJavaFormat().formatJavadoc(false).aosp() - // removeUnusedImports() // https://github.com/diffplug/spotless/issues/2159 + removeUnusedImports() trimTrailingWhitespace() endWithNewline() } diff --git a/src/main/java/com/team766/framework3/Context.java b/src/main/java/com/team766/framework3/Context.java index c2bdcdcfc..f09366775 100644 --- a/src/main/java/com/team766/framework3/Context.java +++ b/src/main/java/com/team766/framework3/Context.java @@ -89,23 +89,23 @@ public interface Context { * calling Procedure. * In most cases, you want to use runParallel instead of startAsync. */ - LaunchedContext startAsync(final RunnableWithContext func); + LaunchedContext startAsync(final Procedure func); /** * Run the given Procedure synchronously (the calling Procedure will not resume until this one * has finished). */ - void runSync(final RunnableWithContext func); + void runSync(final Procedure func); /** * Run the given Procedures at the same time. The calling Procedure will resume after all * Procedures in the group finish. */ - void runParallel(RunnableWithContext... procedures); + void runParallel(Procedure... procedures); /** * Run the given Procedures at the same time. The calling Procedure will resume once any * Procedure in the group finishes, and the others will be cancelled. */ - void runParallelRace(RunnableWithContext... procedures); + void runParallelRace(Procedure... procedures); } diff --git a/src/main/java/com/team766/framework3/ContextImpl.java b/src/main/java/com/team766/framework3/ContextImpl.java index bd9127a0c..d0963ea90 100644 --- a/src/main/java/com/team766/framework3/ContextImpl.java +++ b/src/main/java/com/team766/framework3/ContextImpl.java @@ -105,7 +105,7 @@ public boolean succeeded() { /** * The top-level procedure being run by this Context. */ - private final RunnableWithContext m_func; + private final Procedure m_func; /** * The OS thread that this Context is executing on. @@ -149,7 +149,7 @@ public boolean succeeded() { * {@link Scheduler#startAsync}. */ - ContextImpl(final RunnableWithContext func) { + ContextImpl(final Procedure func) { m_func = func; Logger.get(Category.FRAMEWORK) .logRaw( @@ -170,10 +170,6 @@ public String getContextName() { return "Context/" + Integer.toHexString(hashCode()) + "/" + m_func.toString(); } - /* package */ RunnableWithContext getRunnable() { - return m_func; - } - @Override public String toString() { String repr = getContextName(); @@ -349,7 +345,7 @@ public void yield() { } @Override - public LaunchedContext startAsync(final RunnableWithContext func) { + public LaunchedContext startAsync(final Procedure func) { checkProcedureReservationsDisjoint(func); var context = new ContextImpl(func); context.schedule(); @@ -357,13 +353,13 @@ public LaunchedContext startAsync(final RunnableWithContext func) { } @Override - public void runSync(final RunnableWithContext func) { + public void runSync(final Procedure func) { checkProcedureReservationsSubset(func); func.run(this); } @Override - public void runParallel(RunnableWithContext... procedures) { + public void runParallel(Procedure... procedures) { var contexts = new ContextImpl[procedures.length]; for (int i = 0; i < contexts.length; ++i) { var procedure = procedures[i]; @@ -375,7 +371,7 @@ public void runParallel(RunnableWithContext... procedures) { } @Override - public void runParallelRace(RunnableWithContext... procedures) { + public void runParallelRace(Procedure... procedures) { var contexts = new ContextImpl[procedures.length]; for (int i = 0; i < contexts.length; ++i) { var procedure = procedures[i]; @@ -386,28 +382,28 @@ public void runParallelRace(RunnableWithContext... procedures) { runSync(new WPILibCommandProcedure(Commands.race(contexts))); } - private void checkProcedureReservationsSubset(RunnableWithContext procedure) { + private void checkProcedureReservationsSubset(Procedure procedure) { final var this_reservations = getRequirements(); for (var req : procedure.reservations()) { if (!this_reservations.contains(req)) { throw new IllegalArgumentException( getName() + " tried to run " - + procedure.toString() + + procedure.getName() + " but is missing the reservation on " + req.getName()); } } } - private void checkProcedureReservationsDisjoint(RunnableWithContext procedure) { + private void checkProcedureReservationsDisjoint(Procedure procedure) { final var this_reservations = getRequirements(); for (var req : procedure.reservations()) { if (this_reservations.contains(req)) { throw new IllegalArgumentException( getName() + " tried to launch " - + procedure.toString() + + procedure.getName() + " asynchronously, but both have a reservation on " + req.getName()); } diff --git a/src/main/java/com/team766/framework3/FunctionalProcedure.java b/src/main/java/com/team766/framework3/FunctionalProcedure.java new file mode 100644 index 000000000..7a93fd0f7 --- /dev/null +++ b/src/main/java/com/team766/framework3/FunctionalProcedure.java @@ -0,0 +1,22 @@ +package com.team766.framework3; + +import edu.wpi.first.wpilibj2.command.Subsystem; +import java.util.Set; +import java.util.function.Consumer; + +public final class FunctionalProcedure extends Procedure { + private final Consumer runnable; + + public FunctionalProcedure(Set reservations, Consumer runnable) { + super(runnable.toString()); + this.runnable = runnable; + for (var r : reservations) { + reserve(r); + } + } + + @Override + public void run(Context context) { + runnable.accept(context); + } +} diff --git a/src/main/java/com/team766/framework3/FunctionalRunnableWithContext.java b/src/main/java/com/team766/framework3/FunctionalRunnableWithContext.java deleted file mode 100644 index 5c96019af..000000000 --- a/src/main/java/com/team766/framework3/FunctionalRunnableWithContext.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.team766.framework3; - -import edu.wpi.first.wpilibj2.command.Subsystem; -import java.util.Set; -import java.util.function.Consumer; - -public final class FunctionalRunnableWithContext implements RunnableWithContext { - private final Consumer runnable; - private final Set reservations; - - public FunctionalRunnableWithContext(Set reservations, Consumer runnable) { - this.runnable = runnable; - this.reservations = reservations; - } - - @Override - public void run(Context context) { - runnable.accept(context); - } - - @Override - public Set reservations() { - return reservations; - } - - @Override - public String toString() { - return runnable.toString(); - } -} diff --git a/src/main/java/com/team766/framework3/InstantCommand.java b/src/main/java/com/team766/framework3/InstantCommand.java index d6d8e859a..60c40bf99 100644 --- a/src/main/java/com/team766/framework3/InstantCommand.java +++ b/src/main/java/com/team766/framework3/InstantCommand.java @@ -7,8 +7,8 @@ public class InstantCommand extends Command { private final Runnable runnable; - public InstantCommand(InstantRunnable runnable) { - this(runnable.reservations(), runnable); + public InstantCommand(InstantProcedure procedure) { + this(procedure.reservations(), procedure); } public InstantCommand(Set requirements, Runnable runnable) { diff --git a/src/main/java/com/team766/framework3/InstantProcedure.java b/src/main/java/com/team766/framework3/InstantProcedure.java index 20a1bbb78..a7445763e 100644 --- a/src/main/java/com/team766/framework3/InstantProcedure.java +++ b/src/main/java/com/team766/framework3/InstantProcedure.java @@ -1,6 +1,9 @@ package com.team766.framework3; -public abstract non-sealed class InstantProcedure extends ProcedureBase implements InstantRunnable { +public abstract class InstantProcedure extends Procedure implements Runnable { + @Override + public abstract void run(); + @Override public final void run(Context context) { run(); diff --git a/src/main/java/com/team766/framework3/InstantRunnable.java b/src/main/java/com/team766/framework3/InstantRunnable.java deleted file mode 100644 index 1f49c44f3..000000000 --- a/src/main/java/com/team766/framework3/InstantRunnable.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.team766.framework3; - -import edu.wpi.first.wpilibj2.command.Subsystem; -import java.util.Set; - -// This interface is sealed because implementors must implement run(Context) like this: -// @Override -// public final void run(Context context) { -// run(); -// } -public sealed interface InstantRunnable extends Runnable, RunnableWithContext - permits InstantProcedure { - @Override - void run(); - - @Override - Set reservations(); -} diff --git a/src/main/java/com/team766/framework3/Procedure.java b/src/main/java/com/team766/framework3/Procedure.java index e226b552f..832faa663 100644 --- a/src/main/java/com/team766/framework3/Procedure.java +++ b/src/main/java/com/team766/framework3/Procedure.java @@ -1,3 +1,60 @@ package com.team766.framework3; -public abstract class Procedure extends ProcedureBase implements RunnableWithContext {} +import com.google.common.collect.Sets; +import com.team766.logging.Category; +import edu.wpi.first.wpilibj2.command.Subsystem; +import java.util.Set; + +public abstract class Procedure implements LoggingBase { + // A reusable Procedure that does nothing. + private static final class NoOpProcedure extends InstantProcedure { + @Override + public void run() {} + } + + public static final InstantProcedure NO_OP = new NoOpProcedure(); + + private static int c_idCounter = 0; + + private static synchronized int createNewId() { + return c_idCounter++; + } + + private final String name; + private final Set reservations = Sets.newHashSet(); + protected Category loggerCategory = Category.PROCEDURES; + + protected Procedure() { + this.name = this.getClass().getName() + "/" + createNewId(); + } + + protected Procedure(String name) { + this.name = name; + } + + public abstract void run(Context context); + + @Override + public final String getName() { + return name; + } + + @Override + public Category getLoggerCategory() { + return loggerCategory; + } + + protected final M reserve(M m) { + reservations.add(m); + return m; + } + + public final Set reservations() { + return reservations; + } + + @Override + public final String toString() { + return getName(); + } +} diff --git a/src/main/java/com/team766/framework3/ProcedureBase.java b/src/main/java/com/team766/framework3/ProcedureBase.java deleted file mode 100644 index 1f34e8a5d..000000000 --- a/src/main/java/com/team766/framework3/ProcedureBase.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.team766.framework3; - -import com.google.common.collect.Sets; -import com.team766.logging.Category; -import edu.wpi.first.wpilibj2.command.Subsystem; -import java.util.Set; - -/* package */ class ProcedureBase implements LoggingBase { - // A reusable Procedure that does nothing. - private static final class NoOpProcedure extends InstantProcedure { - @Override - public void run() {} - } - - public static final InstantRunnable NO_OP = new NoOpProcedure(); - - private static int c_idCounter = 0; - - private static synchronized int createNewId() { - return c_idCounter++; - } - - private final String name; - private final Set reservations = Sets.newHashSet(); - protected Category loggerCategory = Category.PROCEDURES; - - protected ProcedureBase() { - this.name = this.getClass().getName() + "/" + createNewId(); - } - - @Override - public String getName() { - return name; - } - - @Override - public Category getLoggerCategory() { - return loggerCategory; - } - - protected M reserve(M m) { - reservations.add(m); - return m; - } - - public Set reservations() { - return reservations; - } - - @Override - public String toString() { - return getName(); - } -} diff --git a/src/main/java/com/team766/framework3/Rule.java b/src/main/java/com/team766/framework3/Rule.java index 4a2818b2f..bd0d56123 100644 --- a/src/main/java/com/team766/framework3/Rule.java +++ b/src/main/java/com/team766/framework3/Rule.java @@ -14,7 +14,7 @@ * in an OperatorInterface loop or Display (LED lights, etc) loop. The Rule keeps track of * when the predicate starts triggering, continues triggering, and has finished triggering, via * a {@link TriggerType}, eg when a driver or boxop starts pressing a button, continues holding down - * the button, and releases the button. Each Rule has optional {@link RunnableWithContext} actions + * the button, and releases the button. Each Rule has optional {@link Procedure} actions * for each of these trigger types, which the {@link RuleEngine} will consider running, after checking * if higher priority rules have reserved the same {@link Mechanism}s that the candidate rule would use. * @@ -26,7 +26,7 @@ * public MyRules() { * // add rule to spin up the shooter when the boxop presses the right trigger on the gamepad * rules.add(Rule.create("spin up shooter", gamepad.getButton(InputConstants.XBOX_RT)). - * withNewlyTriggeringRunnable(() -> new ShooterSpin(shooter))); + * withNewlyTriggeringProcedure(() -> new ShooterSpin(shooter))); * ... * } * } @@ -43,28 +43,28 @@ private interface CommandCreator { } /** - * Functional interface for creating new {@link RunnableWithContext}s. + * Functional interface for creating new {@link Procedure}s. */ @FunctionalInterface - public interface RunnableWithContextCreator extends CommandCreator { - RunnableWithContext createRunnable(); + public interface ProcedureCreator extends CommandCreator { + Procedure createProcedure(); @Override default Command createCommand() { - return new ContextImpl(createRunnable()); + return new ContextImpl(createProcedure()); } } /** - * Functional interface for creating new {@link InstantRunnable}s. + * Functional interface for creating new {@link InstantProcedure}s. */ @FunctionalInterface - public interface InstantRunnableCreator extends CommandCreator { - InstantRunnable createRunnable(); + public interface InstantProcedureCreator extends CommandCreator { + InstantProcedure createProcedure(); @Override default Command createCommand() { - return new InstantCommand(createRunnable()); + return new InstantCommand(createProcedure()); } } @@ -93,9 +93,9 @@ enum TriggerType { public static class Builder { private final String name; private final BooleanSupplier predicate; - private CommandCreator newlyTriggeringRunnable; - private CommandCreator continuingTriggeringRunnable; - private CommandCreator finishedTriggeringRunnable; + private CommandCreator newlyTriggeringProcedure; + private CommandCreator continuingTriggeringProcedure; + private CommandCreator finishedTriggeringProcedure; private Builder(String name, BooleanSupplier predicate) { this.name = name; @@ -103,52 +103,52 @@ private Builder(String name, BooleanSupplier predicate) { } /** Specify a creator for the Command that should be run when this rule starts triggering. */ - public Builder withNewlyTriggeringRunnable(RunnableWithContextCreator action) { - this.newlyTriggeringRunnable = action; + public Builder withNewlyTriggeringProcedure(ProcedureCreator action) { + this.newlyTriggeringProcedure = action; return this; } - public Builder withNewlyTriggeringRunnable(InstantRunnableCreator action) { - this.newlyTriggeringRunnable = action; + public Builder withNewlyTriggeringProcedure(InstantProcedureCreator action) { + this.newlyTriggeringProcedure = action; return this; } - public Builder withNewlyTriggeringRunnable(Set reservations, Runnable action) { - this.newlyTriggeringRunnable = () -> new InstantCommand(reservations, action); + public Builder withNewlyTriggeringProcedure(Set reservations, Runnable action) { + this.newlyTriggeringProcedure = () -> new InstantCommand(reservations, action); return this; } /** Specify a creator for the Command that should be run when this rule was triggering before and is continuing to trigger. */ - public Builder withContinuingTriggeringRunnable(RunnableWithContextCreator action) { - this.continuingTriggeringRunnable = action; + public Builder withContinuingTriggeringProcedure(ProcedureCreator action) { + this.continuingTriggeringProcedure = action; return this; } - public Builder withContinuingTriggeringRunnable(InstantRunnableCreator action) { - this.continuingTriggeringRunnable = action; + public Builder withContinuingTriggeringProcedure(InstantProcedureCreator action) { + this.continuingTriggeringProcedure = action; return this; } - public Builder withContinuingTriggeringRunnable( + public Builder withContinuingTriggeringProcedure( Set reservations, Runnable action) { - this.continuingTriggeringRunnable = () -> new InstantCommand(reservations, action); + this.continuingTriggeringProcedure = () -> new InstantCommand(reservations, action); return this; } /** Specify a creator for the Command that should be run when this rule was triggering before and is no longer triggering. */ - public Builder withFinishedTriggeringRunnable(RunnableWithContextCreator action) { - this.finishedTriggeringRunnable = action; + public Builder withFinishedTriggeringProcedure(ProcedureCreator action) { + this.finishedTriggeringProcedure = action; return this; } - public Builder withFinishedTriggeringRunnable(InstantRunnableCreator action) { - this.finishedTriggeringRunnable = action; + public Builder withFinishedTriggeringProcedure(InstantProcedureCreator action) { + this.finishedTriggeringProcedure = action; return this; } - public Builder withFinishedTriggeringRunnable( + public Builder withFinishedTriggeringProcedure( Set reservations, Runnable action) { - this.finishedTriggeringRunnable = () -> new InstantCommand(reservations, action); + this.finishedTriggeringProcedure = () -> new InstantCommand(reservations, action); return this; } @@ -157,15 +157,15 @@ public Builder withFinishedTriggeringRunnable( return new Rule( name, predicate, - newlyTriggeringRunnable, - continuingTriggeringRunnable, - finishedTriggeringRunnable); + newlyTriggeringProcedure, + continuingTriggeringProcedure, + finishedTriggeringProcedure); } } private final String name; private final BooleanSupplier predicate; - private final Map triggerRunnables = + private final Map triggerProcedures = Maps.newEnumMap(TriggerType.class); private final Map> triggerReservations = Maps.newEnumMap(TriggerType.class); @@ -179,44 +179,44 @@ public static Builder create(String name, BooleanSupplier predicate) { private Rule( String name, BooleanSupplier predicate, - CommandCreator newlyTriggeringRunnable, - CommandCreator continuingTriggeringRunnable, - CommandCreator finishedTriggeringRunnable) { + CommandCreator newlyTriggeringProcedure, + CommandCreator continuingTriggeringProcedure, + CommandCreator finishedTriggeringProcedure) { if (predicate == null) { throw new IllegalArgumentException("Rule predicate has not been set."); } - if (newlyTriggeringRunnable == null) { + if (newlyTriggeringProcedure == null) { throw new IllegalArgumentException("Newly triggering rule is not defined."); } this.name = name; this.predicate = predicate; - if (newlyTriggeringRunnable != null) { - triggerRunnables.put(TriggerType.NEWLY, newlyTriggeringRunnable); + if (newlyTriggeringProcedure != null) { + triggerProcedures.put(TriggerType.NEWLY, newlyTriggeringProcedure); triggerReservations.put( - TriggerType.NEWLY, getReservationsForRunnable(finishedTriggeringRunnable)); + TriggerType.NEWLY, getReservationsForProcedure(finishedTriggeringProcedure)); } - if (continuingTriggeringRunnable != null) { - triggerRunnables.put(TriggerType.CONTINUING, continuingTriggeringRunnable); + if (continuingTriggeringProcedure != null) { + triggerProcedures.put(TriggerType.CONTINUING, continuingTriggeringProcedure); triggerReservations.put( TriggerType.CONTINUING, - getReservationsForRunnable(continuingTriggeringRunnable)); + getReservationsForProcedure(continuingTriggeringProcedure)); } - if (finishedTriggeringRunnable != null) { - triggerRunnables.put(TriggerType.FINISHED, finishedTriggeringRunnable); + if (finishedTriggeringProcedure != null) { + triggerProcedures.put(TriggerType.FINISHED, finishedTriggeringProcedure); triggerReservations.put( - TriggerType.FINISHED, getReservationsForRunnable(finishedTriggeringRunnable)); + TriggerType.FINISHED, getReservationsForProcedure(finishedTriggeringProcedure)); } } - private Set getReservationsForRunnable(CommandCreator creator) { + private Set getReservationsForProcedure(CommandCreator creator) { if (creator != null) { - Command runnable = creator.createCommand(); - if (runnable != null) { - return runnable.getRequirements(); + Command command = creator.createCommand(); + if (command != null) { + return command.getRequirements(); } } return Collections.emptySet(); @@ -257,10 +257,10 @@ public String getName() { return Collections.emptySet(); } - /* package */ Command getRunnableToRun() { + /* package */ Command getProcedureToRun() { if (currentTriggerType != TriggerType.NONE) { - if (triggerRunnables.containsKey(currentTriggerType)) { - CommandCreator creator = triggerRunnables.get(currentTriggerType); + if (triggerProcedures.containsKey(currentTriggerType)) { + CommandCreator creator = triggerProcedures.get(currentTriggerType); if (creator != null) { return creator.createCommand(); } diff --git a/src/main/java/com/team766/framework3/RuleEngine.java b/src/main/java/com/team766/framework3/RuleEngine.java index 7f553a36e..e08762a1a 100644 --- a/src/main/java/com/team766/framework3/RuleEngine.java +++ b/src/main/java/com/team766/framework3/RuleEngine.java @@ -38,8 +38,8 @@ protected void addRule(Rule.Builder builder) { rulePriorities.put(rule, priority); } - protected Rule getRuleForTriggeredRunnable(Command runnable) { - RuleAction ruleAction = ruleMap.get(runnable); + protected Rule getRuleForTriggeredProcedure(Command command) { + RuleAction ruleAction = ruleMap.get(command); return (ruleAction == null) ? null : ruleAction.rule; } @@ -61,11 +61,11 @@ public final void run() { int priority = rulePriorities.get(rule); - // see if there are mechanisms a potential runnable would want to reserve + // see if there are mechanisms a potential procedure would want to reserve Set reservations = rule.getMechanismsToReserve(); for (Subsystem mechanism : reservations) { // see if any of the mechanisms higher priority rules will use would also be - // used by this lower priority rule's runnable. + // used by this lower priority rule's procedure. if (mechanismsToUse.contains(mechanism)) { log( "RULE CONFLICT! Ignoring rule: " @@ -76,11 +76,11 @@ public final void run() { continue; } // see if a previously triggered rule is still using the mechanism - Command existingRunnable = + Command existingProcedure = CommandScheduler.getInstance().requiring(mechanism); - if (existingRunnable != null) { + if (existingProcedure != null) { // look up the rule - Rule existingRule = getRuleForTriggeredRunnable(existingRunnable); + Rule existingRule = getRuleForTriggeredProcedure(existingProcedure); if (existingRule != null) { // look up the priority int existingPriority = rulePriorities.get(existingRule); @@ -100,13 +100,13 @@ public final void run() { } // we're good to proceed - Command runnable = rule.getRunnableToRun(); - if (runnable == null) { + Command command = rule.getProcedureToRun(); + if (command == null) { continue; } mechanismsToUse.addAll(reservations); - ruleMap.put(runnable, new RuleAction(rule, triggerType)); - runnable.schedule(); + ruleMap.put(command, new RuleAction(rule, triggerType)); + command.schedule(); } } catch (Exception ex) { log(Severity.ERROR, LoggerExceptionUtils.exceptionToString(ex)); diff --git a/src/main/java/com/team766/framework3/RunnableWithContext.java b/src/main/java/com/team766/framework3/RunnableWithContext.java deleted file mode 100644 index 132e197eb..000000000 --- a/src/main/java/com/team766/framework3/RunnableWithContext.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.team766.framework3; - -import edu.wpi.first.wpilibj2.command.Subsystem; -import java.util.Set; - -public interface RunnableWithContext { - void run(Context context); - - Set reservations(); -} diff --git a/src/main/java/com/team766/framework3/WPILibCommandProcedure.java b/src/main/java/com/team766/framework3/WPILibCommandProcedure.java index 35f083e97..056128883 100644 --- a/src/main/java/com/team766/framework3/WPILibCommandProcedure.java +++ b/src/main/java/com/team766/framework3/WPILibCommandProcedure.java @@ -1,14 +1,12 @@ package com.team766.framework3; import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.Subsystem; -import java.util.Set; /** * This wraps a class that confroms to WPILib's Command interface, and allows * it to be used in the Maroon Framework as a Procedure. */ -public final class WPILibCommandProcedure implements RunnableWithContext { +public final class WPILibCommandProcedure extends Procedure { private final Command command; @@ -17,6 +15,9 @@ public final class WPILibCommandProcedure implements RunnableWithContext { */ public WPILibCommandProcedure(final Command command_) { this.command = command_; + for (var r : this.command.getRequirements()) { + reserve(r); + } } @Override @@ -38,9 +39,4 @@ public void run(final Context context) { this.command.end(interrupted); } } - - @Override - public Set reservations() { - return this.command.getRequirements(); - } } diff --git a/src/main/java/com/team766/robot/gatorade/OI.java b/src/main/java/com/team766/robot/gatorade/OI.java index 8bbb13bc4..a5cfe28c8 100644 --- a/src/main/java/com/team766/robot/gatorade/OI.java +++ b/src/main/java/com/team766/robot/gatorade/OI.java @@ -197,18 +197,18 @@ public void run(Context context) { private void setLightsForPlacement() { switch (placementPosition) { - // case NONE: - // Robot.lights.white(); - // break; - // case LOW_NODE: - // Robot.lights.green(); - // break; - // case MID_NODE: - // Robot.lights.red(); - // break; - // case HIGH_NODE: - // Robot.lights.orange(); - // break; + // case NONE: + // Robot.lights.white(); + // break; + // case LOW_NODE: + // Robot.lights.green(); + // break; + // case MID_NODE: + // Robot.lights.red(); + // break; + // case HIGH_NODE: + // Robot.lights.orange(); + // break; case HUMAN_PLAYER: setLightsForGamePiece(); break; diff --git a/src/test/java/com/team766/framework3/Context3Test.java b/src/test/java/com/team766/framework3/Context3Test.java index 730aa1b53..4faa05af4 100644 --- a/src/test/java/com/team766/framework3/Context3Test.java +++ b/src/test/java/com/team766/framework3/Context3Test.java @@ -104,7 +104,7 @@ public void testRunSync() { var proc2 = new FakeProcedure(1, Set.of(mech1, mech2)); var proc = - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(mech1, mech2), context -> { context.runSync(proc1); @@ -154,7 +154,7 @@ public void testRunParallel() { var proc2 = new FakeProcedure(2, Set.of(mech2)); var proc = - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(mech1, mech2), context -> { context.runParallel(proc1, proc2); @@ -203,7 +203,7 @@ public void testRunParallelRace() { var proc2 = new FakeProcedure(3, Set.of(mech2)); var proc = - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(mech1, mech2), context -> { context.runParallelRace(proc1, proc2); @@ -239,13 +239,13 @@ public void testRunParallelRace() { /// is not reserved by the parent Procedure. Should raise an exception. @ParameterizedTest @MethodSource("paramsRunWithMissingReservation") - public void testRunWithMissingReservation(BiConsumer runMethod) { + public void testRunWithMissingReservation(BiConsumer runMethod) { var mech = new FakeMechanism(); var proc1 = new FakeProcedure(1, Set.of(mech)); AtomicReference thrownException = new AtomicReference<>(null); var proc = - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(), context -> { try { @@ -264,7 +264,7 @@ public void testRunWithMissingReservation(BiConsumer> paramsRunWithMissingReservation() { + static Stream> paramsRunWithMissingReservation() { return Stream.of(Context::runSync, Context::runParallel, Context::runParallelRace); } @@ -272,19 +272,18 @@ static Stream> paramsRunWithMissingRese /// Should raise an exception. @ParameterizedTest @MethodSource("paramsRunWithConflictingReservation") - public void testRunWithConflictingReservation( - BiConsumer runMethod) { + public void testRunWithConflictingReservation(BiConsumer runMethod) { var mech = new FakeMechanism(); var proc1 = new FakeProcedure(1, Set.of(mech)); var proc2 = new FakeProcedure(1, Set.of(mech)); AtomicReference thrownException = new AtomicReference<>(null); var proc = - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(mech), context -> { try { - runMethod.accept(context, new RunnableWithContext[] {proc1, proc2}); + runMethod.accept(context, new Procedure[] {proc1, proc2}); } catch (IllegalArgumentException ex) { thrownException.set(ex.getMessage()); } @@ -299,8 +298,7 @@ public void testRunWithConflictingReservation( "Multiple commands in a parallel composition cannot require the same subsystems"); } - static Stream> - paramsRunWithConflictingReservation() { + static Stream> paramsRunWithConflictingReservation() { return Stream.of(Context::runParallel, Context::runParallelRace); } @@ -312,7 +310,7 @@ public void testStartAsync() { var proc1age = new AtomicInteger(0); var proc1 = - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(), context -> { var lc = context.startAsync(proc2); @@ -368,7 +366,7 @@ public void testStartAsyncWithConflictingReservation() { AtomicReference thrownException = new AtomicReference<>(null); var proc1 = - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(mech), context -> { try { diff --git a/src/test/java/com/team766/framework3/FakeMechanism.java b/src/test/java/com/team766/framework3/FakeMechanism.java index 53ed2f960..b69694a4c 100644 --- a/src/test/java/com/team766/framework3/FakeMechanism.java +++ b/src/test/java/com/team766/framework3/FakeMechanism.java @@ -1,6 +1,8 @@ package com.team766.framework3; class FakeMechanism extends Mechanism { + record FakeStatus(int currentState) implements Status {} + public record FakeRequest(int targetState) implements Request { @Override public boolean isDone(FakeStatus status) { diff --git a/src/test/java/com/team766/framework3/FakeStatus.java b/src/test/java/com/team766/framework3/FakeStatus.java deleted file mode 100644 index e0a8d9151..000000000 --- a/src/test/java/com/team766/framework3/FakeStatus.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.team766.framework3; - -record FakeStatus(int currentState) implements Status {} diff --git a/src/test/java/com/team766/framework3/MechanismTest.java b/src/test/java/com/team766/framework3/MechanismTest.java index cb7251dd0..f8cc411a5 100644 --- a/src/test/java/com/team766/framework3/MechanismTest.java +++ b/src/test/java/com/team766/framework3/MechanismTest.java @@ -28,7 +28,7 @@ protected void run(FakeRequest request, boolean isRequestNew) { var cmd = new ContextImpl( - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(mech), context -> { // Step 1 @@ -89,7 +89,7 @@ protected void run(FakeRequest request, boolean isRequestNew) {} var thrownException = new AtomicReference(null); var cmd = new ContextImpl( - new FunctionalRunnableWithContext( + new FunctionalProcedure( Set.of(), context -> { try {