Improve generator control and status displays
This commit is contained in:
@@ -17,6 +17,7 @@ class GeneratorState:
|
||||
spool_remaining: float
|
||||
power_output_mw: float
|
||||
battery_charge: float
|
||||
status: str = "OFF"
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -32,6 +33,7 @@ class DieselGenerator:
|
||||
return
|
||||
state.starting = True
|
||||
state.spool_remaining = self.spool_time
|
||||
state.status = "STARTING"
|
||||
LOGGER.info("Generator starting (spool %.0fs)", self.spool_time)
|
||||
|
||||
def stop(self, state: GeneratorState) -> None:
|
||||
@@ -41,6 +43,7 @@ class DieselGenerator:
|
||||
state.starting = False
|
||||
state.spool_remaining = 0.0
|
||||
state.power_output_mw = 0.0
|
||||
state.status = "OFF"
|
||||
LOGGER.info("Generator stopped")
|
||||
|
||||
def step(self, state: GeneratorState, load_demand_mw: float, dt: float) -> float:
|
||||
@@ -51,12 +54,15 @@ class DieselGenerator:
|
||||
if state.spool_remaining <= 0.0:
|
||||
state.starting = False
|
||||
state.running = True
|
||||
state.status = "RUN"
|
||||
LOGGER.info("Generator online at %.1f MW", self.rated_output_mw)
|
||||
elif state.running:
|
||||
available = self.rated_output_mw
|
||||
state.power_output_mw = min(available, load_demand_mw)
|
||||
state.status = "RUN" if state.power_output_mw > 0 else "IDLE"
|
||||
else:
|
||||
state.power_output_mw = 0.0
|
||||
state.status = "OFF"
|
||||
|
||||
if state.running:
|
||||
state.battery_charge = min(1.0, state.battery_charge + 0.02 * dt)
|
||||
|
||||
Reference in New Issue
Block a user