Skip to content

Commit

Permalink
Transition to a listener-based approach for the dashboard compressor …
Browse files Browse the repository at this point in the history
…toggle
  • Loading branch information
5t0n3 committed Apr 15, 2022
1 parent 8d6cd77 commit f3c18fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/main/java/frc/robot/Robot.java
Expand Up @@ -44,8 +44,6 @@ public void robotPeriodic() {
// and running subsystem periodic() methods. This must be called from the robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run();

m_robotContainer.updateCompressorStatus();
}

/** This function is called once each time the robot enters Disabled mode. */
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/frc/robot/RobotContainer.java
Expand Up @@ -8,6 +8,8 @@

import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.cscore.UsbCamera;
import edu.wpi.first.networktables.EntryListenerFlags;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.util.net.PortForwarder;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.GenericHID;
Expand Down Expand Up @@ -68,7 +70,8 @@ public class RobotContainer {
private final PneumaticsControlModule m_pcm = new PneumaticsControlModule();

// Used for toggling the compressor state (see updateCompressorState() method)
private boolean m_compressorEnabled = true;
// private boolean m_compressorEnabled = true;
private final NetworkTableEntry m_compressorEnabled = SmartDashboard.getEntry("Compressor On?");

// Automodes - if you add more here, add them to the chooser in setupAutoChooser()
private final TaxiThenShoot m_taxiThenShoot =
Expand Down Expand Up @@ -98,6 +101,20 @@ public RobotContainer() {
// Silence joystick connection warnings since they're not useful
DriverStation.silenceJoystickConnectionWarning(true);

// Display a compressor toggle on the dashboard
SmartDashboard.setDefaultBoolean("Compressor On?", true);
m_compressorEnabled.addListener(
(event) -> {
// Enable or disable the compressor depending on the updated toggle value
boolean enabled = event.value.getBoolean();
if (enabled) {
m_pcm.enableCompressorDigital();
} else {
m_pcm.disableCompressor();
}
},
EntryListenerFlags.kUpdate);

// Set default drivetrain command to arcade driving (happens during teleop)
m_robotDrive.setDefaultCommand(
new DefaultDrive(
Expand Down Expand Up @@ -187,19 +204,6 @@ private void setupAutoChooser() {
SmartDashboard.putData(m_autoChooser);
}

/** Used to toggle the compressor using the dashboard. */
public void updateCompressorStatus() {
m_compressorEnabled = SmartDashboard.getBoolean("Enable Compressor", m_compressorEnabled);
if (m_compressorEnabled) {
m_pcm.enableCompressorDigital();
} else {
m_pcm.disableCompressor();
}

// Put the toggle onto the dashboard
SmartDashboard.putBoolean("Enable Compressor", m_compressorEnabled);
}

/** Retracts the climber pistons and sets them to a vertical position. */
public void resetClimber() {
m_climberSubsystem.retractArms();
Expand Down

0 comments on commit f3c18fc

Please sign in to comment.