Don't Blink LogoFTC Stack

PID Control

Learn how PID controllers use feedback to accurately control robot mechanisms.

A PID controller is one of the most common algorithms used in robotics. It allows a robot to move a mechanism smoothly and accurately to a desired position by continuously correcting its own mistakes.

You'll find PID controllers everywhere in FTC, including:

  • Linear slides
  • Arms
  • Turrets
  • Flywheels
  • Robot heading correction
  • Autonomous movement

At its core, a PID controller takes information from a sensor, compares it to where the mechanism should be, and decides how much power to send to the motor.

Error

Everything in PID starts with error.

Error is simply the difference between the desired position and the current position.

Error = Setpoint − Current Position

Suppose you want a lift to move to 1000 encoder ticks.

Current position:

700 ticks

Target position:

1000 ticks

The error is

1000 - 700 = 300 ticks

The controller uses this value to determine how much power should be applied.

As the lift gets closer to its target, the error becomes smaller.

The PID Formula

A PID controller calculates its output using three separate terms.

Output =
(Kp × Error)
+
(Ki × Sum of Previous Errors)
+
(Kd × Rate of Change of Error)

Each term solves a different problem.

Fortunately, you do not need to fully understand the math to understand how PID works.

Proportional Control (P)

The proportional term is the easiest to understand.

It simply says:

The farther away I am, the harder I should try to get there.

The equation is

P = Kp × Error

Suppose

  • Kp = 0.02
  • Error = 50 ticks

The controller outputs

0.02 × 50 = 1.0

The motor runs at full power. After moving closer to the target, the error drops to 20 ticks. Now the output becomes

0.02 × 20 = 0.4

Instead of running at full speed, the motor automatically slows down. This is why PID-controlled mechanisms naturally decelerate as they approach their target.

Think of it like a rubber band. Imagine the mechanism is attached to its target with a rubber band. The farther away it gets, the harder the rubber band pulls. As it gets closer, the pull becomes weaker. Increasing Kp is like replacing that rubber band with a thicker one.

The Problem with Only P

Although proportional control works surprisingly well, it isn't perfect. If Kp is too low, the mechanism may never quite reach its target. If Kp is too high, the mechanism may overshoot and bounce back and forth. This is why the remaining two terms exist.

Integral Control (I)

The integral term remembers past error. Instead of only looking at the current error, it adds together every previous error.

I = Ki × Sum of Previous Errors

Imagine a lift that always stops a few ticks below its target because gravity is pulling it downward. Even though the remaining error is small, it never completely disappears. The integral term notices this. The longer the error exists, the larger the integral output becomes until the mechanism finally reaches its target.

You can think of integral as patience. If the controller has been missing the target for a long time, it becomes increasingly determined to fix the remaining error.

Do FTC teams use Integral?

Usually, not much. Because FTC matches are short and mechanisms are relatively simple, many teams use PD controllers instead of full PID controllers.

Integral can also introduce problems such as integral windup, where accumulated error grows too large and causes large overshoots.

For many FTC controllers, Ki is simply left at zero.

Derivative Control (D)

The derivative term looks at how quickly the error is changing.

Instead of asking

"How far away am I?"

it asks

"How fast am I approaching the target?"

Its equation is

D = Kd × Rate of Change of Error

Derivative acts like a shock absorber.

Imagine skating across an ice rink. Without friction, it's easy to fly past your stopping point. Adding derivative is like increasing the friction beneath your skates. It slows the mechanism as it approaches the target, reducing overshoot and making the movement smoother.

Increasing Kd generally reduces overshoop, reduces oscillation, and improves stability. Setting it too high, however, can make the mechanism sluggish.

Tuning a PID Controller

Finding good values for Kp, Ki, and Kd is called tuning. Every robot is different, so there is no universal set of values.

A common tuning procedure is:

Step 1

Start with all three values at zero.

kP = 0;
kI = 0;
kD = 0;

Step 2

Increase Kp until the mechanism reaches the target quickly. Keep increasing it until the mechanism begins to oscillate slightly around the target.

Step 3

Increase Kd until the oscillation disappears and the mechanism comes to a smooth stop. For many FTC mechanisms, tuning can stop here. A well-tuned PD controller is often all that is needed.

Step 4

If the mechanism consistently stops slightly short of the target, increase Ki a small amount until the steady-state error disappears. Only add as much integral gain as necessary.

Common Tuning Problems

ProblemLikely Cause
Mechanism moves too slowlyIncrease Kp
Mechanism oscillatesDecrease Kp or increase Kd
Mechanism overshootsIncrease Kd
Mechanism never reaches the targetIncrease Ki slightly
Mechanism feels sluggishDecrease Kd
Large overshoot after waitingReduce Ki

Applications in FTC

PID controllers are used throughout competitive robots.

Examples include:

  • Slides: Move to an encoder position.
  • Arms: Hold a desired angle.
  • Flywheels: Maintain a target RPM.
  • Drivetrains: Turn to a specific heading.
  • Vision: Rotate until a detected object is centered.
  • Autonomous: Drive to a target pose using localization.

Was this resource helpful?

On this page

Was this resource helpful?