Skip to content

Commit f611e19

Browse files
fletch3555virtuald
authored andcommitted
add CANPDP example
1 parent eed9a36 commit f611e19

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

canpdp/robot.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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)

run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ BASE_TESTS="
77
addressableled
88
arcade-drive
99
arm-simulation
10+
canpdp
1011
commands-v2/hatchbot
1112
commands-v2/hatchbot-inlined
1213
cscore-intermediate-vision

0 commit comments

Comments
 (0)