PID programming guide

So over the past year I have been trying my hardest to expand on my programming knowledge and so I have now entered the realm of PID controllers.

I have written a guide for programmers new to PID to hopefully help them where possible. The guide can be found here.

It hasn’t been out on the internet for too long, but I am confident that hasn’t got any errors, thanks to a few people who have very kindly checked it over. But if you do spot any errors, PLEASE let me know. Also, if you have any suggestions or comments, please leave a comment. :slight_smile:

You may know that I wrote a Beginners Guide to ROBOTC, and in case you are interested, I have decided to stop my plan to make an Intermediate Guide. Instead, I have goals put in place to make an Advanced Guide (in replacement), and then just do individual guides on more specific areas. My PID tutorial is the first of the more specific guides.

As I said, any comments, suggestions or errors you find, please let me know.

Thanks!! :slight_smile:

~George

Very nice George.
Something you might consider if you update it is a section that talks about practical uses in Vex. But in particular one discovery we made was that if conditions change in the system you may need to account for updating the PID coefficients. What we discovered when using a PID function to control our arm last year is that it behaved differently with 0-2 game pieces vs 3-4 game pieces and we added code to allow for different PID coefficients based upon how many pieces were being held. I believe we just used this in autonomous, but it was very helpful.

Cheers Kb

Excellent guide. Very well written. I’ll forward this thread to my team. :slight_smile:

This was perfect timing, I was planing on getting into learning PID controllers these upcoming days, and this explained everything extremely well. :smiley:

Thank you very much!

You should replace my control systems lecturer…

Thanks to you, I finally understand the issues my team had when we were tuning our PID controller. I won’t be doing VEX next year, but I’ll definitely make sure the CAMS VEX teams see this. Thanks again! :smiley:

First of all, wow! Thanks everybody!!! :smiley:

Thanks for the feedback, I will certainly look into that idea. It’s a great idea, I hadn’t really thought about it that much but it would be very useful.

Hehe :stuck_out_tongue:

Thank you all again, I’m glad you found the guide useful :slight_smile:

~George

This is awesome and VERY useful. Thank you so much!!!

I’m glad to hear it! Thank you for your kind words! :slight_smile:

~George

One of best publications on an introduction to PID that I have read. Nice job and thank-you!

Brad

Thanks for the guide George.

Something we learned about PID in the clean sweep season is that you need to understand your robot a little to verify if PID is worth using. This is especially true when using PID for line followers. If the centre of gravity or the centre of a a regular turn cirlcle is in front of your line followers, then PID will not help you stay on a line. We wasted hours and hours on this until we figured out why it wouldn’t work.

This is a good point. To generalise it a bit more: make sure the error (as measured by your sensors and used in the PID code) actually corresponds to what you are trying to achieve. Sometimes it is easy to assume that it does, but this turns out to be false.

It should be possible to use PID on a line follower even if the sensors were right at the back, although the PID loop might not be designed as you expect, and granted it probably wouldn’t be nearly as effective

I know I told you this already, but I will say it again and again. This is a great guide for PID. Its really very helpful.

Very good. I like auto-tuning control loops a lot.

Suggestions for more advanced topics:

-Gain scheduling. I have done “binary” and “linear”/“Algorithmic” gain scheduling in different applications, both worked well. Linear/Algorithmic gain scheduling is useful when linkages do not linearly translate the controllers motion to actual motion, or for arms that are balanced differently at many points (most arms) - Usually using a linear or trig function for scaling. Binary gain scheduling is useful for up/down or loaded/unloaded gain sets.

-Integration with the rest of the code - It is sometimes better to run the controller all the time and adjust the setpoint - This results in better loaded performance for arms, but is undesirable for autonomous vehicle motion controls.

-Speed control with PID (it is very different from position control in terms of tuning).
–I does the job of P, P does the job of D, i personally don’t use D in speed controllers
–Feeding forward the estimated power for better rise time (since the integrator will be doing most of the work)
–Limiting of the I term for stability (I use a linear piece-wise limit proportional to the error) - Only if P gain is high enough and you feed-forward.

These are great points, I will look into them.

~George

This is an excellent post and I will definitely be referring to your tutorial in the future. Thanks!

Zeroing the integral (bottom of Page 7) makes sense only if no output is required to maintain the target position.

For example, if the vehicle is on an incline then you need a non-zero output to hold the target position. The integral component is what does this (unless, of course, you zero it).

Hmm yes I understand what you mean. I will definitely look into this and I will make alterations to the guide to address this issue.

Thanks a lot! :slight_smile:

~George

Thank you!! :smiley: It was the PID controllers which killed 4886a last year