-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hotfix-break-coast switch -> master #82
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,13 +112,16 @@ public void robotPeriodic() { | |
@Override | ||
public void disabledInit() { | ||
CommandScheduler.getInstance().cancelAll(); | ||
|
||
BreakCoastSwitch.getInstance().setIsDisabled(true); | ||
} | ||
|
||
|
||
|
||
@Override | ||
public void teleopInit() { | ||
CommandScheduler.getInstance().cancelAll(); | ||
BreakCoastSwitch.getInstance().setIsDisabled(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
// | ||
// Grid.init(); | ||
// MultiLimelight.getInstance().updateRobotPoseAlliance(); | ||
|
@@ -214,8 +217,6 @@ public void disabledPeriodic() { | |
// SwerveChassis.getInstance().isEncoderBroken(); | ||
// Elbow.getInstance().resetEncoder(); | ||
|
||
BreakCoastSwitch.getInstance().toggleBreakCoast(); | ||
|
||
if (SwerveChassis.getInstance().isEncoderBroken()){ | ||
if (Extender.getInstance().DidReset()){ | ||
LED.getInstance().setColor(new Color(136, 8 ,90)); //dark red | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,28 @@ | |
|
||
import edu.greenblitz.tobyDetermined.RobotMap; | ||
import edu.greenblitz.tobyDetermined.subsystems.GBSubsystem; | ||
import edu.wpi.first.math.filter.Debouncer; | ||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
import edu.wpi.first.wpilibj.RobotController; | ||
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import org.apache.logging.log4j.core.appender.rolling.action.IfAll; | ||
|
||
import java.sql.Driver; | ||
import java.util.HashMap; | ||
|
||
public class BreakCoastSwitch { | ||
public class BreakCoastSwitch extends GBSubsystem { | ||
|
||
private static BreakCoastSwitch instance; | ||
|
||
private boolean isDisabled; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for this? 🤔 |
||
|
||
private static boolean lastState = false; | ||
private DigitalInput switchInput; | ||
private int switchPressCount; | ||
private HashMap<GBSubsystem, BreakCoastRunnables> subsystems; | ||
private Debouncer debouncer; | ||
|
||
public static BreakCoastSwitch getInstance() { | ||
if (instance == null) { | ||
|
@@ -26,7 +35,9 @@ public static BreakCoastSwitch getInstance() { | |
private BreakCoastSwitch(int id) { | ||
switchInput = new DigitalInput(id); | ||
subsystems = new HashMap<>(); | ||
this.switchPressCount = 0; | ||
this.switchPressCount = 1; | ||
debouncer = new Debouncer(0.1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is 0.1 in this context? |
||
isDisabled = false; | ||
} | ||
|
||
public void addSubsystem(GBSubsystem subsystem, Runnable setBrakeMode, Runnable setCoastMode) { | ||
|
@@ -47,25 +58,36 @@ public void setBreak() { | |
} | ||
} | ||
|
||
public void toggleBreakCoast() { | ||
if (getSwitchState() != lastState) { | ||
switchPressCount += lastState ? 1 : 0; | ||
|
||
@Override | ||
public void periodic() { | ||
if (getSwitchState() != lastState && isDisabled) { | ||
lastState = !lastState; | ||
switchPressCount += lastState ? 1 : 0; | ||
} | ||
SmartDashboard.putNumber("cnt",switchPressCount); | ||
|
||
|
||
if (this.switchPressCount % 2 == 1) { | ||
SmartDashboard.putBoolean("is", true); | ||
NoamRosenberg08 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setBreak(); | ||
} else if (this.switchPressCount % 2 == 0) { | ||
SmartDashboard.putBoolean("is", false); | ||
NoamRosenberg08 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setCoast(); | ||
} | ||
|
||
SmartDashboard.putNumber("press count", switchPressCount); | ||
} | ||
|
||
|
||
public boolean getSwitchState() { | ||
return !switchInput.get(); | ||
return !debouncer.calculate(switchInput.get()); | ||
} | ||
|
||
public void setIsDisabled (boolean isDisabled){ | ||
this.isDisabled = isDisabled; | ||
if(isDisabled){ | ||
switchPressCount++; | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing the name to something clearer, such as
In any case, couldn't you just get this from the driver station?