PID

PID stands for proportional-integral-derivative controller, and is defined by this formula on the right, where e(t) is the error from setpoint at time t. If you don’t already know this, this is not the doc for you, and I recommend beginning learning about PID from online documentation (feedback loops are a very common tool in robotics theory) or WPI. Feedforward + PID

$u(t)=K_pe(t) + K_i\int_0^t{e(\tau)d\tau} + K_d\frac{de(t)}{dt}$

PID has three gains to worry about, $K_p$, $K_i$, and $K_d$. In FRC, you will (hopefully) never have to use $K_i$. If you feel the need to, then you likely forgot about or mistuned your feedforward gains and need to revist those. $K_i$ typically accounts for steady-state error, but all steady-state errors are resolved with feedforward, including static & viscous friction, back-emf, rotational inertia, and gravity.

Tuning raw PID is easy! Of course, if necessary, do this after tuning your feedforward, as you need accurate efforts that don’t depend on things that your feedforward would account for. For example, you want your pivot to act the same at any position, regardless of gravity pulling it down, which is why $K_g$ needs to be tuned first. Here are my personal tips on how to tune PID quickly:

For position control:

  1. Reset all PID gains to 0.
  2. Increase $K_p$ until you reach setpoint in around double your desired time. You will notice oscillation, ignore it until you are slightly satisfied with the time from start to setpoint.
  3. Increase $K_d$ slowly. You want $K_d$ to be as low as possible to prevent overdampening while still stopping oscillations. Keep $K_d$ at a value which creates no oscillations when moving between setpoints.
  4. Repeat steps 2 and 3, but increasing $K_p$ each time until the mechanism reaches its setpoint in your desired time, without oscillation.
  5. Done!

For velocity control:

<aside> 💡

You must do feedforward first for velocity control, as your $K_s$ and $K_v$ (and possibly $K_a$ if using a MotionMagic profile) are your main drivers for your control effort. PID is just used in velocity control to get to setpoint faster.

</aside>

  1. Reset all PID gains to 0.
  2. Increase $K_p$ until your system becomes unstable. Do this very, very carefully. Remember, all $K_p$ will do is make your effort higher when farther away, and therefore will just make you go faster to the setpoint. In some low-inertia cases, you don’t even need any PID gains, so this will be left as 0. Increase the gain value until the system begins to oscillate uncontrollably, then go to the last value before it oscillated. Test with multiple setpoints through all target RPMS.
  3. Again, being careful, you can increase $K_d$ by very little. In most cases, this can just be left as 0, however, if you feel that it’s necessary, you can increase it. This can almost always be left as 0.
  4. That’s it…

Now wasn’t that easy?

Feedforward

Now, feedforward is really the beast that hides among all the gains. It’s less intuitive to understand than PID, so if you don’t understand it, make sure to read over the doc Feedforward + PID . Note that the doc talks about