Help With Profiled PID Controller

Can someone explain the Profiled PID Controller constructor (and other stuff) to me. What do the arguments mean? Also, what is feedforward? This is the WpiLib Page:

(sorry if this is really obvious and im just dumb)

If you know what a regular PID is, then this one isn’t too much more complicated than that.

First off, PIDs work by using the Error to calculate the output needed to reach a goal. Feed Forward is essentially just additional output that you know you will need. For example, if you have an elevator, and it takes 20% power to hold it still (less will cause it to fall, more will cause it to raise), your feed forward would be the 20%. Or, and Arm at 90 degrees out takes 20% power, your feed forward would be sin(arm angle) * 20%. This is your kG term

There is an additional feed forward for static friction (kS)

You don’t need those, but they do help make your control tighter

Now, Profiled PID is just a PID that does smooth acceleration and deceleration. It does this by applying a trapezoidal profile to the output. In order to do this, you need to specify your acceleration (kAVoltSecondSquaredPerRad) and your top speed (kVVoltSecondPerRad)

When done right, this will give you a super smooth mechanism. I highly recommend using one if you have the time

Profiling makes tuning PIDs actually easier

MotionMagic is CTRE’s implementation of this, which runs directly on the motor Motion Magic® Controls - They also have a more detailed explaination

1 Like

Ok, thanks. This clears allot of stuff up, but I am not particularly familiar with PID so could you explain that (sorry should have mentioned that in my OP).

Here is a video that does a great job of explaining PID control. Don’t expect to gain an understanding from zero-to-usablity on feedback control, feedforward control, and motion profiling from a few short responses to a CD post. Longer tutorials are going to be essential. Do you have mentors and students on your team that have used these control techniques in practice? Getting instruction from them would be a much more effective direction.

The ProfiledPIDController in WPILib applies a trapezoidal profile to the setpoint velocity. The maximum velocity and maximum acceleration of the setpoint can be set with the TrapezoidProfile.Constraints object. Watch this oldie-but-goodie video from 254 that does a little bit to explain PID and setpoint profiling. It doesn’t address the use of any of the WPILib controller classes, but helps in understanding how those work.


Here is a fantastic video that was ostensibly made to show how to use robot simulation and the simulation GUI. However, the example shows WPILib profiled PID + feedforward control of a simulated elevator. You can follow the video to get the code for yourself and you can play with it as much as you want to experiment with the PID tuning parameters, feedforward model parameters, and the trapezoidal profile parameters. You can learn a ton from this example.