Make two motors work at the same time

Hello :), I need help with something. I’m having trouble with a line of code. . . I was trying to make two motors work at the same time but one starts at different times. Any help, recommendation, inspiration will be appreciated thanks. I’ll leave the code at the bottom.

if (Controller1.ButtonDown.pressing()){

RollerBottomBack.setVelocity(100, vex::percentUnits::pct);
RollerTopBack.setVelocity(100, vex::percentUnits::pct);

//Motors that need to move at the same time

RollerBottomBack.spinFor(vex::directionType::fwd,1000, vex::rotationUnits::deg);
RollerTopBack.spinFor(vex::directionType::rev,1000, vex::rotationUnits::deg);

}

There is a fourth parameter you can add to the spinFor function - bool waitForCompletion.
So if you say RollerBottomBack.spinFor(vex::directionType::fwd,1000, vex::rotationUnits::deg, false); then it won’t wait for the back roller to finish and will run both at the same time.

3 Likes

Thank you. I appreciate your time.

Have a nice day :slight_smile:

2 Likes

@ashatoolsidas is right. Your final code should look like this

RollerBottomBack.spinFor(vex::directionType::fwd,1000, vex::rotationUnits::deg, false);
RollerTopBack.spinFor(vex::directionType::rev,1000, vex::rotationUnits::deg); 
4 Likes