|
14 | 14 | import edu.wpi.first.math.geometry.Translation3d; |
15 | 15 | import edu.wpi.first.math.kinematics.ChassisSpeeds; |
16 | 16 | import edu.wpi.first.math.numbers.N3; |
| 17 | +import edu.wpi.first.wpilibj.DriverStation; |
17 | 18 | import frc.robot.DependencyOrderedExecutor.ActionKey; |
18 | 19 | import frc.robot.ShotCalculations.MapBasedShotInfo; |
19 | 20 | import frc.robot.ShotCalculations.ShotInfo; |
20 | 21 | import frc.robot.ShotCalculations.ShotTarget; |
21 | 22 | import frc.robot.constants.FieldConstants; |
22 | 23 | import frc.robot.constants.JsonConstants; |
| 24 | +import frc.robot.coordination.MatchState; |
23 | 25 | import frc.robot.subsystems.HomingSwitch; |
24 | 26 | import frc.robot.subsystems.drive.Drive; |
25 | 27 | import frc.robot.subsystems.drive.DriveCoordinator; |
|
30 | 32 | import frc.robot.subsystems.shooter.ShooterSubsystem; |
31 | 33 | import frc.robot.subsystems.turret.TurretSubsystem; |
32 | 34 | import java.util.Optional; |
| 35 | +import org.littletonrobotics.junction.Logger; |
33 | 36 |
|
34 | 37 | /** |
35 | 38 | * The coordination layer is responsible for updating subsystem dependencies, running the shot |
@@ -61,14 +64,25 @@ public class CoordinationLayer { |
61 | 64 | new ActionKey("CoordinationLayer::runShotCalculator"); |
62 | 65 | public static final ActionKey RUN_DEMO_MODES = |
63 | 66 | new ActionKey("CoordinationLayer::runSubsystemDemoModes"); |
| 67 | + public static final ActionKey UPDATE_MATCH_STATE = |
| 68 | + new ActionKey("CoordinationLayer::updateMatchState"); |
64 | 69 |
|
65 | 70 | // State variables (these will be updated by various methods and then their values will be passed |
66 | 71 | // to subsystems during the execution of a cycle) |
| 72 | + private final MatchState matchState = new MatchState(); |
| 73 | + // Manual override requests set by controller bindings. These are cleared once consumed in |
| 74 | + // updateMatchState and forwarded to MatchState.enabledPeriodic as booleans. |
| 75 | + private boolean manualRedOverrideRequest = false; |
| 76 | + private boolean manualBlueOverrideRequest = false; |
| 77 | + |
67 | 78 | public CoordinationLayer(DependencyOrderedExecutor dependencyOrderedExecutor) { |
68 | 79 | this.dependencyOrderedExecutor = dependencyOrderedExecutor; |
69 | 80 |
|
| 81 | + dependencyOrderedExecutor.registerAction(UPDATE_MATCH_STATE, this::updateMatchState); |
70 | 82 | dependencyOrderedExecutor.registerAction(RUN_SHOT_CALCULATOR, this::runShotCalculator); |
71 | 83 | dependencyOrderedExecutor.registerAction(RUN_DEMO_MODES, this::runSubsystemDemoModes); |
| 84 | + |
| 85 | + dependencyOrderedExecutor.addDependencies(RUN_SHOT_CALCULATOR, UPDATE_MATCH_STATE); |
72 | 86 | } |
73 | 87 |
|
74 | 88 | /** |
@@ -211,6 +225,9 @@ private void updateIntakeDependencies(IntakeSubsystem intake) { |
211 | 225 | } |
212 | 226 |
|
213 | 227 | // Coordination and processing |
| 228 | + /** Coordinates subsystem actions based on the desired action and subsystem inputs */ |
| 229 | + public void coordinateSubsystemActions() {} |
| 230 | + |
214 | 231 | /** |
215 | 232 | * Runs the shot calculator and logs the resulting trajectories for debugging. Eventually, this |
216 | 233 | * method should also command the subsystems to take their actinos. |
@@ -331,6 +348,35 @@ private void runSubsystemDemoModes() { |
331 | 348 | } |
332 | 349 | } |
333 | 350 |
|
| 351 | + /** Update the MatchState each periodic loop */ |
| 352 | + private void updateMatchState() { |
| 353 | + if (DriverStation.isEnabled()) { |
| 354 | + matchState.enabledPeriodic(manualRedOverrideRequest, manualBlueOverrideRequest); |
| 355 | + } |
| 356 | + |
| 357 | + // This is temporary code left here to make it easy to integrate the time left functionality |
| 358 | + // with LEDs and superstructure coordination later. |
| 359 | + double timeLeft = matchState.getTimeLeftInCurrentShift(); |
| 360 | + |
| 361 | + boolean hasFiveSecondsLeft = timeLeft >= 5.0; |
| 362 | + Logger.recordOutput("MatchState/has5sLeft", hasFiveSecondsLeft); |
| 363 | + } |
| 364 | + |
| 365 | + /** |
| 366 | + * Called by a controller binding or DOE action to request that the match state be overridden to |
| 367 | + * red for the next enabledPeriodic call. This sets a one-shot request which is consumed by |
| 368 | + * updateMatchState. |
| 369 | + */ |
| 370 | + public void overrideMatchStateRed() { |
| 371 | + manualRedOverrideRequest = true; |
| 372 | + manualBlueOverrideRequest = false; |
| 373 | + } |
| 374 | + |
| 375 | + public void overrideMatchStateBlue() { |
| 376 | + manualBlueOverrideRequest = true; |
| 377 | + manualRedOverrideRequest = false; |
| 378 | + } |
| 379 | + |
334 | 380 | /** |
335 | 381 | * Given an "ideal" shot, command the scoring subsystems to target it |
336 | 382 | * |
|
0 commit comments