Skip to content
Browse files

Added P, I, and D variables #3

Bug fix for math where PID > 1.0 #4
  • Loading branch information...
1 parent 1a19746 commit 2224727c972dec2ca7836500c61f3618946b1885 @RyanPierce RyanPierce committed Sep 25, 2012
Showing with 13 additions and 4 deletions.
  1. +13 −4 chillmon
View
17 chillmon
@@ -42,6 +42,9 @@ class PID(object) :
self.fDError = None
self.fPriorError = None
+ self.fP = None
+ self.fI = None
+ self.fD = None
self.fPID = None
self.fTemp = None
@@ -60,6 +63,9 @@ class PID(object) :
'err' : nv(self.fError),
'ierr' : nv(self.fIError),
'derr' : nv(self.fDError),
+ 'p' : nv(self.fP)
+ 'i' : nv(self.fI)
+ 'd' : nv(self.fD)
'pid' : nv(self.fPID)
}
@@ -79,21 +85,24 @@ class PID(object) :
self.fPID = 0.0
# apply proportional...
- self.fPID += self.fKP * self.fError
+ self.fP = self.fKP * self.fError
# to degree-minutes
self.fIError += (self.fError * self.fPeriod) / 60.0
# apply integral...
- self.fPID += self.fKI * self.fIError
+ self.fI = self.fKI * self.fIError
if self.fPriorError is not None :
self.fDError = ((self.fError - self.fPriorError) * 60.0) / self.fPeriod
self.fPriorError = self.fError
# if we've got a derivative... apply it
if self.fDError is not None :
- self.fPID += self.fKD * self.fDError
+ self.fD = self.fKD * self.fDError
+
+ # sum it all up
+ self.fPID = self.fP + self.fI + self.fD
print time.ctime(), 'PID output: %f' % self.fPID
@@ -102,7 +111,7 @@ class PID(object) :
self.events.append((now, False))
print time.ctime(), 'no chilling, pid output way low. just turning off'
else :
- off_sec = (1.0 - self.fPID) * self.fPeriod
+ off_sec = (1.0 - min(self.fPID, 1.0)) * self.fPeriod`
off_sec = max(off_sec, self.fMinOff) # 3 minute minimum to be off
on_sec = self.fPeriod - off_sec

0 comments on commit 2224727

Please sign in to comment.
Something went wrong with that request. Please try again.