Skip to content

Commit a4b0e50

Browse files
added a method to check if setVoltage is close to appliedVoltage
1 parent 8e57e8b commit a4b0e50

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

src/main/java/frc/robot/subsystems/groundIntake/GroundIntake.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public GroundIntake (GroundIntakeIO io) {
2727
logP = new LoggedDashboardNumber("GroundIntake/P", io.getP());
2828
logI = new LoggedDashboardNumber("GroundIntake/I", io.getI());
2929
logD = new LoggedDashboardNumber("GroundIntake/D", io.getD());
30-
3130
}
3231

32+
3333
public void periodic() {
3434
io.updateInputs(inputs);
3535
// Update PID constants to ensure they are up to date
@@ -48,12 +48,23 @@ public void periodic() {
4848
Logger.recordOutput("GroundIntake/GIntakeMotorConnected", inputs.velocityRadsPerSec != 0);
4949
}
5050

51+
//Check if the actual voltage is close to the desired voltage
52+
public boolean isVoltageClose(double setVoltage, double tolerance) {
53+
// Calculate the absolute difference between the desired and applied voltages
54+
double voltageDifference = Math.abs(setVoltage - inputs.appliedVoltage);
55+
56+
// Check if the absolute difference is within the tolerance
57+
return voltageDifference <= tolerance;
58+
}
59+
5160
public void setVoltage(double voltage) {
5261
if (SmartDashboard.getBoolean("Turbo Mode", false)){
5362
io.setVoltage(0);
5463
} else {
5564
io.setVoltage(voltage);
5665
}
66+
67+
Logger.recordOutput('GroundIntake/Close', isVoltageClose(voltage, 1));
5768
}
5869

5970
public void setBrake(boolean brake) {

src/main/java/frc/robot/subsystems/indexer/Indexer.java

+11
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,21 @@ public Indexer (IndexerIO io) {
4343
logD = new LoggedDashboardNumber("Intake/D", io.getD());
4444
}
4545

46+
//Check if the actual voltage is close to the desired voltage
47+
public boolean isVoltageClose(double setVoltage, double tolerance) {
48+
// Calculate the absolute difference between the desired and applied voltages
49+
double voltageDifference = Math.abs(setVoltage - inputs.appliedVoltage);
50+
51+
// Check if the absolute difference is within the tolerance
52+
return voltageDifference <= tolerance;
53+
}
54+
4655
public void periodic() {
4756
io.updateInputs(inputs);
4857
// Update PID constants to ensure they are up to date
4958
Logger.processInputs("Intake", inputs);
5059

60+
5161
// Updates state of where the note is in the intake
5262
if(noteState == NoteState.NOT_ENOUGH && inputs.breakBeam) { // Note just entered the right spot
5363
noteState = NoteState.GOLDILOCKS;
@@ -95,6 +105,7 @@ public void setVoltage(double voltage) {
95105
} else {
96106
io.setVoltage(voltage);
97107
}
108+
Logger.recordOutput('Indexer/Close', isVoltageClose(voltage, 1));
98109
}
99110

100111
public void setBrake(boolean brake) {

src/main/java/frc/robot/subsystems/pivotArm/PivotArm.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ public void setBrake(boolean brake) {
134134
io.setBrake(brake);
135135
}
136136

137+
//Check if the actual voltage is close to the desired voltage
138+
public boolean isVoltageClose(double setVoltage, double tolerance) {
139+
// Calculate the absolute difference between the desired and applied voltages
140+
double voltageDifference = Math.abs(setVoltage - inputs.appliedVoltage);
141+
142+
// Check if the absolute difference is within the tolerance
143+
return voltageDifference <= tolerance;
144+
}
145+
137146
public void setVoltage(double motorVolts) {
138147
// limit the arm if its past the limit
139148
if (io.getAngle() > PivotArmConstants.PIVOT_ARM_MAX_ANGLE && motorVolts > 0) {
@@ -147,6 +156,7 @@ public void setVoltage(double motorVolts) {
147156
} else {
148157
io.setVoltage(motorVolts);
149158
}
159+
Logger.recordOutput('PivotArm/Close', isVoltageClose(voltage, 1));
150160
}
151161

152162
public void move(double speed) {
@@ -324,5 +334,4 @@ public Command dynamicBack() {
324334
.alongWith(new InstantCommand(() -> Logger.recordOutput("PivotArm/sysid-test-state-", "dynamic-reverse")));
325335
}
326336

327-
}
328-
337+
}

src/main/java/frc/robot/subsystems/shooter/Shooter.java

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public Shooter(ShooterIO io) {
6060
shooterIO.setRightPID(rightkP.get(), rightkI.get(), rightkD.get());
6161
}
6262

63+
//Check if the actual voltage is close to the desired voltage
64+
public boolean isVoltageClose(double setVoltage, double tolerance) {
65+
// Calculate the absolute difference between the desired and applied voltages
66+
double voltageDifference = Math.abs(setVoltage - inputs.appliedVoltage);
67+
68+
// Check if the absolute difference is within the tolerance
69+
return voltageDifference <= tolerance;
70+
71+
6372
@Override
6473
public void periodic() {
6574
// check controllers
@@ -175,6 +184,8 @@ public void setVoltage(DoubleSupplier leftVoltage, DoubleSupplier rightVoltage){
175184
shooterIO.setVoltage(leftMotorVoltage, rightMotorVoltage);
176185
}
177186
}
187+
Logger.recordOutput('Shooter/Close', isVoltageClose(voltage, 1));
188+
}
178189

179190
public void setVoltage(double volts){
180191
setVoltage(() -> volts, () -> volts);

0 commit comments

Comments
 (0)