Overflow bug if PID > 1 or < 1 #4

RyanPierce opened this Issue Sep 26, 2012 · 0 comments


None yet
1 participant

RyanPierce commented Sep 26, 2012

The following code breaks if PID becomes > 1.0

off_sec = (1.0 - self.fPID) * self.fPeriod
off_sec = max(off_sec, self.fMinOff)
on_sec = self.fPeriod - off_sec

So off_sec becomes negative in the case that self.fPID > 1 in the first line. In the second line it gets set to self.fMinOff. So the right thing happens, but it isn't exactly clean.

In the case where PID becomes negative, off_sec becomes > self.fPeriod. This means on_sec becomes a negative number. I'm not sure what the code would do here; the following code would be called:

self.events.append((now, True))
self.events.append((now + on_sec, False))

So the chiller is supposed to turn off before it turns on. I'm guessing this is an unsorted array, so this would result in the pin going high then low immediately.

@RyanPierce RyanPierce added a commit that referenced this issue Sep 26, 2012

@RyanPierce RyanPierce Added P, I, and D variables #3
Bug fix for math where PID > 1.0 #4

RyanPierce closed this Sep 26, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment