Przeglądaj źródła

make use of power operator

Steffen Vogel 9 lat temu
rodzic
commit
f7e65935fb
1 zmienionych plików z 4 dodań i 6 usunięć
  1. 4
    6
      Marlin/scripts/createTemperatureLookupMarlin.py

+ 4
- 6
Marlin/scripts/createTemperatureLookupMarlin.py Wyświetl plik

@@ -26,7 +26,7 @@ import getopt
26 26
 ZERO   = 273.15                             # zero point of Kelvin scale
27 27
 VADC   = 5                                  # ADC voltage
28 28
 VCC    = 5                                  # supply voltage
29
-ARES   = pow(2,10)                          # 10 Bit ADC resolution
29
+ARES   = 2**10                              # 10 Bit ADC resolution
30 30
 VSTEP  = VADC / ARES                        # ADC voltage resolution
31 31
 TMIN   = 0                                  # lowest temperature in table
32 32
 TMAX   = 350                                # highest temperature in table
@@ -43,8 +43,6 @@ class Thermistor:
43 43
         x = (y2 - y1) / (l2 - l1)
44 44
         y = (y3 - y1) / (l3 - l1)
45 45
         c = (y - x) / ((l3 - l2) * (l1 + l2 + l3))
46
-        b = x - c * (pow(l1,2) + pow(l2,2) + l1*l2)
47
-        a = y1 - (b + pow(l1,2)*c)*l1
48 46
         self.c1 = a                         # Steinhart-Hart coefficients
49 47
         self.c2 = b
50 48
         self.c3 = c
@@ -67,14 +65,14 @@ class Thermistor:
67 65
     def temp(self, adc):
68 66
         "Convert ADC reading into a temperature in Celcius"
69 67
         l = log(self.resist(adc))
70
-        Tinv = self.c1 + self.c2*l + self.c3*pow(l,3) # inverse temperature
68
+        Tinv = self.c1 + self.c2*l + self.c3* l**3) # inverse temperature
71 69
         return (1/Tinv) - ZERO              # temperature
72 70
 
73 71
     def adc(self, temp):
74 72
         "Convert temperature into a ADC reading"
75 73
         x = (self.c1 - (1.0 / (temp+ZERO))) / (2*self.c3)
76
-        y = sqrt(pow(self.c2 / (3*self.c3),3) + pow(x,2))
77
-        r = exp(pow(y-x,1.0/3) - pow(y+x,1.0/3)) # resistance of thermistor
74
+        y = sqrt((self.c2 / (3*self.c3)**3 + x**2)
75
+        r = exp((y-x)**(1.0/3) - (y+x)**(1.0/3))
78 76
         return (r / (self.rp + r)) * ARES
79 77
 
80 78
 def main(argv):

Ładowanie…
Anuluj
Zapisz