Mini-Project 3: A Live Power-Monitoring Dashboard
Use the WPILib PowerDistribution class to stream per-channel current, total current, voltage, and energy to your driver dashboard.
Sign in to track progress, earn XP, and save lessons.
Both the CTRE PDP and the REV PDH log current per channel and report battery voltage over CAN. WPILib exposes all of it through the PowerDistribution class, so you can build a real dashboard that tells your drive team exactly where the amps are going. This is how you catch a stalling intake or a failing battery before it costs you a match.
Construct the object for your hardware:
import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
// REV PDH default CAN ID is 1
PowerDistribution pdh = new PowerDistribution(1, ModuleType.kRev);
// CTRE PDP default CAN ID is 0
// PowerDistribution pdp = new PowerDistribution(0, ModuleType.kCTRE);
Read and publish metrics each loop:
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
@Override public void robotPeriodic() {
SmartDashboard.putNumber("Battery Voltage", pdh.getVoltage());
SmartDashboard.putNumber("Total Current (A)", pdh.getTotalCurrent());
SmartDashboard.putNumber("Total Power (W)", pdh.getTotalPower());
SmartDashboard.putNumber("Energy (J)", pdh.getTotalEnergy());
SmartDashboard.putNumber("PDH Temp (C)", pdh.getTemperature());
// Per-channel current, e.g. the four drive motors on channels 0-3
for (int ch = 0; ch < 4; ch++) {
SmartDashboard.putNumber("Drive Ch " + ch + " (A)", pdh.getCurrent(ch));
}
}
A practical brownout warning widget:
if (pdh.getVoltage() < 7.5) {
SmartDashboard.putBoolean("LOW VOLTAGE", true);
}
if (edu.wpi.first.wpilibj.RobotController.isBrownedOut()) {
// A brownout already happened this loop
DataLogManager.log("BROWNOUT at " + Timer.getFPGATimestamp());
}
The brownout cutoff is 6.3V on the roboRIO 1 and 6.75V by default on the roboRIO 2, so a 7.5V warning gives the driver a meaningful heads-up before outputs actually cut. (7.5V is also the voltage the roboRIO must climb back above to exit brownout.)
Known PDH quirk to design around: the REV PDH's four low-current-class channels (20-23) have a documented firmware bug where current readings above 15.9375A wrap back toward 0A (so 20A reads as roughly 4A). Readings below 15.9375A are accurate. Keep anything you actually want to current-monitor on the 40A high-current channels (0-19), and treat low-current channel readings above ~16A as unreliable.
Graph total current against time during a practice match. A healthy battery holds voltage; one that sags to 9-10V under a 150A draw is on its way out and belongs on the test bench, not in the next match.
Key takeaways
- PowerDistribution(1, ModuleType.kRev) for the PDH or (0, ModuleType.kCTRE) for the PDP gives per-channel and total telemetry over CAN.
- Surface a 7.5V low-voltage warning so the driver reacts before the 6.3V/6.75V brownout cutoff (7.5V is also the brownout-recovery threshold).
- PDH low-current channels 20-23 mis-report current above 15.9375A (wraps toward 0A); keep monitored loads on the 40A channels.
Go deeper
Lesson quiz
RequiredAnswer all 3 questions correctly to complete this lesson.
1.Which WPILib class is used to read live voltage, per-channel current, and temperature from a CTRE PDP or REV PDH over CAN for a power-monitoring dashboard?
2.What are the default CAN IDs that WPILib's PowerDistribution uses for the CTRE PDP and the REV PDH, respectively?
3.On a live dashboard, which PowerDistribution method gives you the current draw of one specific output channel?
Answer every question to submit.