How to control a DC motor with an encoder