PID control - quasics/quasics-frc-sw-2015 GitHub Wiki
[Note: the following information is largely taken from the Programming 101 resource provided by FIRST]
Basics of PID control
PID Control allows you to control a mechanism based on position, rather than voltage. Using PID, you can tell an arm to turn to 30 degrees, instead of telling it to directly output a voltage. This is especially useful in autonomous mode, but can also be useful for other cases, such as moving parts of the robot to specific positions (e.g., required heights to pick up/deliver game pieces in vertical positions). Being able to tell a robot to drive 5 metres instead of full power for 0.5 seconds allows for enhanced repeatability.
Some useful documents for PID are:
- FRC Programming done right
- Wesley’s Blog
- CSIM’s PID for Dummies
- Motion magic
- If using a TalonSRX speed controller on CAN bus, it is recommended to use MotionMagic for controlling mechanisms, especially something like an arm or an elevator. MotionMagic is essentially a 1KHz PID loop following autogenerated trapezoidal motion profiles. If those words make no sense, don’t worry! See the links above above for background information on PID, and here’s a document explaining motion profiles.
Drive paths and following them
Sometimes raw PID isn’t enough for controlling the drivetrain autonomously. For example, you might want the robot to go around the switch and pick up a cube from behind. A clean way to do this would be to create a drive path. A drive path is essentially a set of points that the drivetrain PID loop will follow, and the points will lead to the eventual goal.
PathWeaver is a graphical tool that uses a library called PathFinder which generates such paths and saves them to a parsable file. Detailed instructions on PathWeaver usage are found here.
Once the points have been generated, there are a variety of ways to follow them. These range from using PID to directly follow the points, to adding a path following algorithm to process the points before giving them to the PID loop. An example of such a path following algorithm can be found here (eqn 5.12). Other popular approaches to path following include adaptive pure pursuit control. Team 254 has a handy implementation of adaptive pure pursuit which can be found here.
Model based control
Model based control is a step beyond PID. It allows for keeping a mathematical model of the system in the code, and updating the model with sensor data. Using such a model, one can control a mechanism’s position, velocity, acceleration, etc much more precisely. Some teams that use model based control include 1678 and 971.
Useful resources for learning model-based control are: