Browse Source

make use of power operator

Steffen Vogel 9 years ago
parent
commit
f7e65935fb
1 changed files with 4 additions and 6 deletions
  1. 4
    6
      Marlin/scripts/createTemperatureLookupMarlin.py

+ 4
- 6
Marlin/scripts/createTemperatureLookupMarlin.py View File

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

Loading…
Cancel
Save