2024-12-12 14:59:04 +01:00
|
|
|
from src.variables.service import get_variable, set_variable
|
|
|
|
from src.modules.RTD8.service import read_temp
|
2025-01-16 14:16:13 +01:00
|
|
|
from src.modules.IndustrialAutomation.service_analog import set_0_10_out
|
2024-12-12 14:59:04 +01:00
|
|
|
|
|
|
|
fans = [
|
|
|
|
{
|
2025-01-16 14:16:13 +01:00
|
|
|
"inputs": [ #temperature inputs
|
2024-12-12 14:59:04 +01:00
|
|
|
{
|
2025-01-16 14:16:13 +01:00
|
|
|
"type": "RTD", #Card type
|
|
|
|
"stack": 1, #Card stack
|
|
|
|
"channel": 1 #Card channel
|
2024-12-12 14:59:04 +01:00
|
|
|
},
|
|
|
|
{
|
2025-01-16 14:16:13 +01:00
|
|
|
"type": "RTD", #Card type
|
|
|
|
"stack": 1, #Card stack
|
|
|
|
"channel": 2 #Card channel
|
2024-12-12 14:59:04 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2025-01-16 14:19:27 +01:00
|
|
|
def get_temp(channel: dict) -> float:
|
2025-01-16 14:16:13 +01:00
|
|
|
match channel["type"]:
|
|
|
|
case "RTD":
|
|
|
|
return read_temp(stack=channel["stack"], channel=channel["channel"])
|
|
|
|
case _:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2024-12-12 14:59:04 +01:00
|
|
|
def max_temp(channels: list) -> float:
|
|
|
|
temp: float = 0
|
|
|
|
for channel in channels:
|
2025-01-16 14:16:13 +01:00
|
|
|
temp_ch = get_temp(channel=channel)
|
2024-12-12 14:59:04 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|