Skip to content

Commit 8be75f4

Browse files
committed
tweaks to constants implementation
1 parent 225cbc8 commit 8be75f4

File tree

3 files changed

+74
-29
lines changed

3 files changed

+74
-29
lines changed

src/main/java/frc/robot/constants/BattMonConstants.java

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,55 @@
22

33
public class BattMonConstants {
44
// All of these aren't right and will need to be determined
5-
public static double kBattVolt1 = 42;
6-
public static double kBattVolt2;
7-
public static double kBattCurrent1 = 42;
8-
public static double kBattCurrent2;
9-
public static double kPdpVoltage1 = 42;
10-
public static double kPdpVoltage2;
5+
6+
// Battery Voltage Conversion
7+
public static final double kBattVolt1 = 12;
8+
public static final double kBattVolt1DC = 0.9;
9+
public static final double kBattVolt2 = 2;
10+
public static final double kBattVolt2DC = 0.1;
11+
public static final double kBattVoltSlope =
12+
(kBattVolt1 - kBattVolt2) / (kBattVolt1DC - kBattVolt2DC);
13+
public static final double kBattVoltOffset = kBattVolt1 - kBattVoltSlope * kBattVolt1DC;
14+
15+
// Battery Current Conversion
16+
public static final double kBattCurrent1 = 50;
17+
public static final double kBattCurrent1DC = 0.9;
18+
public static final double kBattCurrent2 = 1;
19+
public static final double kBattCurrent2DC = 0.1;
20+
public static final double kBattCurrentSlope =
21+
(kBattCurrent1 - kBattCurrent2) / (kBattCurrent1DC - kBattCurrent2DC);
22+
public static final double kBattCurrentOffset =
23+
kBattCurrent1 - kBattCurrentSlope * kBattCurrent1DC;
24+
25+
// PDP Voltage Conversion
26+
public static final double kPdpVoltage1 = 42;
27+
public static final double kPdpVoltage1DC = 0.9;
28+
public static final double kPdpVoltage2 = 2;
29+
public static final double kPdpVoltage2DC = 0.1;
30+
public static final double kPdpVoltSlope =
31+
(kPdpVoltage1 - kPdpVoltage2) / (kPdpVoltage1DC - kPdpVoltage2DC);
32+
public static final double kPdpVoltOffset = kPdpVoltage1 - kPdpVoltSlope * kPdpVoltage1DC;
33+
34+
// Breaker Temp Conversion
1135
public static double kBreakerTemp1 = 0.32;
1236
public static double kBreakerTemp2 = 0.0047;
1337

14-
public static double kBatt1Low = 2;
15-
public static double kBatt2Low = 2;
16-
public static double kPDPHigh = 42;
17-
public static double kTempHighSlope = 10;
18-
public static double kTempDangerSlope = 15;
19-
public static double kHysteresis= 1;
38+
// Low Battery Thresholds
39+
public static final double kBatt1Low = 2;
40+
public static final double kBatt2Low = 2;
41+
42+
// Temp Limiting
43+
public static final double kCurrent1 = 10;
44+
public static final double kCurrent1Temp = 200;
45+
public static final double kCurrent2 = 200;
46+
public static final double kCurrent2Temp = 160;
47+
public static final double kTempLimitSlope =
48+
(kCurrent1Temp - kCurrent2Temp) / (kCurrent1 - kCurrent2);
49+
public static final double kTempLimitOffset = kCurrent1Temp - kTempLimitSlope * kCurrent1;
50+
public static final double kHysteresis = 20;
51+
public static final double kWarningOffset = 5;
52+
53+
public static final double kPDPHigh = 42;
54+
public static final double kTempHighSlope = 10;
55+
public static final double kTempDangerSlope = 15;
2056
}

