PID (Proportional-Integral-Derivative) control is the foundation of all closed-loop motor control in Spectrum’s robot — from launcher velocity to turret position. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/spectrum3847/2026-Spectrum/llms.txt
Use this file to discover all available pages before exploring further.
Mechanism class exposes PID and Motion Magic configuration through the Config inner class, and Phoenix Tuner X provides live tuning without redeploying code.
PID concepts
A PID controller continuously calculates an output to drive a motor toward a setpoint by minimizing the error between the target and measured value.P — Proportional
P — Proportional
Responds to the current error. A higher Start here when tuning. Increase until you get a fast response, then back off when oscillation appears.
kP produces a stronger correction but can cause overshoot and oscillation if too large.I — Integral
I — Integral
Responds to the accumulated error over time. Eliminates persistent steady-state error (when the mechanism stops just short of the target). Keep
kI small — a large value causes windup and instability.D — Derivative
D — Derivative
Responds to the rate of change of error. Dampens oscillation and reduces overshoot. Tune after
kP is set.Motion Magic (CTRE)
Motion Magic (CTRE)
Motion Magic is a CTRE-specific profiled position control mode that generates a smooth velocity/acceleration trajectory to a target position. It wraps PID with feedforward and constrains motion with
cruiseVelocity and acceleration limits — giving smoother, more predictable motion than raw PID position control.The Mechanism class exposes motionMagicVoltage() and motionMagicTorqueCurrentFOC() command factories that use Motion Magic automatically.Tuning process
Open Phoenix Tuner X and connect to the robot
Connect your laptop to the robot’s network. Open Phoenix Tuner X and select your device (TalonFX by name or CAN ID). Navigate to the Controls tab.
Set all gains to zero
Start with
kP = 0, kI = 0, kD = 0, kS = 0, kV = 0, kA = 0. Command the motor to a known setpoint.Tune kP first
Increase
kP slowly until the mechanism moves toward the setpoint quickly. Stop when you see oscillation, then back off by ~20%.Add kD to dampen oscillation
If the mechanism overshoots or oscillates, increase
kD until it settles cleanly. Too much kD causes sluggishness.Add kI only if needed
If the mechanism consistently stops short of the setpoint (steady-state error), add a small
kI. Use iZone to limit windup to a small error window.Set Motion Magic cruise velocity and acceleration
For Motion Magic modes, set
cruiseVelocity and acceleration in the Config. These define the profile shape — faster cruise and acceleration means quicker but potentially jerkier motion.TuneValue utility
SpectrumLib includes aTuneValue utility class that publishes a value to NetworkTables so it can be adjusted live from SmartDashboard or Elastic without redeploying code — useful during initial tuning sessions on hardware.
java
