PID Control

From FRC11 - Mentor Wiki
Jump to navigation Jump to search

Intro

PID Control is a closed loop control architecture that uses monitoring and feedback to improve control of a process variable - that is something you wish to control. It is more robust than open loop controllers that have a set it and forget it type of mentality, which do not monitor what is happening.

Before learning about PID Control, it is important to know where it fits in with other types of control options. The introduction to PID is on this other page:

See page: Intro to Control Theory and PID Loops

Tips and Guides

  1. PID control works best if the underlying control mechanism does a decent job first
    • That way, the correction constants can be tuned to correct disturbances, and not to control the system for its default behavior.
    • This implies that your feed-forward/open loop/bias component should be calculated appropriately, and not rely on the PID portion to perform basic operation. Proper bias is an important element of the controller, and will allow you to focus efforts on tuning for step changes or variability, and not for basic performance. It is unnatural to combine them into the P, I, and D, and it will complicate the tuning process considerably if you do not account for a proper bias. Consider the final step about using a setpoint sequence as part of this analysis.
  2. Get your bias right before tuning P, I, or D.
    • If the bias is incorrect, you will have a hard time tuning with only P. Figure out a good bias for as many setpoints as you find appropriate.
    • If you have more than one setpoint of interest, and they would work best with different biases, create an equation or lookup table to help provide an appropriate bias for whatever setpoint is used.
  3. Tune P before I or D.
    • P should generally be the largest input to correct the error, and should be tuned first.
    • If you have to retune P, you will likely need to retune I and then D.
  4. Tune I before D.
    • I should be used to help with variation and unexpected inputs that can be corrected over time.
    • If you have oscillations, consider if windowing would be helpful, limiting the time error samples are included. Windowing limits the impact of lengthy error accumulation, reducing windup, or effects after the problem has been corrected. However, if the window is too small, it may not guarantee that you ever reach the goal (setpoint).
    • If you have to retune I, you will likely need to retune D.
  5. D often does not need to be used
    • Only use D values if you have issues with oscillation, and are confident that is the best approach after considering:
    Is your I value too high?
    Would windowing the I integration to only recent samples help?
    • The Derivative component D is often subject to noise and can be difficult to control
    • You can perform noise filtering to get improvements at a cost of slightly delayed response for the D component. Usually the delayed response is insignificant.
    • In order to filter, you need to keep track of several samples, so you can determine the slope using a longer time period, and also perhaps to average the samples.
    • For example, instead of creating the slope from only the 2 most recent samples 20 ms apart, keep track of the last 10 samples, spanning 200 ms. Compute the slope using the first and last values, using the time span between them.
    • Another good idea to help with noise is to average 2-3 samples at the beginning and end of the period (be sure to average the times too!) before computing the slope.
  6. When tuning, be mindful of what is available for corrections
    • Know that you cannot correct with MORE than 100% of system max positive output or MORE than 100% of system max negative output.
    • Negative output is any output that causes the process variable to lessen
    • Note that either the system max positive or system max negative output may be nil (zero). (And max positive and max negative values chosen for corrections can be less than the extremes that the system allows.)
    For example, when heating to a specific temperature, the best you may want to do when it is already too hot, is to turn off the heating element (not introduce cooling). Similarly, when cooling, you may only want to turn off cooling and not want to introduce heating when it has gotten too cold.
  7. Use banding or multiple Design Levels of Operation (DLOs) to provide a stronger and more tunable response
    • Banding of the PID controller is a simple way to get maximum controllability around the setpoint. The idea is that maximum positive output chosen is applied below (setpoint - LOWER_THRESHOLD), and maximum negative output chosen is applied above (setpoint + UPPER_THRESHOLD), and PID is used in-between the two thresholds.
    If you do not band, you will distribute the response of the PID controller over a wide area, thereby weakening it, especially when it is near to the setpoint. If it is so weak that the I component needs to take over, you will likely have issues with oscillation. On the other hand, if you make the bands too tight, it may act more like a Bang-Bang controller.
    • Multiple DLOs are used when you've identified different setpoint areas that require different types of responses. This may happen near boundary points, or due to some other aberration. You can create a controller for each of the setpoint areas, and they don't even have to be the same type.
    For example, for setpoints in range 0-10 you could use constant output, for setpoints in range 10-20 you could uses Bang-Bang, and for 20+ you could use a PID controller.
  8. Consider guiding a PID controller through a planned and timed setpoint sequence
  9. For example, maybe you want to have a trapezoidal style ramp up and ramp down, but don't want a simple trapezoidal controller due to variability in the environment. You can feed the PID controller setpoints that ramp up to a max over time, just like in trapezoidal control, but the PID controller will tend to keep it on track better, more closely following the velocity curve that you give it.
    Caution: if you are going to feed in lots of tiny step changes, you may want to make sure the banding is tight enough (and thereby strong enough) to accommodate the small changes in the correct amount of time. It will self correct, however - if the setpoints get too far away from the actual value, the error will increase, thereby increasing the response.

Resources

Links:

Control Guru offers a really good, solid basis for understanding PID Control and intro to PID loops by discussing Proportional only. Careful - ControlGuru uses Kc instead of Kp, and Kc/Ti instead of Ki. Essentially works the same.
Some of the most comprehensive documentation on PID Control on the net. Includes beginner topics and advanced topics.
Good explanations for when and how to use DLOs. To tune a non-linear process that responds differently to changes at different levels of output, you need to determine a representative operating point (DLO). Maybe you need more than one because there is too much variation, in which case - you need more than one controller, each based on its own range of operation.
Pretty thorough introduction with examples, plus lots of concepts not presented above.
Pretty thorough introduction to Control Theory, with examples and more details.
PID Control built into the Talon SRX controllers


To Do:

  • Cover use of the PIDF controller built into the Talon SRX controllers by descriptive text here.
  • Cascading controllers?
  • Info about the mentor PID Controller code when completed?
  • Additional topics: more tips for tuning (i.e. testing with drag), typical places to apply on the robot.