Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/edu/greenblitz/tobyDetermined/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ public void robotPeriodic() {
@Override
public void disabledInit() {
CommandScheduler.getInstance().cancelAll();

BreakCoastSwitch.getInstance().setIsDisabled(true);
Copy link
Collaborator Author

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

Suggested change
BreakCoastSwitch.getInstance().setIsDisabled(true);
BreakCoastSwitch.getInstance().setDisabled(true);

In any case, couldn't you just get this from the driver station?

}



@Override
public void teleopInit() {
CommandScheduler.getInstance().cancelAll();
BreakCoastSwitch.getInstance().setIsDisabled(false);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

//
// Grid.init();
// MultiLimelight.getInstance().updateRobotPoseAlliance();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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) {
Expand All @@ -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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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) {
Expand All @@ -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++;
}
}

}