Added scripts/fan_controller.py - fan control
This commit is contained in:
parent
c6b047cc0c
commit
85c87b1b2a
2 changed files with 62 additions and 0 deletions
57
scripts/fan_controller.py
Normal file
57
scripts/fan_controller.py
Normal file
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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))
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue