Quadrature Encoders and How They Work
A quadratureencoder is the workhorse incremental position sensor. It produces two square-wave pulse trains, called channels A and B, that are 90 degrees out of phase with each other — the ‘quadrature’ relationship.
Counting and direction
Section titled “Counting and direction”Because A and B are offset by a quarter cycle, the controller can tell direction by which channel leads. If A rises before B, the shaft turns one way; if B leads A, it turns the other. Counting the edges accumulates a position relative to wherever you started.
This is the key property and limitation: a quadrature encoder is incremental/relative. It tells you how far you have moved from power-on, not your absolute angle. If the robot boots with an arm halfway up, the encoder reads zero there until you zero it against a known reference (often a limit switch).
Resolution: CPR vs PPR
Section titled “Resolution: CPR vs PPR”Resolution is described with two easily-confused acronyms — CPR (cycles or counts per revolution) and PPR (pulses per revolution). One full electrical cycle of a single channel contains only two edges (one rising, one falling). But across both channels A and B there are four edges per cycle (hence ‘quad’). The roboRIO FPGA and WPILib’s Encoder class default to 4x decoding (k4X), counting all four of those edges to yield four counts per cycle. Always read the datasheet to learn whether a spec means cycles, pulses, or edges. As a guideline, your effective resolution should be finer than the smallest position error you can tolerate.
Reading one in WPILib
Section titled “Reading one in WPILib”Encoder enc = new Encoder(0, 1); // DIO 0 (A), DIO 1 (B)enc.setDistancePerPulse(Math.PI * wheelDiameter / countsPerRev);double meters = enc.getDistance();double metersPerSec = enc.getRate();setDistancePerPulse converts raw counts into real-world units (meters, degrees), which is essential before using the value in control code. Remember that regardless of decoding type, WPILib always treats one “pulse” in setDistancePerPulse as a full cycle (four edges) — the denominator should be the encoder’s raw cycles per revolution from its datasheet, not multiplied by 4.
Common quadrature encoders
Section titled “Common quadrature encoders”WPILib lists several FRC-legal quadrature encoders, including the CUI/AMT103-V , the US Digital E4T , the Grayhill 63R , the CIMcoder , the legacy CTRE Mag Encoder , and the REV Through Bore Encoder (covered next, which also offers absolute output).
Key takeaways
Section titled “Key takeaways”- Quadrature encoders use two 90-degree-out-of-phase channels to sense both distance and direction.
- They are incremental/relative: they measure change from power-on, so they usually need zeroing.
- Watch CPR/PPR carefully — one cycle = four edges, and WPILib defaults to 4x decoding — and always call setDistancePerPulse to get real units.
This lesson was adapted from learnfrc.com.
