From 3e2b96dbe22e37fda259cb725b8c47adc344881a Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 27 Jan 2024 14:17:07 -0800 Subject: [PATCH 1/2] Test code for the Features code in lib2813 Features can be initally disabled or disabled, and can be configured to be enabled via Shuffleboard. Commands can be configured to be scheduled only if all controlling features are enabled by using Features.whenAllEnabled(). This allows us to add functionality to the robot that might not be fully tested by having the functionality disabled by default. --- Robot2024/.idea/vcs.xml | 1 + Robot2024/lib2813 | 2 +- .../src/main/java/com/team2813/Feature.java | 19 +++++++++++++++++++ .../java/com/team2813/RobotContainer.java | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Robot2024/src/main/java/com/team2813/Feature.java diff --git a/Robot2024/.idea/vcs.xml b/Robot2024/.idea/vcs.xml index 6c0b863..a6c9db8 100644 --- a/Robot2024/.idea/vcs.xml +++ b/Robot2024/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/Robot2024/lib2813 b/Robot2024/lib2813 index b283d5d..fa6e3b7 160000 --- a/Robot2024/lib2813 +++ b/Robot2024/lib2813 @@ -1 +1 @@ -Subproject commit b283d5d1d54559608881251d63a504756789698f +Subproject commit fa6e3b77e7cf2db7e5fce72a2d2c8495b410fbae diff --git a/Robot2024/src/main/java/com/team2813/Feature.java b/Robot2024/src/main/java/com/team2813/Feature.java new file mode 100644 index 0000000..866109d --- /dev/null +++ b/Robot2024/src/main/java/com/team2813/Feature.java @@ -0,0 +1,19 @@ +package com.team2813; + +import com.team2813.lib2813.feature.FeatureIdentifier; + +/** Enumeration of all features for this robot. */ +public enum Feature implements FeatureIdentifier { + EXAMPLE(FeatureBehavior.INITIALLY_DISABLED); + + private final FeatureBehavior behavior; + + Feature(FeatureBehavior behavior) { + this.behavior = behavior; + } + + @Override + public FeatureBehavior behavior() { + return behavior; + } +} diff --git a/Robot2024/src/main/java/com/team2813/RobotContainer.java b/Robot2024/src/main/java/com/team2813/RobotContainer.java index 68f49ca..fb94583 100644 --- a/Robot2024/src/main/java/com/team2813/RobotContainer.java +++ b/Robot2024/src/main/java/com/team2813/RobotContainer.java @@ -6,11 +6,13 @@ import com.pathplanner.lib.auto.AutoBuilder; +import com.team2813.lib2813.feature.Features; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; // import frc.robot.Constants.OperatorConstants; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.InstantCommand; import com.team2813.commands.DefaultDriveCommand; @@ -42,6 +44,8 @@ public RobotContainer() { shooter.setDefaultCommand(new DefaultShooterCommand(shooter, operatorController::getRightY)); configureBindings(); autoChooser = AutoBuilder.buildAutoChooser(); + autoChooser.addOption("Test Feature", + Features.whenAllEnabled(Commands.print("autonomousInit"), Feature.EXAMPLE)); SmartDashboard.putData("Auto", autoChooser); } From aae14f994822d12d77fdbdc5106aa64950e68756 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sun, 17 Mar 2024 20:35:42 -0700 Subject: [PATCH 2/2] Reset the robot when features are changed while the robot is disabled. --- Robot2024/.idea/gradle.xml | 15 ++++++++- Robot2024/lib2813 | 2 +- .../src/main/java/com/team2813/Robot.java | 33 +++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Robot2024/.idea/gradle.xml b/Robot2024/.idea/gradle.xml index 2c48b5c..4537d2e 100644 --- a/Robot2024/.idea/gradle.xml +++ b/Robot2024/.idea/gradle.xml @@ -4,11 +4,24 @@