Vex Coding Studio Brake Bug?

All,

My students have stumbled upon a unique scenario. During one of their auton routines, they park at the end and brake. They specifically use the function:


Motor1.stop(brakeType::brake);

However, after switching from auton to driver control- their driver control still has the brake type applied. This was verified by running driver control first before auton and NOT experiencing the same braking.

Is there a reason that auton functions are effecting those outside if its scope?

Anyone else experience this?

That’s normal and expected behavior, it’s all part of the same program, we do not reset anything you may do in main or any other thread that you may start from main when the robot changes between the different phases of a competition. The same was true for cortex and programs written in ROBOTC.

For clarification: If they were to select a different brake type… maybe coast… would this not be noticeable?

If you still want you brake at the end of auton you can still have that just after your while loop for your drive set the motors to coast

like this
int drive()
{
leftDrive1.setStopping(vex::brakeType::coast);
leftDrive2.setStopping(vex::brakeType::coast);
rightDrive1.setStopping(vex::brakeType::coast);
rightDrive2.setStopping(vex::brakeType::coast);
while(true)
{
rightStick = Controller1.Axis2.value();
leftStick = Controller1.Axis3.value();
right motors = one of the joysticks
left motors = one of the joysticks
}
leftDrive1.setStopping(vex::brakeType::coast);
leftDrive2.setStopping(vex::brakeType::coast);
rightDrive1.setStopping(vex::brakeType::coast);
rightDrive2.setStopping(vex::brakeType::coast);
}

I would also have a buffer to make it work better

that would look like this
int drive()
{
int leftStick;
int rightStick;

leftDrive1.setStopping(vex::brakeType::coast);
leftDrive2.setStopping(vex::brakeType::coast);
rightDrive1.setStopping(vex::brakeType::coast);
rightDrive2.setStopping(vex::brakeType::coast);

while(true)
{
rightStick = Controller1.Axis2.value();
leftStick = Controller1.Axis3.value();

right motors = one of the joysticks
left motors = one of the joysticks

if(abs(rightStick) < 3)
rightStick = 0;
if(abs(leftStick) < 3)
leftStick = 0;
}

leftDrive1.setStopping(vex::brakeType::coast);
leftDrive2.setStopping(vex::brakeType::coast);
rightDrive1.setStopping(vex::brakeType::coast);
rightDrive2.setStopping(vex::brakeType::coast);

}

I have a similar issue. We were doing a simple if/else in a while(true) loop, where a button press set the brake mode to Hold, or else the brake mode was set to coast.

The program started and the motor was in coast. The button was pressed, and the motor went to hold. The button was released and the motor stayed at hold. We aren’t sure why the hold condition persists.

so you were doing this ?

  while(1) {
    if( Controller.ButtonX.pressing() ) {
      motor1.setStopping( brakeType::hold );
    }
    else {
      motor1.setStopping( brakeType::coast );
    }    

    // Allow other tasks to run
    this_thread::sleep_for(10);
  }

Basically. We were using a limit switch instead of a controller, and didn’t have a thread sleep.

ok, we will take another look but there’s no reason why hold would persist if the motor was told to use coast mode.

If you have a while(true){} loop, it will never exit unless you create a break (in which case I find it generally better to put that condition in instead of using “true”). That means you’ll never execute the code following it. Generally when using while(true), you want to set everything general ahead of time and then enter that infinite loop, while varying things will probably be set within the loop, but nothing after the loop.