![]() |
(Experimental) PID Control System
This code could be used in any feedback loop. I wrote it all in theory, using a simple simulator for testing... Robot still not back from FedEx yet....
Testing is well appreciated. Feel free to use if desired. --NOTE-- The following source was designed to run on a PC (Actually, Cygwin+KDevelop). Tweak accordingly. You only need the do_discrete_control and its global variables on the robot -- the rest was for PC simulation. Code:
|
Re: (Experimental) PID Control System
I don't see the integral part of the PID.
Why is Ki multiplied by the current error? There should be a variable keeping track of the running sum of the error. That variable would be multiplied by Ki. |
Re: (Experimental) PID Control System
yes...you want to integrate i add up all the values then divide by total time (multiplying each new i by time shouldn't matter because its an "assumed" even loop time...or use interrupts timers or whatever..) ...then multiply by Ki... don't even bother multiplying by .025 or whatever the loop time is ...just by 1 its simpler
this is what I did for our also Experimental PID loop (PI so far actuallY): Code:
error=realv-targetv;can you please explain how the deriviatve portion works? ... I am kinda clueless to how it works...and does anything ...basically the theory behind it..and why it helps and what exactly it is |
Re: (Experimental) PID Control System
What exactly is PID supposed to do? Is it a fancy way of having whatever get to a certain position?
|
Re: (Experimental) PID Control System
Quote:
|
Re: (Experimental) PID Control System
or getting to certain speed too
|
Beware of the I...
With regard to the I part of PID, be very careful.
There is a phenomon called "integral wind up" that is not a theoretical problem but a practical implementation problem. Essentially, you need to "turn off" the integration when the controller output is saturated or limited (for example when your robot is disabled). We had a nasty bug that we had fits trying to kill. Our robot would come out of a disabled state and do a major twitch that hurt our robot and almost hurt some workers on a number of occassions. We finally killed the bug, but it was very sutble and was quite difficult to discover. It turned out to be a case of integral wind up. Joe J. |
Re: (Experimental) PID Control System
Thank you. We used something to that sense, but we just had direction (if too low go up, if too high go down), that worked pretty well.
|
Re: (Experimental) PID Control System
oops, sorry, I switched kp and ki when typing in a hurry. kp is ki and ki is kp :ahh: :ahh:
Time constants are 'included' in the k's. I thought that if anyone needed a code snippet for PID, they probably wouldn't know exactly what effect each constant has, and probably would just "guess and check" |
Re: (Experimental) PID Control System
Reguarding the addup -- the loop goes through and adds the current output to previous outputs -- so errors are summed in there. I found this in a whitepaper about PID (I lost the url, so can't post it here). It was the "most optimal and stable" implementation, according to the author.
|
Re: (Experimental) PID Control System
Integral windup can definately become a problem if you leave your robot on, and something that is connected to your PID loop sensor moves (when the RC is on but the robot is powerless to do anything about it, it will build the integral uselessly, until reactivation when people get hurt). We struggled for a while trying to get the RC to realize when the OI was on or off, but if you can manage to reset everything when the OI comes on (not just resetting the RC), that's a good way to go. You can also limit your integral, as this will help you if you ever get stuck on something during real testing (you won't break your motors). If you don't have a failsafe implemented though, make sure to reset your robot every time before turning your OI back on!
|
Re: (Experimental) PID Control System
If the OI isn't on, doesn't it NOT execute user code? I'd be more worried about disable.
|
Re: (Experimental) PID Control System
The OI does know what state it is in. It knows when it is in competition mode, disable mode, or autonomous mode. Your control loops should be aware of which state the sytem is in and provide code for transitioning between each state. You can use different controls for each state, but anything with memory like integrators should be delt with as the system changes from state to state. All memory type variables should be initialized to a known state while not being used in a specific state so it is ready to be used when the new state starts.
|
Re: (Experimental) PID Control System
I know that. But if you unplug the OI (the OI is no longer broadcasting), then doesn't the RC just stop the user proc?
|
Re: (Experimental) PID Control System
No, the RC goes into disabled mode.
|
| All times are GMT -5. The time now is 14:07. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi