Skip to content

Commit

Permalink
feat: added user button functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammingSR committed Feb 27, 2024
1 parent faee82d commit c4eac26
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
14 changes: 13 additions & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

package frc.robot;


import edu.wpi.first.wpilibj.RobotController;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.subsystems.ClimberSubsystem;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
Expand All @@ -19,6 +23,9 @@ public class Robot extends TimedRobot {

private RobotContainer m_robotContainer;

public ClimberSubsystem m_climberSubsystem = new ClimberSubsystem();

private Timer m_buttonTimer = new Timer();
/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand Down Expand Up @@ -51,7 +58,12 @@ public void robotPeriodic() {
public void disabledInit() {}

@Override
public void disabledPeriodic() {}
public void disabledPeriodic() {
if (RobotController.getUserButton() && m_buttonTimer.get() > 1) {
m_climberSubsystem.toggleCompressor();
m_buttonTimer.reset();
}
}

/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
@Override
Expand Down
29 changes: 10 additions & 19 deletions src/main/java/frc/robot/subsystems/ClimberSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class ClimberSubsystem extends SubsystemBase{

private final Compressor m_compressor = new Compressor(PneumaticsModuleType.REVPH);

private boolean enableCompressor = true;
private boolean m_compressorEnabled;

private Value m_state;

public ClimberSubsystem() {
solenoidOff();
m_compressor.disable();
m_compressor.enableAnalog(ClimberConstants.minPressure, ClimberConstants.maxPressure);
m_compressorEnabled = false;
solenoidOff();
toggleCompressor();
}

// Runs once every tick (~20ms)
Expand Down Expand Up @@ -56,22 +56,13 @@ public void forward() {
public void reverse() {
m_state = kReverse;
}
/*
* Toggles the state of the climber
*/

public void toggle() {
if(m_state == kForward){
m_state = kReverse;
}else if(m_state == kReverse){
m_state = kForward;
}
}

// Toggles the state of the compressor (on/off)
public void toggleCompresor() {
enableCompressor = !enableCompressor;
if (enableCompressor) {
/**
* Toggles the state of the compressor (on/off)
*/
public void toggleCompressor() {
m_compressorEnabled = !m_compressorEnabled;
if (m_compressorEnabled) {
m_compressor.enableAnalog(ClimberConstants.minPressure, ClimberConstants.maxPressure);
} else {
m_compressor.disable();
Expand Down

0 comments on commit c4eac26

Please sign in to comment.