How do I make drivetrain coast instead of brake?

I’m always having trouble with my robot having its motion stunted. For example, when I quickly switch directions forward and backward, the entire robot is lifted off the front or back two wheels. I am already fixing the balance of the robot to try and prevent this, but are there any code changes to make the motors for the wheels to coast? Do I set this in the motor initialization part or in the main user control task?

Here’s my motor initialization:

// A global instance of competition
competition Competition;
controller Controller1;
motor leftFront = motor (PORT1);
motor leftBack = motor (PORT2);
motor rightFront = motor (PORT3, true);
motor rightBack = motor (PORT4, true);

And here is the my user control:

void usercontrol(void) {
 // User control code here, inside the loop
 while (1) {
   leftFront.spin(directionType::fwd, Controller1.Axis3.position(), pct);
   leftBack.spin(directionType::fwd, Controller1.Axis3.position(), pct);
   rightFront.spin(directionType::fwd, Controller1.Axis2.position(), pct);
   rightBack.spin(directionType::fwd, Controller1.Axis2.position(), pct);

Will this code work, or do I need to add something else?

\\ I’m sorry I have poor English

I think this is a problem of mechanical structure rather than program.Do you have a high center of gravity?You should try to lower the center of gravity.

The brake type you set only valid for Motor.stop().It won’t work when Motor.spin() called.

1 Like

Yes I think that would work, but I usually write it like this:


But I think that is all you would need.

1 Like

all you need is motor.setStopping(coast);

1 Like

Sorry, yes,


Hold is what I have on mine.

This doesn’t sound like a programming problem, and instead sounds more like a weight distribution problem and a driving problem. If quickly going from full forward to full reverse tips your robot, then you can try getting better at not doing that when you drive, and instead try to move the stick more smoothly.


You have to remember that coast, hold and brake modes for the motor only apply when the motor is actually stopped. If you send a motor command to spin the motors in the opposite direction while is is moving, the expected result with a light and possibly unbalanced robot is as you are observing.


I actually had this problem with our robot a while back. This might be a built-in PID problem, as Percent uses it. Maybe voltage might be better.

Consider Replacing:

exampleDTmotor.spin(vex::forward, wishpercent, vex::percent);

And Instead:

exampleDTmotor.spin(vex::forward, (wishpercent / 100) * 12, volt);

This should fix coasting if this was the issue. Also consider moving the setStopping() or brakeType() to the pre_auton function

Also, make sure that whatever variable you use for controlling is a double or float(wishpercent), as you do divide by 100

Do you know what the pre auton function does?

The function is supposed to run before autonomous code, and the reason it might be better to move it there is because you really only need to call the brakeType once

Well then do you know the difference between setStopping and setBrake is? Or is there none?

setBrake is an old deprecated API, we changed the name to setStopping a couple of years ago to better reflect it’s functionality. They do the same thing.