Brake Hold Toggle

I’ve coded our team’s bot to set the motors to brake type hold to avoid being pushed if the driver presses the down arrow button, but I can’t figure out how to make it stop holding either when the driver lets go or presses it again, like a toggle. This is my code so far, but it would prevent the bot from being driven:

if (Controller1.ButtonDown.pressing() == true) {
      if (holdToggle == false) {
        holdToggle = true;
      } else {
        holdToggle = false;
      }
}
if (holdToggle == true) {
      Fl.stop(hold);
      Fr.stop(hold);
      Bl.stop(hold);
      Br.stop(hold);
    } else {
      Fl.stop(coast);
      Fr.stop(coast);
      Bl.stop(coast);
      Br.stop(coast);
}

note the brain screen update thread was just while i was testing it.

this might help, replace the boolean assignment with brake /velocity code for your motors.


bool go = true;
int updateBrainScreen(){
    while(1){
        Brain.Screen.setCursor(2,0);
        Brain.Screen.clearLine();
        Brain.Screen.print(go);
        vex::this_thread::sleep_for(500);
    }
    return -1;
}
void brakePress(){
    go = false;
}
void brakeUnPress(){
go = true;
}
void test(){
myController.ButtonUp.pressed(brakePress);
myController.ButtonUp.released(brakeUnPress);
    vex::thread brainUpdateLoop(updateBrainScreen);
}

The logic looks like it should work, I think the problems is that the stop function sets the motor speed to zero. I think the function you are looking for is setStopping, which doesn’t stop the motor but tells it how to behave when it does stop.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.