diff --git a/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp index aed898fb5c..95a9a0d412 100644 --- a/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp @@ -13,20 +13,40 @@ */ class Robot : public frc::TimedRobot { public: - void TeleopPeriodic() override { - /* Get the current going through channel 7, in Amperes. The PDP returns the - * current in increments of 0.125A. At low currents the current readings - * tend to be less accurate. - */ - frc::SmartDashboard::PutNumber("Current Channel 7", m_pdp.GetCurrent(7)); + void RobotInit() override { + // Put the PDP itself to the dashboard + frc::SmartDashboard::PutData("PDP", &m_pdp); + } - /* Get the voltage going into the PDP, in Volts. The PDP returns the voltage - * in increments of 0.05 Volts. - */ - frc::SmartDashboard::PutNumber("Voltage", m_pdp.GetVoltage()); + void RobotPeriodic() override { + // Get the current going through channel 7, in Amperes. + // The PDP returns the current in increments of 0.125A. + // At low currents the current readings tend to be less accurate. + double current7 = m_pdp.GetCurrent(7); + frc::SmartDashboard::PutNumber("Current Channel 7", current7); + + // Get the voltage going into the PDP, in Volts. + // The PDP returns the voltage in increments of 0.05 Volts. + double voltage = m_pdp.GetVoltage(); + frc::SmartDashboard::PutNumber("Voltage", voltage); // Retrieves the temperature of the PDP, in degrees Celsius. - frc::SmartDashboard::PutNumber("Temperature", m_pdp.GetTemperature()); + double temperatureCelsius = m_pdp.GetTemperature(); + frc::SmartDashboard::PutNumber("Temperature", temperatureCelsius); + + // Get the total current of all channels. + double totalCurrent = m_pdp.GetTotalCurrent(); + frc::SmartDashboard::PutNumber("Total Current", totalCurrent); + + // Get the total power of all channels. + // Power is the bus voltage multiplied by the current with the units Watts. + double totalPower = m_pdp.GetTotalPower(); + frc::SmartDashboard::PutNumber("Total Power", totalPower); + + // Get the total energy of all channels. + // Energy is the power summed over time with units Joules. + double totalEnergy = m_pdp.GetTotalEnergy(); + frc::SmartDashboard::PutNumber("Total Energy", totalEnergy); } private: diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java index 1d5e24f66e..e2b699d250 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/canpdp/Robot.java @@ -15,24 +15,41 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; public class Robot extends TimedRobot { private final PowerDistribution m_pdp = new PowerDistribution(); + @Override + public void robotInit() { + // Put the PDP itself to the dashboard + SmartDashboard.putData("PDP", m_pdp); + } + @Override public void robotPeriodic() { - /* - * Get the current going through channel 7, in Amperes. The PDP returns the - * current in increments of 0.125A. At low currents - * the current readings tend to be less accurate. - */ - SmartDashboard.putNumber("Current Channel 7", m_pdp.getCurrent(7)); + // Get the current going through channel 7, in Amperes. + // The PDP returns the current in increments of 0.125A. + // At low currents the current readings tend to be less accurate. + double current7 = m_pdp.getCurrent(7); + SmartDashboard.putNumber("Current Channel 7", current7); - /* - * Get the voltage going into the PDP, in Volts. - * The PDP returns the voltage in increments of 0.05 Volts. - */ - SmartDashboard.putNumber("Voltage", m_pdp.getVoltage()); + // Get the voltage going into the PDP, in Volts. + // The PDP returns the voltage in increments of 0.05 Volts. + double voltage = m_pdp.getVoltage(); + SmartDashboard.putNumber("Voltage", voltage); - /* - * Retrieves the temperature of the PDP, in degrees Celsius. - */ - SmartDashboard.putNumber("Temperature", m_pdp.getTemperature()); + // Retrieves the temperature of the PDP, in degrees Celsius. + double temperatureCelsius = m_pdp.getTemperature(); + SmartDashboard.putNumber("Temperature", temperatureCelsius); + + // Get the total current of all channels. + double totalCurrent = m_pdp.getTotalCurrent(); + SmartDashboard.putNumber("Total Current", totalCurrent); + + // Get the total power of all channels. + // Power is the bus voltage multiplied by the current with the units Watts. + double totalPower = m_pdp.getTotalPower(); + SmartDashboard.putNumber("Total Power", totalPower); + + // Get the total energy of all channels. + // Energy is the power summed over time with units Joules. + double totalEnergy = m_pdp.getTotalEnergy(); + SmartDashboard.putNumber("Total Energy", totalEnergy); } }