Controller for a DC motor for moving 18 cm constantly
It looks like you are only using distance remaining as your control variable.

You also need to use velocity, that is, rate of arrival of pulses, or number of pulses per sample cycle. 

You can then use that to calculate your required speed/deceleration rate and come to a halt where you desire, possibly even back driving the motor(s) to act as a brake if need be.