Skip to content

Commit

Permalink
add rumble
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelLesirge committed Mar 28, 2024
1 parent 9665517 commit 3627526
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/main/java/frc/robot/commands/IntakeControllerSignal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package frc.robot.commands;

import java.util.function.BooleanSupplier;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
import edu.wpi.first.wpilibj2.command.Command;

public class IntakeControllerSignal extends Command {
private final XboxController controller;
private final BooleanSupplier signal;
private final double rumbleValue;

private final double rumbleTimeMax = 0.2 / TimedRobot.kDefaultPeriod;
private double rumbleTime = 0;

public IntakeControllerSignal(XboxController controller, BooleanSupplier signal, double rumbleValue) {
this.controller = controller;
this.signal = signal;
this.rumbleValue = rumbleValue;
}

@Override
public void execute() {
boolean value = signal.getAsBoolean();

if (value) {
if (rumbleTime < rumbleTimeMax) {
rumbleTime++;
controller.setRumble(RumbleType.kBothRumble, rumbleValue);
}
}
else {
rumbleTime = 0;
controller.setRumble(RumbleType.kBothRumble, 0);
}
}

@Override
public boolean isFinished() {
return false;
}

@Override
public void end(boolean interrupted) {
controller.setRumble(RumbleType.kBothRumble, 0);
}
}

0 comments on commit 3627526

Please sign in to comment.