|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | + This is a sample program showing how to retrieve information from the Power |
| 4 | + Distribution Panel via CAN. The information will be displayed under variables |
| 5 | + through the SmartDashboard. |
| 6 | +""" |
| 7 | + |
| 8 | +import wpilib |
| 9 | +import wpilib.drive |
| 10 | + |
| 11 | + |
| 12 | +class MyRobot(wpilib.TimedRobot): |
| 13 | + def robotInit(self): |
| 14 | + """Robot initialization function""" |
| 15 | + |
| 16 | + # Object for dealing with the Power Distribution Panel (PDP). |
| 17 | + self.pdp = wpilib.PowerDistribution() |
| 18 | + |
| 19 | + # Put the PDP itself to the dashboard |
| 20 | + wpilib.SmartDashboard.putData("PDP", self.pdp) |
| 21 | + |
| 22 | + def robotPeriodic(self): |
| 23 | + # Get the current going through channel 7, in Amperes. |
| 24 | + # The PDP returns the current in increments of 0.125A. |
| 25 | + # At low currents the current readings tend to be less accurate. |
| 26 | + current7 = self.pdp.getCurrent(7) |
| 27 | + wpilib.SmartDashboard.putNumber("Current Channel 7", current7) |
| 28 | + |
| 29 | + # Get the voltage going into the PDP, in Volts. |
| 30 | + # The PDP returns the voltage in increments of 0.05 Volts. |
| 31 | + voltage = self.pdp.getVoltage() |
| 32 | + wpilib.SmartDashboard.putNumber("Voltage", voltage) |
| 33 | + |
| 34 | + # Retrieves the temperature of the PDP, in degrees Celsius. |
| 35 | + temperatureCelsius = self.pdp.getTemperature() |
| 36 | + wpilib.SmartDashboard.putNumber("Temperature", temperatureCelsius) |
| 37 | + |
| 38 | + # Get the total current of all channels. |
| 39 | + totalCurrent = self.pdp.getTotalCurrent() |
| 40 | + wpilib.SmartDashboard.putNumber("Total Current", totalCurrent) |
| 41 | + |
| 42 | + # Get the total power of all channels. |
| 43 | + # Power is the bus voltage multiplied by the current with the units Watts. |
| 44 | + totalPower = self.pdp.getTotalPower() |
| 45 | + wpilib.SmartDashboard.putNumber("Total Power", totalPower) |
| 46 | + |
| 47 | + # Get the total energy of all channels. |
| 48 | + # Energy is the power summed over time with units Joules. |
| 49 | + totalEnergy = self.pdp.getTotalEnergy() |
| 50 | + wpilib.SmartDashboard.putNumber("Total Energy", totalEnergy) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + wpilib.run(MyRobot) |
0 commit comments