There is much information on the VEX Forum and various websites concerning PID, and most of them do a better job of explaining how it works and how to implement it than I could hope to achieve. So I thought I’d write a post here with links to the resources I found useful.
An item to consider as you read these articles: PID can be used for a few major functionalities, and it helps to understand which of these functions the article is discussing before you get too far into trying to replicate their method. Major uses include:
- Driving straight or making a double-flywheel to shoot straight, via adjusting left-side and right-side power
- Holding an arm in place
- Slowing down as you approach your sensor target so you don’t overshoot
- Line following
EasyC users: Most of this code and descriptions are in RobotC (thought there are some specifically for EasyC), but that doesn’t mean you’re out in the cold. The EasyC built-in PID functionality is for holding up an arm only; all other uses of PID require you to write the code yourself anyway, so you can follow along with what the RobotC code is doing and write your own EasyC.
My Recommendation for Newbies
If you’ve never programmed a PID control and you’re reading through these guides, make yourself a P-only controller to start. Most guides walk you through the entire process of creating the P, I, and D components. That doesn’t mean you have to use them. In fact, it’s generally a good thing to get the “P” part as good as possible first, such that any change in Kp up or down does not produce a better outcome for your robot’s movement.
For some applications, a P-only controller is perfectly fine (or at least sufficient), in which case you’re done, and there’s no need to move on to the I and/or D portions. So while it’s helpful to understand what these guides are explaining for all 3 parts of the system, you are never required to use all of them in any given application.
RobotC: Use the Datalog Function
If you’re using RobotC and are determining your best values for Kp, Ki, and Kd, then you should 100% be using the datalog feature. This RobotC tool can get you from start to finish on setting your PID constants in under an hour. See my previous post about using the datalog. You won’t be disappointed; this is THE go-to feature when writing your own PID.
- George Guillard, Introduction to PID Controllers
- AURA (Auckland Univ, NZ), How to Do a “Good Turn”
- Martin Ma YouTube video series, Let’s Make a PID Loop
- Tim Wescott, PID Without a PhD
- J. Sluka, PID Controller for Lego Mindstorm Robots
- VEX Forum user REX 1727B’s YouTube video for a double flywheel, PID Control Loop Tutorial
- VEX Forum thread, Preset Arm Heights in EasyC v4
- Michael David Lawton, Free Range Robotics, Line Following with RobotC
- J.M. McKinney’s Bitbucket Gyro PID Library, and associated VEX Forum thread. Note that this Bitbucket link is different than the Github repository in the Forum thread. Bitbucket is the one you want to use; the author has stated that the Github link contains outdated code. Concerning this new code he says, “There’s a really nice PID implementation, my motion planner code, and my gyro filtering code. Note that my gyro functions only return rate, I assume that the user will sum it over time themselves.”
- Cross Company Integrated Systems has a lengthy and well-explained blog post on PID, from soup to nuts.
- Wikipedia has a comprehensive write-up and background on PID controllers.
And, of course (the awesome) JPearman of the VEX Forum has several items to check out:
- VEX Forum post, Simple PID for EasyC (and ConVEX)
- VEX Forum post, Simple P Controller for Arm Position
- VEX Forum post, A PID Controller in RobotC
- PID Library (may overlap with the posts above)
If you are aware of additional resources that are not on this list, please email me and I will be happy to add them; I would like for this post to serve as a reference library for those looking for PID help. There are of course many YouTube videos explaining what PID is, but I want this listing to include only those sources that would help VEX teams learn, code, and successfully use PID for their robots.