From e1ccc7e6a04d5ae2cb91102f11502f682d8276b9 Mon Sep 17 00:00:00 2001 From: Adrien DELSALLE Date: Tue, 1 Mar 2022 09:49:15 +0100 Subject: [PATCH] use events in fan controler fix typos --- demos/cpu/cpu/systems/__init__.py | 2 +- demos/cpu/cpu/systems/cpusystem.py | 4 ++-- .../{fancontroller.py => fancontroler.py} | 21 +++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) rename demos/cpu/cpu/systems/{fancontroller.py => fancontroler.py} (51%) diff --git a/demos/cpu/cpu/systems/__init__.py b/demos/cpu/cpu/systems/__init__.py index fbaafe2..567b3fd 100644 --- a/demos/cpu/cpu/systems/__init__.py +++ b/demos/cpu/cpu/systems/__init__.py @@ -1,5 +1,5 @@ from .cpu import CPU from .heatexchanger import HeatExchanger -from .fancontroller import FanController +from .fancontroler import FanControler from .fan import Fan from .cpusystem import CPUSystem diff --git a/demos/cpu/cpu/systems/cpusystem.py b/demos/cpu/cpu/systems/cpusystem.py index f8522bd..a7409f4 100644 --- a/demos/cpu/cpu/systems/cpusystem.py +++ b/demos/cpu/cpu/systems/cpusystem.py @@ -1,6 +1,6 @@ from cosapp.systems import System -from cpu.systems import CPU, HeatExchanger, Fan, FanController +from cpu.systems import CPU, HeatExchanger, Fan, FanControler class CPUSystem(System): @@ -8,7 +8,7 @@ class CPUSystem(System): def setup(self): # children - self.add_child(FanController("controler")) + self.add_child(FanControler("controler")) self.add_child(Fan("fan")) self.add_child(HeatExchanger("exchanger")) self.add_child(CPU("cpu"), pulling={"T" : "T_cpu"}) diff --git a/demos/cpu/cpu/systems/fancontroller.py b/demos/cpu/cpu/systems/fancontroler.py similarity index 51% rename from demos/cpu/cpu/systems/fancontroller.py rename to demos/cpu/cpu/systems/fancontroler.py index 468bc3d..6df998d 100644 --- a/demos/cpu/cpu/systems/fancontroller.py +++ b/demos/cpu/cpu/systems/fancontroler.py @@ -1,7 +1,7 @@ from cosapp.systems import System -class FanController(System): +class FanControler(System): """ Define tension for fan from the level of CPU temperature """ @@ -13,14 +13,23 @@ def setup(self): self.add_inward("low_tension", 0.0, unit="V", desc="Output low tension") self.add_inward("medium_tension", 6.0, unit="V", desc="Output medium tension") self.add_inward("max_tension", 12.0, unit="V", desc="Output max tension") + self.add_inward("tension_command", 12.0, unit="V", desc="Output command tension") # outputs self.add_outward("tension", 0.0, unit="V", desc="Output tension") + self.add_event('null_to_low_tension', trigger="T >= low_threshold") + self.add_event('low_to_max_tension', trigger="T >= high_threshold") + self.add_event('low_to_null_tension', trigger="T <= low_threshold") + self.add_event('max_to_low_tension', trigger="T <= high_threshold") + def compute(self): - if self.T_cpu <= self.low_threshold: - self.tension = self.low_tension - elif self.T_cpu <= self.high_threshold: - self.tension = self.medium_tension + self.tension = self.tension_command + + def transition(self): + if self.low_to_null_tension.present: + self.tension_command = 0. + elif self.null_to_low_tension.present or self.max_to_low_tension.present: + self.tension_command = self.medium_tension else: - self.tension = self.max_tension + self.tension_command = self.max_tension