Rotary encoders are useful tools for measuring rotation on a shaft. They come in many different forms, including optical, mechanical, and magnetic. In this video, we show you how they work and how to use them on DC motors to ensure that a robot drives in a straight line for a set distance.
Optical encoder demo: https://www.hackster.io/ShawnHymel/quadrature-encoder-demo-dea334
Code for making Fred drive in a straight line: https://gist.github.com/ShawnHymel/1de08ffaca990b65fade81cb8d01a44a