
13-01-2016, 22:00
|
 |
 |
Data wins arguments.
AKA: Phil Lopreiato
 FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
|
|
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,113
|
|
|
Re: Application of PID in code/real world
I go over some good papers/math explanation of how PID works in this post, take a look and read some of the linked resources. My details are LabVIEW specific, but there's some good java examples on ScreenSteps, and also as a subsystem.
Quote:
Originally Posted by plnyyanks
There are many, many threads on CD and the general internet about PID control. Try searching around.
Here's some good resources from NI:
Quote:
Originally Posted by plnyyanks
Additionally, if you search through NI's website, they have some great resources about PID theory (and their examples are in LV). You can also view the complete help page for the PID VI here.
|
And here are some more resources:
Quote:
Originally Posted by plnyyanks
The PID VI is entirely mathematical - it doesn't care what the inputs are, all it does it brings the error of the system (Setpoint - Process Variable) down to zero. It will work exactly the same with encoder rates and distances, provided that the SP and PV are scaled the same way (and the constants are tuned properly). I'd be more than happy to explain how some of the math works, if you'd like.
As for your specific system issues, it just looks like the constants aren't tuned properly. Read a little bit about PID Theory (also: wikipedia) and take a look at some tips on designing a good controller (the rest of that page is helpful too). You may also want to start with the Ziegler-Nichols method for tuning (start with all zero, bring P up until it oscillates, add D to dampen and add I to correct for steady state error.
Just another note - if I remember, the LabVIEW implementation of the algorithm doesn't use Kp, Ki, and Kd as straight constants. It actually uses time constants for I and D (so it has Kp, Ti, and Td). You can see details of the NI implementation here. You can verify this in the help popup (ctrl-H) for the VI. Plan your constants accordingly.
|
And this page looks like it has some cool simulation resources, and some overviews about the theory behind the controller.
|
As for the best way to tune, Ziegler-Nichols is a decent start, but there will inevitably be lots of guesswork involved unless you take the time to really characterize your system (not usually practice in FRC timeframes). Below is a previous post I made about how I always tuned PID controllers.
Quote:
Originally Posted by plnyyanks
Really, the best way to tune PID constants in Guess and Check - after a little practice, you get pretty good at guessing the correct constants. This is pretty much the method we use on 1124, and we haven't really found the need to migrate away from it.
Quote:
|
Originally Posted by Wikipedia
If the system must remain online, one tuning method is to first set Ki and Kd values to zero. Increase the Kp until the output of the loop oscillates, then the Kp should be set to approximately half of that value for a "quarter amplitude decay" type response. Then increase Ki until any offset is corrected in sufficient time for the process. However, too much Ki will cause instability. Finally, increase Kd, if required, until the loop is acceptably quick to reach its reference after a load disturbance. However, too much Kd will cause excessive response and overshoot. A fast PID loop tuning usually overshoots slightly to reach the setpoint more quickly; however, some systems cannot accept overshoot, in which case an over-damped closed-loop system is required, which will require a Kp setting significantly less than half that of the Kp setting causing oscillation.
|
In our robots, we've found that an I parameter is rarely needed - we usually get what we want with only PD (or sometimes just P) controllers. It's really dependant on your application and the type of feedback you want. There's no really easy way to say it: it's a long, time consuming process.
Some more links to read into
To do this in LabVIEW, you have your PID VI, and one of its inputs is a cluster of three doubles, which are the P,I, and D constants that you tune to your liking. The best way to tune quickly is to probably run your code through a computer (using the Run button on Robot Main.vi - not building/running as startup) and modify that parameter cluster until you get satisfactory results. Just remember to reinitialize your PID VI (it's another control - wire that input to a button on your front panel or something like that) to "apply" your changes. NI also has a good whitepaper about working with PID in LV. It's a good read - check it out.
|
Last edited by plnyyanks : 13-01-2016 at 22:08.
Reason: Add subsystem link
|