feat(phase-5): implement battery model, charging queues, production deadlines, and safe reassignment
This commit is contained in:
@@ -135,6 +135,9 @@ class Robot:
|
||||
allowed_zones: Set[str] = field(default_factory=lambda: {"zone_a", "zone_b", "zone_c"})
|
||||
state_enter_time: float = 0.0
|
||||
yaw_degrees: float = 0.0
|
||||
min_battery_percent: float = 100.0
|
||||
total_energy_consumed_kwh: float = 0.0
|
||||
total_energy_charged_kwh: float = 0.0
|
||||
|
||||
@classmethod
|
||||
def from_fleet_dict(cls, fleet_data: Dict[str, Any], type_specs: Dict[str, RobotTypeSpec]) -> Robot:
|
||||
@@ -147,7 +150,7 @@ class Robot:
|
||||
battery_pct = float(fleet_data.get("initial_battery_percent", 100.0))
|
||||
initial_battery = (battery_pct / 100.0) * spec.battery_capacity_kwh
|
||||
|
||||
return cls(
|
||||
robot = cls(
|
||||
robot_id=fleet_data["robot_id"],
|
||||
robot_type=robot_type_id,
|
||||
position=Position3D.from_iterable(fleet_data.get("initial_position", [0.0, 0.0, 0.0])),
|
||||
@@ -158,6 +161,8 @@ class Robot:
|
||||
energy_consumption=dict(spec.power_consumption_kw),
|
||||
allowed_zones=set(spec.allowed_zones),
|
||||
)
|
||||
robot.min_battery_percent = robot.battery_percent
|
||||
return robot
|
||||
|
||||
@property
|
||||
def battery_percent(self) -> float:
|
||||
@@ -280,19 +285,39 @@ class Robot:
|
||||
"""Complete active task and clear binding."""
|
||||
self.release_task()
|
||||
|
||||
def consume_energy(self, duration_seconds: float, mode: str = "moving_empty") -> float:
|
||||
def consume_energy(
|
||||
self,
|
||||
duration_seconds: float,
|
||||
mode: str = "moving_empty",
|
||||
payload_kg: float = 0.0,
|
||||
) -> float:
|
||||
"""Deduct energy consumed over duration according to active power mode.
|
||||
|
||||
For 'moving_loaded', scales power consumption proportionally with actual payload.
|
||||
|
||||
Args:
|
||||
duration_seconds: Time interval in seconds.
|
||||
mode: Power consumption mode ('idle', 'moving_empty', 'moving_loaded', 'handling').
|
||||
payload_kg: Active payload weight in kg (used if mode is 'moving_loaded').
|
||||
|
||||
Returns:
|
||||
Energy consumed in kWh.
|
||||
"""
|
||||
power_kw = self.energy_consumption.get(mode, 0.1)
|
||||
if mode == "moving_loaded":
|
||||
p_empty = self.energy_consumption.get("moving_empty", 0.35)
|
||||
p_loaded_max = self.energy_consumption.get("moving_loaded", 0.65)
|
||||
if self.payload_capacity > 0.0 and payload_kg > 0.0:
|
||||
fraction = min(1.0, max(0.0, payload_kg / self.payload_capacity))
|
||||
power_kw = p_empty + (p_loaded_max - p_empty) * fraction
|
||||
else:
|
||||
power_kw = p_loaded_max
|
||||
else:
|
||||
power_kw = self.energy_consumption.get(mode, 0.1)
|
||||
|
||||
energy_kwh = (power_kw * duration_seconds) / 3600.0
|
||||
self.battery_level = max(0.0, self.battery_level - energy_kwh)
|
||||
self.total_energy_consumed_kwh += energy_kwh
|
||||
self.min_battery_percent = min(self.min_battery_percent, self.battery_percent)
|
||||
return energy_kwh
|
||||
|
||||
def charge_energy(self, duration_seconds: float, charging_rate_kw: float) -> float:
|
||||
@@ -305,4 +330,18 @@ class Robot:
|
||||
new_level = min(self.battery_capacity, self.battery_level + energy_kwh)
|
||||
added = new_level - self.battery_level
|
||||
self.battery_level = new_level
|
||||
self.total_energy_charged_kwh += added
|
||||
return added
|
||||
|
||||
def is_low_battery(self, threshold_pct: float = 25.0) -> bool:
|
||||
"""Check if State of Charge has reached or fallen below mandatory charging threshold."""
|
||||
return self.battery_percent <= threshold_pct + 1e-4
|
||||
|
||||
def is_critical_battery(self, threshold_pct: float = 15.0) -> bool:
|
||||
"""Check if State of Charge has dropped to critical emergency shutdown threshold."""
|
||||
return self.battery_percent <= threshold_pct + 1e-4
|
||||
|
||||
def needs_opportunistic_charge(self, threshold_pct: float = 60.0) -> bool:
|
||||
"""Check if robot is eligible for opportunistic top-up charging when idle."""
|
||||
return self.battery_percent <= threshold_pct + 1e-4
|
||||
|
||||
|
||||
Reference in New Issue
Block a user