Class SimulatedBattery
java.lang.Object
org.ironmaple.simulation.motorsims.SimulatedBattery
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addElectricalAppliances
(Supplier<Current> customElectricalAppliances) Adds a custom electrical appliance.static void
addMotor
(MapleMotorSim mapleMotorSim) Adds a motor to the list of electrical appliances.static Voltage
Clamps the voltage according to the supplied voltage and the battery's capabilities.static Voltage
Obtains the voltage of the battery.static Current
Obtains the total current drawn from the battery.static void
Updates the battery simulation.
-
Constructor Details
-
SimulatedBattery
public SimulatedBattery()
-
-
Method Details
-
addElectricalAppliances
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
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
Obtains the voltage of the battery.
- Returns:
- The battery voltage as a
Voltage
object.
-
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
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.
-