policy_template.py 723 B

12345678910111213141516171819202122
  1. """Minimal closed-loop policy. Change only the first line to switch backends."""
  2. from hth_sdk import Control, HTH
  3. def decide(state):
  4. valid = [t for t in state.temperatures_c if t is not None]
  5. heat = 25 if valid and max(valid) < 45 else 0
  6. return Control(fans=[20] * 4, heaters=[heat] * 4, doors={"x": 0, "y": 0, "z": 0})
  7. def run(hth: HTH, steps: int = 8) -> None:
  8. for state in hth.watch(period=0.05, count=steps):
  9. if not state.ready or not state.fresh:
  10. continue
  11. result = hth.set(decide(state))
  12. print(state.time, result.ok, state.temperatures_c[0])
  13. if __name__ == "__main__":
  14. with HTH.mock(scenario="coupled_4chamber", seed=1, speed=20) as hth:
  15. run(hth)