In that code, interrupts are not disabled before the encoder count is read. Wont this create an error if the count is read at the same time an interrupt is triggered? Is there a way to simply delay the processing of that interrupt till after the encoder count is read?
Disabling the interrupt, reading the value, then enabling it, it would simply ignore any interrupt and your count would be off if you got unlucky, right?
In either situation the interrupt would be missed, whether enabled or not. It works on this assumption:
time to read signal after interrupt << time it takes for the next interrupt to trigger
That assumption will always be true on a typical microcontroller . . . unless your robot is going at light speeds . . .