Robotics Fundamentals 1, Chapter 6: Challenge 1 solution (encoders and speed) Formulas: counts per revolution = 4 x CPR (4x decoding) ; per wheel revolution = 4 x CPR x gear ; resolution = 360 / (CPR x 4 x gear) ; distance per count = pi D / (CPR x 4 x gear) N = v dt / d_count ; quantisation error about 1 / N ; speed of one count = d_count / dt absolute encoder: 360 / 2^n ; potentiometer: T / 2^n (a) CPR = 16, gear 20, D = 80 mm. Counts per motor revolution: 4 x 16 = 64. Counts per wheel revolution: 64 x 20 = 1280. Angular resolution: 360 / 1280 = 0.28125 degrees per count. Circumference: pi x 80 = 251.33 mm. Distance per count = 251.33 / 1280 = 0.19635 mm. (b) v = 0.40 m/s. Counts per second: 0.40 / 0.00019635 = 2037 (2037.2). In 25 ms: 2037.2 x 0.025 = 50.9 counts. One count is 0.00019635 / 0.025 = 0.00785 m/s (7.9 mm/s). Quantisation error: 1 / 50.9 = 1.96 % (also 0.00785 / 0.40 = 1.96 %). Motor speed: wheel revolutions per second = 0.40 / 0.25133 = 1.5915; x 20 = 31.83 motor rev/s = 1910 rpm. (Check: 31.83 rev/s x 64 counts = 2037 counts per second.) (c) For 1 % we need N >= 100 counts: interval >= 100 / 2037.2 = 0.0491 s = about 49 ms. At 0.05 m/s: counts per second = 0.05 / 0.00019635 = 254.6; in 25 ms: 254.6 x 0.025 = 6.4 counts; error about 1 / 6.4 = 15.7 %. Time to collect 100 counts at 0.05 m/s: 100 / 254.6 = 0.393 s (nearly 0.4 s of delay, which is why a long interval is a poor choice for a control loop; timing the gap between counts is the usual answer at low speed). (d) Forward is 00, 10, 11, 01, 00. The decoder sees 00, 01, 11, 10, 00, which is the REVERSE order (00 to 01 is -1, 01 to 11 is -1, 11 to 10 is -1, 10 to 00 is -1). Net count = -4, which is one full cycle backward (the wheel turned backward by 4 counts = 4 x 0.28125 = 1.125 degrees at the wheel). The sequence 00, 11 is a jump of two states: either a transition was missed (the interrupt was too slow, or the signal glitched) or the encoder moved faster than the decoder could follow. The table gives 0 for it, because the direction cannot be known, and the position count is now uncertain by 2 counts. (e) Potentiometer: 270 / 1024 = 0.2637 degrees per count (before any noise). 12-bit absolute encoder: 360 / 4096 = 0.0879 degrees. 14-bit absolute encoder: 360 / 16384 = 0.0220 degrees. (f) 9000 rpm = 150 rev/s. Counts per second = 150 x 64 = 9600. Processor share = 9600 x 10 microseconds = 9600 x 0.00001 = 0.096 = 9.6 %. That is acceptable for one encoder, but a robot has two wheels (19.2 %) and the same processor has other work, so a fast encoder is a good reason for a hardware counter or a quadrature decoder chip (Basic Electronics 10 gives the rules for a short interrupt routine).