public class Battery extends SubsystemBase {
private double voltage;
+
public Battery() {
updateVoltageFromBattery();
}
- private void updateVoltageFromBattery() {
+ private void updateVoltageFromBattery() {
voltage = RobotController.getBatteryVoltage();
}
- public double getVoltage() { return voltage; }
- public double voltsTillBrownOut() { return voltage - RobotController.getBrownoutVoltage(); }
- public double toBrownOut() {
+ public double getVoltage() {
+ return voltage;
+ }
+
+ public double voltsTillBrownOut() {
+ return voltage - RobotController.getBrownoutVoltage();
+ }
+
+ public double toBrownOut() {
// percent of volts we've got left over what we had to start with
return voltsTillBrownOut() / (BatteryConstants.MAX_STARTING_VOLTS - RobotController.getBrownoutVoltage());
}
package frc.robot.subsystems.PowerControl;
public class BatteryConstants {
- public static final double MAX_STARTING_VOLTS = 12.5; // V
+ public static final double MAX_STARTING_VOLTS = 12.5; // V
}
public static final double WARNING_PERCENTAGE = 0.6; // percent that the system reacts to approaching thresholds
// ports
- public static int[] DRIVETRAIN_PORTS = {8,9,10,11,18,19,0,1}; // bls, bld, fld, fls, frs, frd, brd, brs
- public static int[] TURRET_PORTS = {2};
- public static int[] INTAKE_PORTS = {15,14,13}; // right, left, roller
- public static int[] SHOOTER_PORTS = {3,4}; // left, right
- public static int[] HOOD_PORTS = {5}; // shooter
- public static int[] SPINDEXER_PORTS = {12}; // spindexer (unupdated on sheets)
+ public static int[] DRIVETRAIN_PORTS = { 8, 9, 10, 11, 18, 19, 0, 1 }; // bls, bld, fld, fls, frs, frd, brd, brs
+ public static int[] TURRET_PORTS = { 2 };
+ public static int[] INTAKE_PORTS = { 15, 14, 13 }; // right, left, roller
+ public static int[] SHOOTER_PORTS = { 3, 4 }; // left, right
+ public static int[] HOOD_PORTS = { 5 }; // shooter
+ public static int[] SPINDEXER_PORTS = { 12 }; // spindexer (unupdated on sheets)
}
Current w = new Current(); // create a filter for the threshold
w.tau = tau;
w.threshold = threshold;
- w.alpha = 1 - Math.exp(-Constants.LOOP_TIME / tau); // 1 - e^(-0.02/1) = 0.0198, 1 - e^(-0.02/2) = 0.00995
+ w.alpha = 1 - Math.exp(-Constants.LOOP_TIME / tau); // 1 - e^(-0.02/1) = 0.0198, 1 - e^(-0.02/2) = 0.00995
filters.add(w);
}
// subsystems
- for (int i=0; i<pDis.getNumChannels(); i++) {
+ for (int i = 0; i < pDis.getNumChannels(); i++) {
double tau = 1.0;
double threshold = i;
Current w = new Current();
Logger.recordOutput("Breaker/IntervalAverage/" + f.tau, f.average);
}
- // this is getting currents coming out of all the ports from PDH (big thing under robot all the wires come out of)
+ // this is getting currents coming out of all the ports from PDH (big thing
+ // under robot all the wires come out of)
subsystemCurrents = getAllCurrentFromPowerDistribution();
-
+
// this should average out all ports
for (Current s : subsystems) {
s.average += s.alpha * (subsystemCurrents[(int) s.threshold] - s.average);
}
- // this should use updated port averages and sum them to get drivetrain average draw for 1 tau (can add more later)
+ // this should use updated port averages and sum them to get drivetrain average
+ // draw for 1 tau (can add more later)
Logger.recordOutput("Breaker/DrivetrainAverageDraw", getAverageCurrentDraw(BreakerConstants.DRIVETRAIN_PORTS));
Logger.recordOutput("Breaker/SpindexerDraw", getAverageCurrentDraw(BreakerConstants.SPINDEXER_PORTS));
Logger.recordOutput("Breaker/ShooterDraw", getAverageCurrentDraw(BreakerConstants.SHOOTER_PORTS));
}
public double getCurrentFromPowerDistribution() {
- return pDis.getTotalCurrent(); // not using .getCurrent() and then an arguement for the port you can get just one port
+ return pDis.getTotalCurrent(); // not using .getCurrent() and then an arguement for the port you can get just
+ // one port
}
public double[] getAllCurrentFromPowerDistribution() {
worst = f;
}
}
- double[] returnValue = {worst.average/worst.threshold, worst.tau};
+ double[] returnValue = { worst.average / worst.threshold, worst.tau };
return returnValue;
}
}