Class PowerDistribution

java.lang.Object
org.wpilib.hardware.power.PowerDistribution
All Implemented Interfaces:
AutoCloseable, TelemetryLoggable

public class PowerDistribution extends Object implements TelemetryLoggable, 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.
  • Field Details

    • DEFAULT_MODULE

      public static final int DEFAULT_MODULE
      Default module number.
      See Also:
  • Constructor Details

    • PowerDistribution

      public PowerDistribution(CANPort busId, int module, PowerDistribution.ModuleType moduleType)
      Constructs a PowerDistribution object.
      Parameters:
      busId - The bus ID
      module - The CAN ID of the PDP/PDH.
      moduleType - Module type (CTRE or REV).
    • PowerDistribution

      public PowerDistribution(CANPort busId)
      Constructs a PowerDistribution object.

      Detects the connected PDP/PDH using the default CAN ID (0 for CTRE and 1 for REV).

      Parameters:
      busId - The bus ID
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getNumChannels

      public int getNumChannels()
      Gets the number of channels for this power distribution object.
      Returns:
      Number of output channels (16 for PDP, 24 for PDH).
    • getVoltage

      public double getVoltage()
      Query the input voltage of the PDP/PDH.
      Returns:
      The voltage in volts
    • getTemperature

      public double getTemperature()
      Query the temperature of the PDP.

      Not supported on the Rev PDH and returns 0.

      Returns:
      The temperature in degrees Celsius
    • getCurrent

      public double getCurrent(int channel)
      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
    • getAllCurrents

      public double[] getAllCurrents()
      Query all currents of the PDP.
      Returns:
      The current of each channel in Amperes
    • getTotalCurrent

      public double getTotalCurrent()
      Query the current of all monitored channels.
      Returns:
      The current of all the channels in Amperes
    • getTotalPower

      public double 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

      public double 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

      public void resetTotalEnergy()
      Reset the total energy to 0 of the PDP.

      Not supported on the Rev PDH and does nothing.

    • clearStickyFaults

      public void clearStickyFaults()
      Clear all PDP/PDH sticky faults.
    • getModule

      public int getModule()
      Gets module number (CAN ID).
      Returns:
      The module number (CAN ID).
    • getType

      public PowerDistribution.ModuleType getType()
      Gets the module type for this power distribution object.
      Returns:
      The module type
    • getSwitchableChannel

      public boolean 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

      public void setSwitchableChannel(boolean enabled)
      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

      public PowerDistributionVersion getVersion()
      Returns the power distribution version number.
      Returns:
      The power distribution version number.
    • getFaults

      public PowerDistributionFaults getFaults()
      Returns the power distribution faults.

      On a CTRE PDP, this will return an object with no faults active.

      Returns:
      The power distribution faults.
    • getStickyFaults

      public PowerDistributionStickyFaults getStickyFaults()
      Returns the power distribution sticky faults.

      On a CTRE PDP, this will return an object with no faults active.

      Returns:
      The power distribution sticky faults.
    • logTo

      public void logTo(TelemetryTable table)
      Description copied from interface: TelemetryLoggable
      Logs the object to a TelemetryTable.
      Specified by:
      logTo in interface TelemetryLoggable
      Parameters:
      table - telemetry table
    • getTelemetryType

      public String getTelemetryType()
      Description copied from interface: TelemetryLoggable
      Gets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.
      Specified by:
      getTelemetryType in interface TelemetryLoggable
      Returns:
      Table type