Repository navigation
Expand file tree
/
Copy pathalgorithm.py
More file actions
55 lines (51 loc) · 1.91 KB
/
Copy pathalgorithm.py
File metadata and controls
55 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# This file is part of pwm_fanshim.
# Copyright (C) 2015 Ivmech Mechatronics Ltd. <bilgi@ivmech.com>
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# title :algorithm.py
# description :pwm control sauna heater
# author :David Torrens
# start date :2019 12 12
# version :0.1
# python_version :3
# Notes
#
class class_control: # for calc of freq and speed
def __init__(self, config):
self.config = config
self.freq = config.min_freq
self.speed = 0
self.heater_on = False
def calc(self,temp):
# Following gives 0 to 1 over range min_temp to max_temp
self.throttle = 100*(self.config.max_temp - temp)/(self.config.max_temp - self.config.min_temp)
if self.throttle < 0 :
# Fan Off
self.freq = self.config.min_freq
self.speed = self.config.min_speed
self.throttle = 1
self.heater_on = True
elif self.throttle > 100 :
# Fan at Max
self.freq = self.config.max_freq
self.speed = self.config.max_speed
self.throttle = 100
self.heater_on = True
else:
# Fan "Throttled" between Min_speed and max_speed
# Simarly for frequency
self.freq = (self.throttle*(self.config.max_freq - self.config.min_freq)/100) + self.config.min_freq
self.speed = (self.throttle*(self.config.max_speed - self.config.min_speed)/100) + self.config.min_speed
self.heater_on = True