Vernier Encoder Visualizer

Configuration

Main gear count

Left gear count

Right gear count

Left ratio: ????

Right ratio: ????

Encoder resolution (ticks per rotation)

Physical Model

This section simulates the actual mechanism. Click and drag on the main gear to set the angle.

Encoders

This section simulates the values that would be read by encoders on the left and right gears.

This includes both wrapping readings after a full revolution and discretizing the readings based on the encoder resolution.

Solution

The below shows the results of solving for the original mechanism angle, given the left and right encoder angles.

The solution is calculated by calculating for each encoder which possible mechanism position would cause that reading, then returning the only solution present for both encoders.

function solveTheta(p, q1, q2, a, b) { const range = lcm(q1, q2) / p; const r1 = q1 / p; const r2 = q2 / p; let i = 0; let j = 0; while(i * r1 < range && j * r2 < range) { const alpha = r1 * (i + a); const beta = r2 * (j + b); if (Math.abs(alpha - beta) < 1e-3) { return alpha; } if(alpha < beta) { i += 1; } else { j += 1; } } return NaN; }

Range

The effective range of the vernier encoder is determined by when both encoders simultaneously return to their starting point.

This can be determined by the lowest common multiple of the two encoder gear counts, divided by the main gear count.

let range = 2 * Math.PI * lcm(left_count, right_count) / main_count;

The currently simulated vernier encoder can measure up to ????° of rotation.

Note that if the range is not a multiple of 360°, then exceeding the range and wrapping around will produce unexpected values from the vernier encoder. You probably want to avoid this.

Also note that the larger the range, the less precise your measurement. There's no free lunch here.