Package edu.wpi.first.wpilibj
Class PowerDistribution
java.lang.Object
edu.wpi.first.wpilibj.PowerDistribution
- All Implemented Interfaces:
Sendable
,AutoCloseable
public class PowerDistribution extends Object implements Sendable, AutoCloseable
Class for getting voltage, current, temperature, power and energy from the CTRE Power
Distribution Panel (PDP) or REV Power Distribution Hub (PDH) over CAN.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PowerDistribution.ModuleType
Power distribution module type. -
Field Summary
Fields Modifier and Type Field Description static int
kDefaultModule
Default module number. -
Constructor Summary
Constructors Constructor Description PowerDistribution()
Constructs a PowerDistribution object.PowerDistribution(int module, PowerDistribution.ModuleType moduleType)
Constructs a PowerDistribution object. -
Method Summary
Modifier and Type Method Description void
clearStickyFaults()
Clear all PDP/PDH sticky faults.void
close()
double
getCurrent(int channel)
Query the current of a single channel of the PDP/PDH.PowerDistributionFaults
getFaults()
Returns the power distribution faults.int
getModule()
Gets module number (CAN ID).int
getNumChannels()
Gets the number of channels for this power distribution object.PowerDistributionStickyFaults
getStickyFaults()
Returns the power distribution sticky faults.boolean
getSwitchableChannel()
Gets whether the PDH switchable channel is turned on or off.double
getTemperature()
Query the temperature of the PDP.double
getTotalCurrent()
Query the current of all monitored channels.double
getTotalEnergy()
Query the total energy drawn from the monitored channels of the PDP.double
getTotalPower()
Query the total power drawn from the monitored channels of the PDP.PowerDistribution.ModuleType
getType()
Gets the module type for this power distribution object.PowerDistributionVersion
getVersion()
Returns the power distribution version number.double
getVoltage()
Query the input voltage of the PDP/PDH.void
initSendable(SendableBuilder builder)
Initializes thisSendable
object.void
resetTotalEnergy()
Reset the total energy to 0 of the PDP.void
setSwitchableChannel(boolean enabled)
Sets the PDH switchable channel on or off.
-
Field Details
-
kDefaultModule
Default module number.- See Also:
- Constant Field Values
-
-
Constructor Details
-
PowerDistribution
Constructs a PowerDistribution object.- Parameters:
module
- The CAN ID of the PDP/PDH.moduleType
- Module type (CTRE or REV).
-
PowerDistribution
public PowerDistribution()Constructs a PowerDistribution object.Detects the connected PDP/PDH using the default CAN ID (0 for CTRE and 1 for REV).
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
-
getNumChannels
Gets the number of channels for this power distribution object.- Returns:
- Number of output channels (16 for PDP, 24 for PDH).
-
getVoltage
Query the input voltage of the PDP/PDH.- Returns:
- The voltage in volts
-
getTemperature
Query the temperature of the PDP.Not supported on the Rev PDH and returns 0.
- Returns:
- The temperature in degrees Celsius
-
getCurrent
Query the current of a single channel of the PDP/PDH.- Parameters:
channel
- The channel (0-15 for PDP, 0-23 for PDH) to query- Returns:
- The current of the channel in Amperes
-
getTotalCurrent
Query the current of all monitored channels.- Returns:
- The current of all the channels in Amperes
-
getTotalPower
Query the total power drawn from the monitored channels of the PDP.Not supported on the Rev PDH and returns 0.
- Returns:
- the total power in Watts
-
getTotalEnergy
Query the total energy drawn from the monitored channels of the PDP.Not supported on the Rev PDH and returns 0.
- Returns:
- the total energy in Joules
-
resetTotalEnergy
Reset the total energy to 0 of the PDP.Not supported on the Rev PDH and does nothing.
-
clearStickyFaults
Clear all PDP/PDH sticky faults. -
getModule
Gets module number (CAN ID).- Returns:
- The module number (CAN ID).
-
getType
Gets the module type for this power distribution object.- Returns:
- The module type
-
getSwitchableChannel
Gets whether the PDH switchable channel is turned on or off. Returns false with the CTRE PDP.- Returns:
- The output state of the PDH switchable channel
-
setSwitchableChannel
Sets the PDH switchable channel on or off. Does nothing with the CTRE PDP.- Parameters:
enabled
- Whether to turn the PDH switchable channel on or off
-
getVersion
Returns the power distribution version number.- Returns:
- The power distribution version number.
-
getFaults
Returns the power distribution faults.- Returns:
- The power distribution faults.
-
getStickyFaults
Returns the power distribution sticky faults.- Returns:
- The power distribution sticky faults.
-
initSendable
Description copied from interface:Sendable
Initializes thisSendable
object.- Specified by:
initSendable
in interfaceSendable
- Parameters:
builder
- sendable builder
-