Class PDP

java.lang.Object
lib.custom.sensors.PDP

public class PDP extends Object
Simplified version of the PowerDistributionPanel class This class throws exceptions that can actually be caught Based on code from here: https://github.com/wpilibsuite/allwpilib/blob/master/hal/lib/athena/ctre/PDP.cpp
  • Field Details

    • PDP_CURRENT_PRECISION

      public static final double PDP_CURRENT_PRECISION
      See Also:
    • PDP_VOLTAGE_PRECISION

      public static final double PDP_VOLTAGE_PRECISION
      See Also:
    • DEFAULT_VOLTAGE

      protected static final double DEFAULT_VOLTAGE
      See Also:
    • DEFAULT_RESISTANCE

      protected static final double DEFAULT_RESISTANCE
      See Also:
    • PDP_ID_STATUS_1

      protected static final int PDP_ID_STATUS_1
      See Also:
    • PDP_ID_STATUS_2

      protected static final int PDP_ID_STATUS_2
      See Also:
    • PDP_ID_STATUS_3

      protected static final int PDP_ID_STATUS_3
      See Also:
    • PDP_ID_STATUS_ENERGY

      protected static final int PDP_ID_STATUS_ENERGY
      See Also:
    • status1

      protected final CustomCAN status1
    • status2

      protected final CustomCAN status2
    • status3

      protected final CustomCAN status3
    • statusEnergy

      protected final CustomCAN statusEnergy
    • cachedVoltage

      protected double cachedVoltage
    • cachedCurrent

      protected double cachedCurrent
    • cachedChannelCurrents

      protected double[] cachedChannelCurrents
    • cachedResistance

      protected double cachedResistance
    • cachedEnergy

      protected double cachedEnergy
    • cachedPower

      protected double cachedPower
    • lastRead

      protected long lastRead
  • Constructor Details

    • PDP

      public PDP(int ID)
      PDP constructor
      Parameters:
      ID - ID of the PDP. This should be the same as the ID found on the RoboRIO web console.
    • PDP

      public PDP()
      PDP constructor This defaults to the PDP at ID 0.
  • Method Details

    • getVoltage

      public double getVoltage()
      Gets the current voltage. This is the same for all channels. This function defaults to the Driver Station voltage if the PDP becomes disconnected. Note that this data will then be invalid. If you care, use the getVoltageSafely function and catch the exceptions.
      Returns:
      Current voltage.
    • getVoltageSafely

      public double getVoltageSafely() throws InvalidSensorException
      Gets the voltage on the battery.
      Returns:
      Current battery voltage.
      Throws:
      InvalidSensorException - If PDP connection is lost, InvalidSensorException will be thrown.
    • getBatteryResistance

      public double getBatteryResistance()
    • getBatteryResistanceSafely

      public double getBatteryResistanceSafely() throws InvalidSensorException
      Throws:
      InvalidSensorException
    • getTotalCurrent

      public double getTotalCurrent()
    • getTotalCurrentSafely

      public double getTotalCurrentSafely() throws InvalidSensorException
      Gets the total current used by channels 0-15 of the PDP.
      Returns:
      Total robot current used.
      Throws:
      InvalidSensorException - If PDP connection is lost, InvalidSensorException will be thrown.
    • getTotalPower

      public double getTotalPower()
      Gets the total power used by channels 0-15 of the PDP.
      Returns:
      Total robot power
    • getTotalPowerSafely

      public double getTotalPowerSafely() throws InvalidSensorException
      Gets the total power used by channels 0-15 of the PDP, throwing an exception when the PDP is disconnected.
      Returns:
      Total robot power
      Throws:
      InvalidSensorException - If PDP connection is lost, InvalidSensorException will be thrown.
    • getTotalEnergy

      public double getTotalEnergy()
      Gets the total energy used by channels 0-15 of the PDP.
      Returns:
      Total robot energy used
    • getTotalEnergySafely

      public double getTotalEnergySafely() throws InvalidSensorException
      Gets the total energy used by channels 0-15 of the PDP, throwing an exception when the PDP is disconnected.
      Returns:
      Total robot energy used
      Throws:
      InvalidSensorException - If PDP connection is lost, InvalidSensorException will be thrown.
    • getCurrentSafely

      public double getCurrentSafely(int channel) throws InvalidSensorException
      Gets the current used by a single channel.
      Parameters:
      channel - the channel to read the current for
      Returns:
      the current from that channel
      Throws:
      InvalidSensorException - if the PDP is not sending data
    • getCurrent

      public double getCurrent(int channel)
      Gets the current used by a single channel.
      Parameters:
      channel - the channel to read the current for
      Returns:
      the current from that channel