This Arduino program is refered from: https://github.com/cswiger/dcservodrive by cswiger.
It is used to control 2 DC motors and 2 optical encoders from printer head frame by step/ direction signals. In this project, DC motors can be simulated as same as stepper motors and we can control them via GRBL firmware for CNC application. Check 3 axis CNC plotter (built from printer head frame which has DC motors and optical encoders) which is used this Arduino sketch at my YouTube:
https://www.youtube.com/watch?v=Qe13E-eHeJg
The detail description is posted on Instructables website:
https://www.instructables.com/id/3-AXIS-CNC-PLOTTER-FROM-DC-MOTORS-AND-OPTICAL-ENCO/