src/main/java/frc/robot/subsystems/battMon/BattMonHardware.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ public BattMonHardware() {
2424

2525
@Override
2626
public void updateInputs(BattMonIOInputs inputs) {
27-
inputs.batteryVoltage = battVoltageCycle.getOutput()
28-
* BattMonConstants.kBattVolt1 * BattMonConstants.kBattVolt2;
29-
inputs.batteryCurrent = battCurrentCycle.getOutput()
30-
* BattMonConstants.kBattCurrent1 * BattMonConstants.kBattCurrent2;
31-
inputs.pdpVoltage = pdpCycle.getOutput()
32-
* BattMonConstants.kPdpVoltage1 * BattMonConstants.kPdpVoltage2;
27+
inputs.batteryVoltage =
28+
battVoltageCycle.getOutput() * BattMonConstants.kBattVoltSlope
29+
+ BattMonConstants.kBattVoltOffset;
30+
inputs.batteryCurrent =
31+
battCurrentCycle.getOutput() * BattMonConstants.kBattCurrentSlope
32+
+ BattMonConstants.kBattCurrentOffset;
33+
inputs.pdpVoltage =
34+
pdpCycle.getOutput() * BattMonConstants.kPdpVoltSlope + BattMonConstants.kPdpVoltOffset;
3335
inputs.breakerTemp =
3436
((tempCycle.getHighTimeNanoseconds() / (tempCounter.getPeriod() / 1000000000))
35-
- BattMonConstants.kBreakerTemp1) / BattMonConstants.kBreakerTemp2;
37+
- BattMonConstants.kBreakerTemp1)
38+
/ BattMonConstants.kBreakerTemp2;
3639
}
3740
}

src/main/java/frc/robot/subsystems/battMon/BattMonSubsystem.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,51 @@
44
import edu.wpi.first.wpilibj.Alert.AlertType;
55
import edu.wpi.first.wpilibj2.command.SubsystemBase;
66
import frc.robot.constants.BattMonConstants;
7-
import frc.robot.subsystems.battMon.BattMonIO.BattMonIOInputs;
7+
import org.littletonrobotics.junction.Logger;
88

99
public class BattMonSubsystem extends SubsystemBase {
1010
// Private objects
1111
private BattMonIO io;
12-
private BattMonIOInputs inputs = new BattMonIOInputs();
12+
private BattMonIOInputsAutoLogged inputs = new BattMonIOInputsAutoLogged();
1313
private battMonState curState;
1414
// Alerts
1515
private Alert highTempAlert = new Alert("WARNING reaching maximum temp!", AlertType.kWarning);
1616
private Alert dangerTempAlert = new Alert("DANGER MAXIMUM TEMP REACHED", AlertType.kError);
1717
private Alert safeAlert = new Alert("SAFE Temp low. Limits removed", AlertType.kInfo);
1818

19-
private double tempThreshold;
19+
private double recoveryTempThreshold;
20+
private double curDangerThreshold;
21+
private double curWarnThreshold;
2022

2123
@Override
2224
public void periodic() {
2325
// Refresh data and graph it
2426
io.updateInputs(inputs);
27+
Logger.processInputs(getName(), inputs);
28+
29+
curDangerThreshold =
30+
BattMonConstants.kTempLimitSlope * inputs.batteryCurrent
31+
+ BattMonConstants.kTempLimitOffset;
32+
curWarnThreshold = curDangerThreshold - BattMonConstants.kWarningOffset;
2533

2634
// Check for dangerous outputs NOTE all of these values are temporary
2735
switch (curState) {
2836
case NORMAL:
29-
if (inputs.breakerTemp >= (BattMonConstants.kTempHighSlope * inputs.pdpVoltage + 100)) {
37+
if (inputs.breakerTemp >= curWarnThreshold) {
3038
highTempAlert.set(true);
3139
safeAlert.set(false);
32-
tempThreshold = inputs.breakerTemp - BattMonConstants.kHysteresis * inputs.pdpVoltage;
40+
recoveryTempThreshold = curWarnThreshold - BattMonConstants.kHysteresis;
3341
curState = battMonState.WARNING;
3442
} else {
3543
break;
3644
}
3745

3846
case WARNING:
39-
if (inputs.breakerTemp > (BattMonConstants.kTempDangerSlope * inputs.pdpVoltage)) {
47+
if (inputs.breakerTemp > curDangerThreshold) {
4048
highTempAlert.set(false);
4149
dangerTempAlert.set(true);
4250
curState = battMonState.DANGER;
43-
} else if (inputs.breakerTemp < tempThreshold) {
51+
} else if (inputs.breakerTemp < recoveryTempThreshold) {
4452
highTempAlert.set(false);
4553
safeAlert.set(true);
4654
curState = battMonState.NORMAL;
@@ -49,9 +57,7 @@ public void periodic() {
4957
}
5058

5159
case DANGER:
52-
if (inputs.breakerTemp >= (BattMonConstants.kTempDangerSlope * inputs.pdpVoltage)) {
53-
break;
54-
} else {
60+
if (inputs.breakerTemp <= recoveryTempThreshold) {
5561
dangerTempAlert.set(false);
5662
highTempAlert.set(true);
5763
curState = battMonState.WARNING;

0 commit comments

Comments
 (0)