![]() |
Why won't this PID loop stop?
Hi,
I am trying pretty hard to get this PID loop for a turnaround button using this nice example. The problem I am having is that no matter what I set the kToleranceDegrees to, the robot will still oscillate back and forth when I know for sure that it is within my tolerance. Am I forgetting to do something? I don't feel like adjusting the PID values will do anything because the robot won't even stop when the target is 90 degrees, the gyro reads 89.4 degrees and the tolerance is 10 degrees! What am I do wrong? Thanks! |
Re: Why won't this PID loop stop?
Quote:
The loop does not automatically stop when you're within tolerance of the setpoint. Rather, the tolerance setting is used by the onTarget() function to determine whether or not you have reached your setpoint. If you wish to stop the loop once you've reached your setpoint, you'll have to write code to disable the PID controller once onTarget() returns true. Note that you can also set a buffer length for your PID controller which will require that the average over n interations of your main loop be within the tolerance of the setpoint for onTarget() to return true, which is a good idea to prevent the loop from disabling if it overshoots the setpoint. However, you should not need to disable the PID loop to eliminate oscillations - if your robot is oscillating around setpoint, then you need to tune it better to reduce the overshoot. If you find it difficult to reduce/eliminate the overshoot without making it difficult or impossible for the robot to actually reach the setpoint, consider implementing a "minimum output" for your PID loop rather than letting it actually go smoothly to 0. |
Re: Why won't this PID loop stop?
Quote:
|
Re: Why won't this PID loop stop?
Quote:
Edit: Or possibly not, as a reply in that thread indicates that bug does not occur in the python version of WPILib. I'd suggest looking through the PIDController code and debugging to find why this is happening. Edit 2: I have never worked with python myself, so perhaps I'm missing something, but it seems to me that the onTarget() function in the python WPILib doesn't actually, erm, do anything (other than throw a value error): Code:
def onTarget(self): |
Re: Why won't this PID loop stop?
Quote:
https://github.com/robotpy/robotpy-w...r.py#L431-L467 |
Re: Why won't this PID loop stop?
There are a number of bugs with the current WPILib PIDController implementation. The python implementation follows the java implementation closely, so it shares these issues. Here are bug reports on WPILib's github site:
In particular, #29 is probably the one that is biting you (it bit me for a similar reason). If you keep calling setSetpoint (like that example does), each time it is called it will reset things such that onTarget is false, which means the robot will never stop oscillating. There are a number of ways of dealing with this problem -- the easiest is to not call setSetpoint if the input is close (within 0.001) to the original input. However, this isn't satisfactory either for a number of reasons... so I ended up writing my own magicbot-compatible implementation, it'll be part of magicbot next year. |
Re: Why won't this PID loop stop?
If the system has enough inertia that it continues out of the tolerance range, it will continue to oscillate. If this is your issue, I suggest a more dampening D (differential term) to bring the output back when it "overshoots" the design target.
|
Re: Why won't this PID loop stop?
Quote:
Code:
|
Re: Why won't this PID loop stop?
Quote:
Code:
self.last = None |
Re: Why won't this PID loop stop?
Quote:
|
Re: Why won't this PID loop stop?
Quote:
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. |
| All times are GMT -5. The time now is 09:52. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi