Quote:
Originally Posted by team-4480
I don't see how that would work if I were to give the input as 90, it would go through and then self.last would become 90 and then it wouldn't do anything because 90-90 is 0. For me, in order to get that to work, self.last would have to be set like this self.last = self.gyro.getYaw(). But I really don't know what I am doing with setting up PID loops so I could(and probably am) dead wrong.
|
My bad, I should have named the variable 'target', not 'input' (I've changed it above). It's the value that you pass to setSetpoint. Working through the code:
Let's say your target value is 90.
First iteration: self.last is None, setSetpoint would be called
Second iteration: self.last is 90, setSetpoint would not be called
Third iteration: self.last is 90, setSetpoint would not be called
... and so on
However, the setpoint does not get changed -- so the PIDController will still be trying to converge the output to the last setpoint that was set (which is 90). And more importantly, onTarget will work correctly, because it isn't getting reset by the call to setSetpoint.