diff --git a/scripts/fan_controller.py b/scripts/fan_controller.py new file mode 100644 index 0000000..6d99850 --- /dev/null +++ b/scripts/fan_controller.py @@ -0,0 +1,57 @@ +from src.variables.service import get_variable, set_variable +from src.modules.RTD8.service import read_temp +from src.modules.IndustrialAutomation.service_analog import read_0_10_out, set_0_10_out + +fans = [ + { + "inputs": [ + { + "stack": 1, + "channel": 1 + }, + { + "stack": 1, + "channel": 2 + } + ], + "temp_min": 40, #minimum temp for fan_min + "temp_max": 70, #maximum temp for fan_max + "fan_min": 0, #fan minimum 0-10V set + "fan_max": 10, #fan maximum 0-10V set + "output_stack": 0, #stack card + "output_channel": 2 #card channel + } +] + + +def max_temp(channels: list) -> float: + temp: float = 0 + for channel in channels: + temp_ch = read_temp(stack=channel["stack"], channel=channel["channel"]) + if temp < temp_ch: + temp = temp_ch + + return temp + + +def fan_control(): + for fan in fans: + temp = max_temp(fan["inputs"]) + + if temp > fan["temp_max"]: + set_0_10_out(stack=fan["output_stack"], channel=fan["output_channel"], value=10) + elif temp < fan["temp_min"]: + set_0_10_out(stack=fan["output_stack"], channel=fan["output_channel"], value=0) + else: + temp_calc = temp - fan["temp_min"] + temp_max_calc = fan["temp_max"] - fan["temp_min"] + calc_out = round(temp_calc / temp_max_calc, 4) * 10 + set_0_10_out(stack=fan["output_stack"], channel=fan["output_channel"], value=calc_out) + + + + + + + + diff --git a/scripts/timer.py b/scripts/timer.py index f31a6cd..85b7d72 100644 --- a/scripts/timer.py +++ b/scripts/timer.py @@ -10,9 +10,14 @@ if bool(os.getenv("BACKGROUND_SCRIPTS_RUN", 0)): scheduler.start() +#control speed from scripts.speed_controller import rpm_control scheduler.add_job(rpm_control, trigger=IntervalTrigger(seconds=0.2)) +#control fans +from scripts.fan_controller import fan_control +scheduler.add_job(fan_control, trigger=IntervalTrigger(minutes=1)) +