22
33import edu .wpi .first .wpilibj .DigitalInput ;
44import edu .wpi .first .wpilibj .DriverStation ;
5+ import edu .wpi .first .wpilibj .smartdashboard .SendableChooser ;
6+ import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
57import frc .robot .Constants .AutonConstants ;
68import frc .robot .commands .auto .AutoCommandInterface ;
79import frc .robot .commands .auto .DefaultAutoCommand ;
1921import frc .robot .commands .auto .TwoPieceWithDockAutoCommandGroup ;
2022import frc .robot .commands .auto .TwoPieceWithDockAutoMidCommandGroup ;
2123import java .util .ArrayList ;
24+ import java .util .Set ;
2225import org .slf4j .Logger ;
2326import org .slf4j .LoggerFactory ;
27+ import org .strykeforce .telemetry .measurable .MeasurableSubsystem ;
28+ import org .strykeforce .telemetry .measurable .Measure ;
2429import org .strykeforce .thirdcoast .util .AutonSwitch ;
2530
26- public class AutoSwitch {
31+ public class AutoSwitch extends MeasurableSubsystem {
2732 private final AutonSwitch autoSwitch ;
2833 private ArrayList <DigitalInput > switchInputs = new ArrayList <>();
2934 private int currAutoSwitchPos = -1 ;
3035 private int newAutoSwitchPos ;
3136 private int autoSwitchStableCounts = 0 ;
3237 private Logger logger = LoggerFactory .getLogger (AutoSwitch .class );
38+ private static SendableChooser <Integer > sendableChooser = new SendableChooser <>();
3339
3440 private AutoCommandInterface autoCommand ;
3541 private final RobotStateSubsystem robotStateSubsystem ;
@@ -43,6 +49,7 @@ public class AutoSwitch {
4349 private final VisionSubsystem visionSubsystem ;
4450 private final RGBlightsSubsystem rgBlightsSubsystem ;
4551 AutoCommandInterface defaultCommand ;
52+ private boolean useVirtualSwitch = false ;
4653
4754 public AutoSwitch (
4855 RobotStateSubsystem robotStateSubsystem ,
@@ -66,6 +73,21 @@ public AutoSwitch(
6673 this .visionSubsystem = visionSubsystem ;
6774 this .rgBlightsSubsystem = rgBlightsSubsystem ;
6875
76+ sendableChooser .addOption ("00 Cone Lvl 3, Cube Lvl 3, Auto Balance" , 0x00 );
77+ sendableChooser .setDefaultOption ("01 Cone Lvl 3, Cube Lvl 3" , 0x01 );
78+ sendableChooser .setDefaultOption ("02 Same as #1 but scores cone mid" , 0x02 );
79+ sendableChooser .setDefaultOption ("03 Cone lvl 3, Cube lvl 3, Cube lvl 2" , 0x03 );
80+ sendableChooser .setDefaultOption ("10 Cone lvl 3, cube lvl 3, balance" , 0x10 );
81+ sendableChooser .setDefaultOption ("11 Middle to dock" , 0x11 );
82+ sendableChooser .setDefaultOption ("12 Middle to dock with mobility" , 0x12 );
83+ sendableChooser .setDefaultOption ("20 Cone Lvl 3, Cube Lvl 3" , 0x20 );
84+ sendableChooser .setDefaultOption ("21 FALLBACK - Cone Lvl 3, cube lvl 2 and 3" , 0x21 );
85+ sendableChooser .setDefaultOption ("22 Cone Lvl3, Cube Lvl3" , 0x22 );
86+ sendableChooser .setDefaultOption ("23 Cone Lvl 3, cube lvl 2 and 3" , 0x23 );
87+ sendableChooser .setDefaultOption ("24 Cone Lvl 1, Cube Lvl 3 and 2" , 0x24 );
88+ sendableChooser .setDefaultOption ("30 Do nothing" , 0x30 );
89+ SmartDashboard .putData ("Auto Mode" , sendableChooser );
90+
6991 defaultCommand =
7092 new DefaultAutoCommand (
7193 driveSubsystem , robotStateSubsystem , elevatorSubsystem , handSubsystem , armSubsystem );
@@ -100,7 +122,7 @@ public AutoCommandInterface getAutoCommand() {
100122
101123 private boolean hasSwitchChanged () {
102124 boolean changed = false ;
103- int switchPos = autoSwitch .position ();
125+ int switchPos = useVirtualSwitch ? sendableChooser . getSelected () : autoSwitch .position ();
104126
105127 if (switchPos != newAutoSwitchPos ) {
106128 autoSwitchStableCounts = 0 ;
@@ -116,6 +138,28 @@ private boolean hasSwitchChanged() {
116138 return changed ;
117139 }
118140
141+ public void toggleVirtualSwitch () {
142+ logger .info ("toggledSwitch:function" );
143+ if (useVirtualSwitch ) {
144+ useVirtualSwitch = false ;
145+ } else {
146+ useVirtualSwitch = true ;
147+ }
148+ // useVirtualSwitch = useVirtualSwitch ? false : true;
149+ }
150+
151+ public String getSwitchPos () {
152+ return Integer .toHexString (currAutoSwitchPos );
153+ }
154+
155+ public boolean isUseVirtualSwitch () {
156+ return useVirtualSwitch ;
157+ }
158+
159+ public SendableChooser <Integer > getSendableChooser () {
160+ return sendableChooser ;
161+ }
162+
119163 private AutoCommandInterface getAutoCommand (int switchPos ) {
120164 switch (switchPos ) {
121165 // Non-Bump Side
@@ -292,4 +336,11 @@ private AutoCommandInterface getAutoCommand(int switchPos) {
292336 driveSubsystem , robotStateSubsystem , elevatorSubsystem , handSubsystem , armSubsystem );
293337 }
294338 }
339+
340+ @ Override
341+ public Set <Measure > getMeasures () {
342+ return Set .of (
343+ new Measure ("AutoSwitch" , () -> currAutoSwitchPos ),
344+ new Measure ("usingVirtualSwitch" , () -> this .useVirtualSwitch ? 1.0 : 0.0 ));
345+ }
295346}
0 commit comments