Fix mode switching

- Add button to ShuffleBoard
- Remove controller button
This commit is contained in:
nathanrsxtn
2021-11-18 17:45:49 -07:00
parent 9e6c9f29b5
commit 8438bc6768
3 changed files with 22 additions and 13 deletions
+12 -4
View File
@@ -8,12 +8,14 @@
package frc4388.robot;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Vector;
import java.util.function.Consumer;
import com.ctre.phoenix.motorcontrol.SupplyCurrentLimitConfiguration;
import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc4388.utility.Gains;
import frc4388.utility.LEDPatterns;
@@ -29,18 +31,25 @@ import frc4388.utility.LEDPatterns;
public final class Constants {
public enum Mode {
COMPETITIVE, CASUAL;
private static Mode mode;
private static Mode mode = Mode.COMPETITIVE;
private static Vector<Consumer<Mode>> changeHandlers = new Vector<>();
public static void register(Consumer<Mode> changeHandler) {
changeHandlers.add(changeHandler);
}
public static Mode get() {
return mode;
}
public static void set(Mode mode) {
Mode.mode = mode;
System.out.println(mode);
int i = mode.ordinal();
// changeHandlers.forEach(c -> c.accept(mode));
Mode.mode = mode;
CommandScheduler.getInstance().disable();
changeHandlers.forEach(c -> c.accept(mode));
CommandScheduler.getInstance().enable();
DriveConstants.DRIVE_WITH_JOYSTICK_FACTOR = DriveConstants.DRIVE_WITH_JOYSTICK_FACTOR_MODES[i];
IntakeConstants.INTAKE_SPEED = IntakeConstants.INTAKE_SPEED_MODES[i];
StorageConstants.STORAGE_SPEED = StorageConstants.STORAGE_SPEED_MODES[i];
@@ -50,7 +59,6 @@ public final class Constants {
Mode[] values = values();
i = i >= values.length ? 0 : i;
set(values[i]);
System.out.println(mode);
}
}
+10 -3
View File
@@ -13,6 +13,9 @@ import com.ctre.phoenix.motorcontrol.NeutralMode;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.geometry.Pose2d;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
@@ -33,6 +36,7 @@ public class Robot extends TimedRobot {
double m_currentTime;
double m_deltaTime;
SendableChooser<Mode> m_modeChooser = new SendableChooser<>();
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
@@ -43,6 +47,10 @@ public class Robot extends TimedRobot {
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
SmartDashboard.putString("Is Auto Start?", "NAH");
Mode.set(Mode.COMPETITIVE);
m_modeChooser.setDefaultOption(Mode.COMPETITIVE.name(), Mode.COMPETITIVE);
m_modeChooser.addOption(Mode.CASUAL.name(), Mode.CASUAL);
SmartDashboard.putData("Mode", m_modeChooser);
}
/**
@@ -80,6 +88,8 @@ public class Robot extends TimedRobot {
public void disabledPeriodic() {
m_robotContainer.resetOdometry(new Pose2d());
m_robotContainer.idenPath();
if (m_modeChooser.getSelected() != Mode.get())
Mode.set(m_modeChooser.getSelected());
}
/**
@@ -87,7 +97,6 @@ public class Robot extends TimedRobot {
*/
@Override
public void autonomousInit() {
Mode.set(Mode.COMPETITIVE);
//m_robotContainer.buildAutos();
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
@@ -129,7 +138,6 @@ public class Robot extends TimedRobot {
@Override
public void teleopInit() {
Mode.set(Mode.COMPETITIVE);
m_robotContainer.setDriveNeutralMode(NeutralMode.Brake);
m_robotContainer.setDriveGearState(true);
@@ -156,7 +164,6 @@ public class Robot extends TimedRobot {
@Override
public void testInit() {
Mode.set(Mode.CASUAL);
}
/**
@@ -271,9 +271,6 @@ public class RobotContainer {
new JoystickButton(getDriverJoystick(), XboxController.X_BUTTON)
.whenPressed(new InstantCommand());
new JoystickButton(getDriverJoystick(), XboxController.START_BUTTON)
.whenPressed(new InstantCommand(Mode::toggle));
/* Driver Buttons */
// sets solenoids into high gear
new JoystickButton(getDriverJoystick(), XboxController.RIGHT_BUMPER_BUTTON)
@@ -390,9 +387,6 @@ public class RobotContainer {
// A driver test button
new JoystickButton(getDriverJoystick(), XboxController.START_BUTTON)
.whenPressed(new InstantCommand(Mode::toggle));
/* Driver Buttons */
// sets solenoids into high gear
new JoystickButton(getDriverJoystick(), XboxController.RIGHT_BUMPER_BUTTON)