Skip to content

Commit

Permalink
Added P, I, and D variables #3
Browse files Browse the repository at this point in the history
Bug fix for math where PID > 1.0 #4
  • Loading branch information
RyanPierce committed Sep 26, 2012
1 parent 1a19746 commit 2224727
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions chillmon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 2224727

Please sign in to comment.