Does anyone know how to let the motor in the spinFor command stop slowly or coast?

My bot is travelling the distance I tell it to, but when the distance is reached, it abruptly stops, causing its angle to change slightly. I could change my motors to a far slower velocity to minimize inertia, but I need the bot to complete tasks fast in order to gain the advantage. This is the code for my four-motor drive system:

LeftFront.spinFor(forward, turns, degrees, false);
LeftBack.spinFor(forward, turns, degrees, false);
RightFront.spinFor(forward, turns, degrees, false);
RightBack.spinFor(forward, turns, degrees, false);

The variables have already been initialized.

I think you would use motor.setStopping(coast). However, I don’t think that will help you. Using coast will cause your robot to roll additional distance after stopping. If you want it to be precise and fast I recommend looking into writing a PID controller. Here are 2 resources for learning how to write a PID:
PID controller - BLRS wiki
George gillard PID document


Wow thanks! I had no idea this was even a thing. I had thought about calculus but figured it would be too complicated; this looks like something I can do. Very helpful.

I have seen good results using voltage control, and ramping the voltage down as you approach your target. Adjust the slope of the ramp until you are stopping in target with no wheel slip. This is essentially a progressive controller. Progressive is the P in PID. It’s more primitive, but it’s easier.

You can play the same trick when accelerating to speed to prevent wheel slip there