Package trclib.sensor

Class TrcRobotBattery

java.lang.Object
trclib.sensor.TrcRobotBattery
Direct Known Subclasses:
FtcRobotBattery

public abstract class TrcRobotBattery extends Object
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 Details

    • voltageSupported

      private boolean voltageSupported
    • currentSupported

      private boolean currentSupported
    • powerSupported

      private boolean powerSupported
    • robotBatteryTaskObj

      private final TrcTaskMgr.TaskObject 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

      public String toString()
      This method returns the state of the battery in a string.
      Overrides:
      toString in class Object
    • 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.