Class SimulatedBattery

java.lang.Object
org.ironmaple.simulation.motorsims.SimulatedBattery

public class SimulatedBattery extends Object

Simulates the main battery of the robot.

This class simulates the behavior of a robot's battery. Electrical appliances can be added to the battery to draw current. The battery voltage is affected by the current drawn from various appliances.

  • Constructor Details

    • SimulatedBattery

      public SimulatedBattery()
  • Method Details

    • addElectricalAppliances

      public static void addElectricalAppliances(Supplier<Current> customElectricalAppliances)

      Adds a custom electrical appliance.

      Connects the electrical appliance to the battery, allowing it to draw current from the battery.

      Parameters:
      customElectricalAppliances - The supplier for the current drawn by the appliance.
    • addMotor

      public static void addMotor(MapleMotorSim mapleMotorSim)

      Adds a motor to the list of electrical appliances.

      The motor will draw current from the battery.

      Parameters:
      mapleMotorSim - The motor simulation object.
    • simulationSubTick

      public static void simulationSubTick()

      Updates the battery simulation.

      Calculates the battery voltage based on the current drawn by all appliances.

      The battery voltage is clamped to avoid going below the brownout voltage.

    • getBatteryVoltage

      public static Voltage getBatteryVoltage()

      Obtains the voltage of the battery.

      Returns:
      The battery voltage as a Voltage object.
    • getTotalCurrentDrawn

      public static Current getTotalCurrentDrawn()

      Obtains the total current drawn from the battery.

      Iterates through all the appliances to obtain the total current used.

      Returns:
      The total current as a Current object.
    • clamp

      public static Voltage clamp(Voltage voltage)

      Clamps the voltage according to the supplied voltage and the battery's capabilities.

      If the supplied voltage exceeds the battery's maximum voltage, it will be reduced to match the battery's voltage.

      Parameters:
      voltage - The voltage to be clamped.
      Returns:
      The clamped voltage as a Voltage object.