Like this?
-
the higher the tolerance, the earlier it starts braking. Play with it a little to get that little overshoot.
-
deceleration is acceleration in reverse, so if I can know from current speed where I want to stop, I just have to flip the acceleration.