Package frclib.sensor
Class FrcPdp
java.lang.Object
edu.wpi.first.wpilibj.PowerDistribution
frclib.sensor.FrcPdp
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable
,AutoCloseable
public class FrcPdp
extends edu.wpi.first.wpilibj.PowerDistribution
This class extends the WPI PowerDistricbutonPanel class to provide monitoring of energy consumption of registered
power channel.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class contains the info of a PDP channel.Nested classes/interfaces inherited from class edu.wpi.first.wpilibj.PowerDistribution
edu.wpi.first.wpilibj.PowerDistribution.ModuleType
-
Field Summary
Fields inherited from class edu.wpi.first.wpilibj.PowerDistribution
kDefaultModule
-
Constructor Summary
ConstructorsConstructorDescriptionFrcPdp
(int canId, edu.wpi.first.wpilibj.PowerDistribution.ModuleType moduleType) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
energyUsedTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to integrate the power consumption of each channel.getChannelName
(int channel) This method returns the name of the registered PDP channel.double
getEnergyUsed
(int channel) This method returns the energy consumed so far by the specified channel in the unit of Watt-Hour.edu.wpi.first.util.sendable.Sendable
boolean
registerEnergyUsed
(int channel, String name) This method registers a PDP channel for monitoring its energy used.boolean
registerEnergyUsed
(FrcPdp.Channel... channels) This method registers a PDP channel for monitoring its energy used.void
This method registers all currently unregistered PDP channels for monitoring its energy used with a default name based on the channel number.void
setTaskEnabled
(boolean enabled) This method enables/disables the energy monitoring task.void
This method unregisters all PDP channel for monitoring its energy used.boolean
unregisterEnergyUsed
(int channel) This method unregisters a PDP channel for monitoring its energy used.Methods inherited from class edu.wpi.first.wpilibj.PowerDistribution
clearStickyFaults, close, getAllCurrents, getCurrent, getFaults, getModule, getNumChannels, getStickyFaults, getSwitchableChannel, getTemperature, getTotalCurrent, getTotalEnergy, getTotalPower, getType, getVersion, getVoltage, initSendable, resetTotalEnergy, setSwitchableChannel
-
Constructor Details
-
FrcPdp
public FrcPdp(int canId, edu.wpi.first.wpilibj.PowerDistribution.ModuleType moduleType) Constructor: Creates an instance of the object.- Parameters:
canId
- specifies the CAN ID of the PDP.moduleType
- specifies the module type (automatic, CTRE, or REV).
-
-
Method Details
-
setTaskEnabled
public void setTaskEnabled(boolean enabled) This method enables/disables the energy monitoring task. When the task is enabled, it also clears the totalEnergyUsed array.- Parameters:
enabled
- specifies true to enable the task, false to disable.
-
registerEnergyUsed
This method registers a PDP channel for monitoring its energy used.- Parameters:
channel
- specifies the channel to be registered.name
- specifies the channel name.- Returns:
- true if registered successfully, false if channel is invalid or already registered.
-
registerEnergyUsed
This method registers a PDP channel for monitoring its energy used.- Parameters:
channelInfo
- specifies the array of channels to be registered.- Returns:
- true if registered successfully, false if channel is invalid or already registered.
-
registerEnergyUsedForAllUnregisteredChannels
public void registerEnergyUsedForAllUnregisteredChannels()This method registers all currently unregistered PDP channels for monitoring its energy used with a default name based on the channel number. -
unregisterEnergyUsed
public boolean unregisterEnergyUsed(int channel) This method unregisters a PDP channel for monitoring its energy used.- Parameters:
channel
- specifies the channel to be unregistered.- Returns:
- true if unregistered successfully, false if channel is not registered.
-
unregisterAllEnergyUsed
public void unregisterAllEnergyUsed()This method unregisters all PDP channel for monitoring its energy used. -
getEnergyUsed
public double getEnergyUsed(int channel) This method returns the energy consumed so far by the specified channel in the unit of Watt-Hour.- Parameters:
channel
- specifies the PDP channel.- Returns:
- energy consumed by the channel in Watt-Hour if registered, null if not registered.
-
getChannelName
This method returns the name of the registered PDP channel.- Parameters:
channel
- specifies the PDP channel.- Returns:
- PDP channel name if registered, null if not registered.
-
energyUsedTask
public void energyUsedTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to integrate the power consumption of each channel.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is running.slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-
getPdpSendable
public edu.wpi.first.util.sendable.Sendable getPdpSendable()
-