Heads up: WPILib 2027 is still in alpha. These pages are changing quickly and aren't stable or finished yet — expect edits as the APIs settle.
Gray Matter LogoGray Matter Workshop

PID Control

PID (Proportional-Integral-Derivative) control replaces imprecise voltage commands with accurate, feedback-driven control. Toggle between an arm (position), a flywheel (velocity), and an elevator (position) below. The gains in each map directly to the motor's PID settings (a TalonFX Slot0Configs).

Key concept: PID uses sensor feedback to automatically adjust motor output; feedforward predicts the voltage needed before any error has accumulated.

PID · LIVE TUNER
DRIFTING
86.7° overshoot86.7° final err settle0.0 V peak
0°0.000 rot
-90°-45°0°45°90°
targetprofile setpointarm angle

Each loop the arm starts at (horizontal). For the first second the setpoint stays at . Use that window to tune kGuntil the arm holds. For a Kraken X44 + 25:1 driving a 2 kg · 0.4 m arm, CTRE's dyno numbers give kG = mgL / (Kₜ·R) ≈ 0.92 V. Add kS to overcome residual static friction. At t = 1 s the setpoint steps to your slider target; kP and kD chase the arm there and damp the overshoot. Order: kG → kS → kP → kD.

Feedback · PID

V/rot
V/(rot·s)
V·s/rot

Feedforward

V
V·s/rot
V

2 kg · 0.4 m arm on a Kraken X44 + 25:1 reduction (4.11 N·m stall, 7758 RPM free per CTRE dyno data; ≈ 103 N·m / 310 RPM at the arm; back-EMF modelled, ±12 V saturation). Gains use Phoenix 6 / WPILib mechanism-side units. Drop these values straight into a Slot0Configs with SensorToMechanismRatio = 25.

Understanding PID Components

P - Proportional

Definition:"The amount of output to apply per unit of error in the system"

Error = Target - Current
P_Output = kP × Error

Behavior: Larger error = stronger correction. Provides immediate response but may cause oscillation.

I - Integral

Definition:"The amount of output to apply per unit of error for every second of that error"

Accumulated_Error += Error × dt
I_Output = kI × Accumulated_Error

Behavior: Eliminates steady-state error by accumulating past errors over time.

Note:The integral term can lead to "windup," which may make your mechanism unstable. In most FRC applications, you can leave the integral term at zero.

D - Derivative

Definition:"The amount of output to apply per change in error over time"

Error_Rate = (Error - Last_Error) / dt
D_Output = kD × Error_Rate

Behavior: Reduces overshoot by predicting future error trends and damping the response.

Feedforward Gains

Feedforward gains predict the required output based on the target, rather than reacting to error.

kS - Static

Constant output to overcome friction and get the mechanism moving.
When to use:
Always

kG - Gravity

Compensates for gravitational forces acting on the mechanism.
When to use:
Arms/Elevators

kV - Velocity

Output applied per target velocity to maintain smooth motion.
When to use:
Flywheels/Intakes

kA - Acceleration

Output applied per target acceleration for responsive movement.
When to use:
High Inertia Mechanisms

Complete PID Tuning Guide

For detailed tuning instructions and mechanism-specific guidance:

CTRE Closed-Loop Control Reference

PID and Feedforward Tuning Tutorial

This video walks through PID and feedforward tuning, with practical steps for dialing in your gains:

PID Implementation in Code

PID Configuration Example

Workshop Implementation: PID Control

Before & After: Implementation

Before

  • • Commands control Arm with voltage
  • • No position feedback control
  • • Imprecise, inconsistent movement
  • • No automatic target reaching
  • • Manual voltage adjustment needed

After

  • • PID position control with PositionVoltage
  • • Automatic target position reaching
  • • Precise, repeatable movements
  • • Feedforward compensation for gravity
  • • Tolerance checking for "at target"

Loading file...

Code Walkthrough

PID Implementation:

  • PositionVoltage: Replaces VoltageOut for closed-loop control
  • Slot0 Config: PID and feedforward gains configuration
  • Target Setting: setTargetPosition() method for precise control

Gain Values Used:

  • kP = 24.0: Strong proportional response
  • kD = 0.1: Small derivative for damping
  • kS = 0.25: Static friction compensation
  • kG = 0.12: Gravity feedforward for Arm

The arm now reaches and holds a target position on its own. Next, we upgrade to Motion Magic for smooth, profiled movements with controlled acceleration.

NOTE · API STATUS

This is the WPILib 2027 alpha

The code on this page targets the WPILib 2027 alpha stack — Commands v3 + OpModes (GradleRIO 2027.0.0-alpha-6, Phoenix 6 26.50.0-alpha-1) on Java 25 and SystemCore — so exact APIs may still shift between alpha builds. This page was last verified against alpha-6 in July 2026.
CHECKPOINT · 6 ITEMS