PIDF is simply an algorithm that calculates a raw output to a motor to track a setpoint. It sounds complicated, but it is pretty easy to understand. Think of a mechanism that is controlled by a motor, and say that you want it to go to a specific velocity. You can think of this as shooting darts at a board.
PIDF
Feedforward Control
The F term of PIDF is all about feedforward control. Feedforward is like the initial throw when you first throw a dart. You can see your target and your environment and estimate how hard you should throw your dart to reach the target. The feedforward calculation usually composes of:
- Ks - static friction. You can think of this as the minimum power needed to throw the dart out of your hand at all. The static friction feedforward prevents steady state error where the PIDF calculation is giving an output under the power needed to overcome static friction.
- Kg - gravitational feedforward. This usually used in arms and elevators, where the mechanism has a gravitational force acting on it. Kg is the power needed to hold the mechanism in place against the force of gravity.
- KA - acceleration gain. This is unused most of the time, but will make more sense when motion profiling to a velocity goal. This is the measurement of how much power is needed for a given acceleration. It is in the unit of volts / tps2. The most accurate way to find this number is to run the mechanism at different voltages, see the approximate acceleration that it takes before stabilizing at a certain speed, and perform linear regression.
- KV - velocity gain. This is the measurement of how much power is needed for a given velocity. It is usually in the unit of volts / tps (but volts may be replaced with a different unit in different control modes). This calculation can be done through code, but the most accurate way to find this number is to run the mechanism at different voltages, see the speed that it stabilizes at, and perform linear regression.
Feedback Control
The P, I, and D terms are all about feedback control. After you throw your first dart, you can look at where it ended up and adjust your next throw accordingly. The analogy breaks down here, as PID is all about math.
The proportional gain (P term) refers to the amount that the output should change per unit of error (output / tps). For example, a P gain of 2 will attempt to correct itself twice as fast as a P gain of 1. P values that are too small will correct fast enough for your purposes, but P values that are too big will overcorrect and oscillate around your target goal without actually reaching it.
The derivative gain (D term) is the output per unit of the derivative of the error. For example, in position control, the gain will be in the unit of (output / tps) because the derivative of position is velocity. The best way to describe the derivative gain is in how it actually acts. The derivative gain essentially "dampens" the output when it reaches close to its goal. A D gain that is too low will basically do nothing, a D gain that is too high will lead to instability and twitchy behavior, and a D gain that is just right should dampen the output as it reaches its goal to prevent overshoot. One common PID configuration is to have a high P to start moving towards the goal quickly, and a high D to dampen the control loop as it reaches its goal.
The integral gain (I term) is the output per unit of the integral of the error. This term is mostly unused, but can be helpful in certain situations. The I gain essentially "nudges" the output to prevent steady state error, but usually this should be accounted for through feedforward. Because the I gain is based on the sum of the past errors, an I gain that is too high can cause overshoot and oscillations. Usually you should not be setting the I gain unless you have a specific purpose for it.
Motion Profiling
Motion profiling is an enhancement on top of PIDF to plan a profile for how the mechanism is going to move beforehand. When you command a position with a motion profile, you give constraints, such as the maximum velocity, acceleration, and jerk. The motor controller will plan a profile given these constraints. You can think of this as a graph of speed v. time. The motor controller will now command the motor with a speed setpoint, even though you initially told the motor to go to a position goal. The important distinction here is goal vs. setpoint. In the world of motion profiling, goal represents the actual target that you told the motor to go to. This is in the original unit. The setpoint is the intermediate targets that the motor controller commands the motor, which is in the unit of the derivative of your goal (if your goal is in rotations, the setpoints are in rotations per second).
You can think of motion profiling as planning a marathon. In a normal PIDF setup, you come into the marathon with no planning beforehand and just start running. You might wear yourself out, or injure yourself, or might have to slow down to a walk. In a motion profile, you plan out your marathon by planning what speeds you should be running throughout it. For example, you might say that when going up a hill your target speed will be a little slower to conserve energy. Or, if you're recovering from a cold, you can limit your speeds to prevent yourself from getting sick. In any case, you will get a smoother marathon and won't get injured.
In the same way, motion profiling results in a smoother, more reproducible movement and reduces wear and tear on the mechanism by allowing us to adjust its limits.
Note: KA is only used when you are motion profiling to a velocity, because the target setpoints are in terms of acceleration.
You can read more about PIDF and motion profiling on CTRE's website. They do a really nice job of explaining it.