How to with ProfiledPIDController to align with the target

In order to increase the accuracy and stability of our auto aim, l think a profiledPIDController is needed. But since a profiledPIDController needs more setup work like reset() than a normal PIDController class. And l think l am confused with it. So, can any team using ProfiledPIDController to align with the target share how they do it?Perhaps an explanation with code is better!

The WPILIB docs has a good example of this on the website:

Combining Motion Profiling and PID Control with ProfiledPIDController — FIRST Robotics Competition documentation (

Basically, the profiled PID controller is a normal PID controller that follows a trapezoidal motion profile.

Assuming it is relatively far from the target, the controller would accelerate to max velocity (as supplied in constraints), maintain max velocity, and then decelerate until it hits the goal. This would appear graphically somewhat like a trapezoid, hence the name.

So when defining it, you would not only supply PID constants, but also a max acceleration and max velocity.

Additionally, it is not as purely reactive as a normal PID controller, so the current setpoint, or target, of the controller is not actually the same as the intended goal.

I would recommend reading the article, however, as it includes code and proper explanations.


My team does and I think your team also used PID control for the swerve drive motors and profiledPID control for the swerve turn motors. If so you already have good experience and you can apply that knowledge to camera alignment.

My team used essentially a P controller on the desired gyro angle setpoint with a trivial, simple one line of code delta angle x kP (no libraries!) to align the camera and a line of code to check the tolerance and that was good enough.

1 Like