Package lib.custom.sensors
Class PDP
java.lang.Object
lib.custom.sensors.PDP
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 Summary
FieldsModifier and TypeFieldDescriptionprotected double[]protected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected static final doubleprotected static final doubleprotected longstatic final doubleprotected static final intprotected static final intprotected static final intprotected static final intstatic final doubleprotected final CustomCANprotected final CustomCANprotected final CustomCANprotected final CustomCAN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubledoubledoublegetCurrent(int channel) Gets the current used by a single channel.doublegetCurrentSafely(int channel) Gets the current used by a single channel.doubledoubleGets the total current used by channels 0-15 of the PDP.doubleGets the total energy used by channels 0-15 of the PDP.doubleGets the total energy used by channels 0-15 of the PDP, throwing an exception when the PDP is disconnected.doubleGets the total power used by channels 0-15 of the PDP.doubleGets the total power used by channels 0-15 of the PDP, throwing an exception when the PDP is disconnected.doubleGets the current voltage.doubleGets the voltage on the battery.
-
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
-
status2
-
status3
-
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
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
- Throws:
InvalidSensorException
-
getTotalCurrent
public double getTotalCurrent() -
getTotalCurrentSafely
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
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
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
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
-