scenarios.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Named Mock scenarios.
  2. SIMULATION ONLY
  3. NOT IDENTIFIED FROM REAL HARDWARE
  4. NOT A PHYSICAL VALIDATION MODEL
  5. """
  6. from __future__ import annotations
  7. from dataclasses import dataclass
  8. SCENARIO_NAMES = (
  9. "normal",
  10. "coupled_4chamber",
  11. "sensor_invalid",
  12. "sensor_stale",
  13. "startup_delay",
  14. "disconnect_recover",
  15. "safe_mode",
  16. "actuator_clamp",
  17. "slow_consumer",
  18. )
  19. @dataclass(frozen=True)
  20. class ScenarioSpec:
  21. name: str
  22. coupling: float = 0.01
  23. invalid_channels: tuple[int, ...] = ()
  24. stale: bool = False
  25. startup_delay_s: float = 0.0
  26. disconnect_after_s: float = 0.0
  27. recover_after_s: float = 0.0
  28. start_safe: bool = False
  29. clamp_heaters: float = 100.0
  30. tick_s: float = 0.05
  31. noise_c: float = 0.0
  32. fresh_horizon_s: float = 3.0
  33. def scenario_spec(name: str) -> ScenarioSpec:
  34. key = (name or "normal").strip().lower()
  35. if key not in SCENARIO_NAMES:
  36. raise ValueError(f"unknown scenario {name!r}; choose one of {SCENARIO_NAMES}")
  37. if key == "coupled_4chamber":
  38. return ScenarioSpec(name=key, coupling=0.06)
  39. if key == "sensor_invalid":
  40. return ScenarioSpec(name=key, invalid_channels=(3, 11, 26))
  41. if key == "sensor_stale":
  42. return ScenarioSpec(name=key, stale=True, fresh_horizon_s=0.0)
  43. if key == "startup_delay":
  44. return ScenarioSpec(name=key, startup_delay_s=0.4)
  45. if key == "disconnect_recover":
  46. return ScenarioSpec(name=key, disconnect_after_s=0.2, recover_after_s=0.5)
  47. if key == "safe_mode":
  48. return ScenarioSpec(name=key, start_safe=True)
  49. if key == "actuator_clamp":
  50. return ScenarioSpec(name=key, clamp_heaters=80.0)
  51. if key == "slow_consumer":
  52. return ScenarioSpec(name=key, tick_s=0.2)
  53. return ScenarioSpec(name="normal")