Skip to content

Commit 30d3ec9

Browse files
committed
arm brake driver rumble
1 parent e58fd23 commit 30d3ec9

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/main/java/frc/robot/RobotContainer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public class RobotContainer {
3434
CommandXboxController driver = new CommandXboxController(0);
3535
CommandXboxController operator = new CommandXboxController(1);
3636

37-
StateControllerSub stateController = new StateControllerSub(); //this MUST be created before any pathplanner commands
37+
StateControllerSub stateController = new StateControllerSub(driver,operator); //this MUST be created before any pathplanner commands
3838

39-
PneumaticControlSub pneumaticControlSub = new PneumaticControlSub();
39+
PneumaticControlSub pneumaticControlSub = new PneumaticControlSub(stateController);
4040

4141

4242
VisionSubsystem visionSub = new VisionSubsystem(stateController);

src/main/java/frc/robot/StateControllerSub.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import edu.wpi.first.math.util.Units;
66
import edu.wpi.first.networktables.*;
77
import edu.wpi.first.wpilibj.DigitalInput;
8+
import edu.wpi.first.wpilibj.GenericHID;
89
import edu.wpi.first.wpilibj.Timer;
910
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1011
import edu.wpi.first.wpilibj2.command.InstantCommand;
1112
import edu.wpi.first.wpilibj2.command.SubsystemBase;
13+
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
1214
import frc.robot.commands.drive.Alignments;
1315
import frc.robot.util.AllianceFlipUtil;
1416
import frc.robot.util.MBUtils;
@@ -197,7 +199,9 @@ public void setClimbState(ClimbState climbState){
197199
DigitalInput beamBreak1 = new DigitalInput(4);
198200

199201

200-
public StateControllerSub(){
202+
CommandXboxController driver;
203+
CommandXboxController operator;
204+
public StateControllerSub(CommandXboxController driver, CommandXboxController operator){
201205
NamedCommands.registerCommand("intakeMode",new InstantCommand(this::intakePressed));
202206
NamedCommands.registerCommand("holdMode",new InstantCommand(this::holdPressed));
203207
NamedCommands.registerCommand("setObjectiveSpeaker",new InstantCommand(this::speakerPressed));
@@ -215,6 +219,8 @@ public StateControllerSub(){
215219
SmartDashboard.putBoolean("alignWhenClose",alignWhenCloseEnabled);
216220

217221

222+
this.driver = driver;
223+
this.operator = operator;
218224

219225
}
220226

@@ -230,6 +236,8 @@ public void periodic(){
230236

231237
publishTableEntries();
232238

239+
updateRumbles();
240+
233241
//get an x y and z from smartDashboard
234242

235243

@@ -288,6 +296,28 @@ public void periodic(){
288296

289297
}
290298

299+
public void updateRumbles(){
300+
double bothRumbleVal = 0;
301+
302+
if(Timer.getFPGATimestamp() - lastBrakeEngagementTimestamp <0.2 && armState == ArmState.SPEAKER)
303+
bothRumbleVal = 1;
304+
305+
driver.getHID().setRumble(GenericHID.RumbleType.kBothRumble,bothRumbleVal);
306+
operator.getHID().setRumble(GenericHID.RumbleType.kBothRumble,bothRumbleVal);
307+
308+
}
309+
boolean brakeEngaged = false;
310+
double lastBrakeEngagementTimestamp = 0;
311+
public void feedBrakeEngaged(boolean brakeEngaged){
312+
if(brakeEngaged == true && this.brakeEngaged == false)
313+
onBrakeEngaged();
314+
this.brakeEngaged = brakeEngaged;
315+
}
316+
317+
void onBrakeEngaged(){
318+
lastBrakeEngagementTimestamp = Timer.getFPGATimestamp();
319+
}
320+
291321

292322
public void setDuckMode(boolean down){
293323
if(down) duckMode = DuckMode.DOWN;

src/main/java/frc/robot/subsystems/PneumaticControlSub.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import edu.wpi.first.wpilibj.Solenoid;
55
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
66
import edu.wpi.first.wpilibj2.command.SubsystemBase;
7+
import frc.robot.StateControllerSub;
78

89
public class PneumaticControlSub extends SubsystemBase {
910
PneumaticsControlModule pcm = new PneumaticsControlModule(59);
@@ -12,15 +13,18 @@ public class PneumaticControlSub extends SubsystemBase {
1213
Solenoid climbSolenoid;
1314
Solenoid brakeSolenoid;
1415

15-
public PneumaticControlSub(){
16+
17+
StateControllerSub stateControllerSub;
18+
19+
public PneumaticControlSub(StateControllerSub stateControllerSub){
1620
pcm.disableCompressor();
1721
SmartDashboard.putBoolean("enableCompressor",false);
1822

1923
climbSolenoid = pcm.makeSolenoid(6);
2024
brakeSolenoid = pcm.makeSolenoid(5);
2125

2226
SmartDashboard.putBoolean("enableBrakes",true);
23-
27+
this.stateControllerSub = stateControllerSub;
2428

2529
}
2630

@@ -52,6 +56,7 @@ public void setBrakeSolenoid(boolean state){
5256
SmartDashboard.putBoolean("brakeSolenoidClosed",state);
5357
if(!SmartDashboard.getBoolean("enableBrakes",true))
5458
state = false;
59+
stateControllerSub.feedBrakeEngaged(state);
5560
brakeSolenoid.set(state);
5661
}
5762

0 commit comments

Comments
 (0)