Package trclib.sensor
Class TrcRobotBattery
java.lang.Object
trclib.sensor.TrcRobotBattery
- Direct Known Subclasses:
FtcRobotBattery
This class monitors the robot battery level and provides methods to get the current battery voltage as well as
the lowest voltage it has ever seen during the monitoring session.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private double
private double
private double
private double
private double
private double
private double
private boolean
private final TrcTaskMgr.TaskObject
private double
private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionTrcRobotBattery
(boolean voltageSupported, boolean currentSupported, boolean powerSupported) Constructor: create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionabstract double
This method returns the robot battery current.double
This method returns the highest current it has ever seen during the monitoring session.double
This method returns the highest power it has ever seen during the monitoring session.double
This method returns the highest voltage it has ever seen during the monitoring session.double
This method returns the lowest current it has ever seen during the monitoring session.double
This method returns the lowest power it has ever seen during the monitoring session.double
This method returns the lowest voltage it has ever seen during the monitoring session.abstract double
getPower()
This method returns the robot battery power.double
This method returns the total energy consumed since the task was enabled.abstract double
This method returns the robot battery voltage.private void
robotBatteryTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to monitor the battery voltage and to keep track of the lowest voltage it has ever seen.void
setEnabled
(boolean enabled) This method enables/disables the battery monitoring task.toString()
This method returns the state of the battery in a string.
-
Field Details
-
voltageSupported
private boolean voltageSupported -
currentSupported
private boolean currentSupported -
powerSupported
private boolean powerSupported -
robotBatteryTaskObj
-
lowestVoltage
private double lowestVoltage -
highestVoltage
private double highestVoltage -
lowestCurrent
private double lowestCurrent -
highestCurrent
private double highestCurrent -
lowestPower
private double lowestPower -
highestPower
private double highestPower -
totalEnergy
private double totalEnergy -
lastTimestamp
private double lastTimestamp
-
-
Constructor Details
-
TrcRobotBattery
public TrcRobotBattery(boolean voltageSupported, boolean currentSupported, boolean powerSupported) Constructor: create an instance of the object.- Parameters:
voltageSupported
- specifies true if getVoltage is supported, false otherwise.currentSupported
- specifies true if getCurrent is supported, false otherwise.powerSupported
- specifies true if getPower is supported, false otherwise.
-
-
Method Details
-
getVoltage
public abstract double getVoltage()This method returns the robot battery voltage.- Returns:
- robot battery voltage in volts.
-
getCurrent
public abstract double getCurrent()This method returns the robot battery current.- Returns:
- robot battery current in amps.
-
getPower
public abstract double getPower()This method returns the robot battery power.- Returns:
- robot battery power in watts.
-
toString
This method returns the state of the battery in a string. -
setEnabled
public void setEnabled(boolean enabled) This method enables/disables the battery monitoring task. When the task is enabled, it also clears the lowest voltage.- Parameters:
enabled
- specifies true to enable the task, false to disable.
-
getLowestVoltage
public double getLowestVoltage()This method returns the lowest voltage it has ever seen during the monitoring session.- Returns:
- lowest battery voltage.
- Throws:
UnsupportedOperationException
- if voltage is not supported by the system.
-
getHighestVoltage
public double getHighestVoltage()This method returns the highest voltage it has ever seen during the monitoring session.- Returns:
- highest battery voltage.
- Throws:
UnsupportedOperationException
- if voltage is not supported by the system.
-
getLowestCurrent
public double getLowestCurrent()This method returns the lowest current it has ever seen during the monitoring session.- Returns:
- lowest battery current.
- Throws:
UnsupportedOperationException
- if current is not supported by the system.
-
getHighestCurrent
public double getHighestCurrent()This method returns the highest current it has ever seen during the monitoring session.- Returns:
- highest battery current.
- Throws:
UnsupportedOperationException
- if current is not supported by the system.
-
getLowestPower
public double getLowestPower()This method returns the lowest power it has ever seen during the monitoring session.- Returns:
- lowest battery power.
- Throws:
UnsupportedOperationException
- if power is not supported by the system.
-
getHighestPower
public double getHighestPower()This method returns the highest power it has ever seen during the monitoring session.- Returns:
- highest battery power.
- Throws:
UnsupportedOperationException
- if power is not supported by the system.
-
getTotalEnergy
public double getTotalEnergy()This method returns the total energy consumed since the task was enabled.- Returns:
- total energy consumed in WH (Watt-Hour).
-
robotBatteryTask
private void robotBatteryTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to monitor the battery voltage and to keep track of the lowest voltage it has ever seen.- 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.
-