@Nathan1, you don’t really need if statements here, because rotateFor() function could accept an additional argument, which tells it to wait for the rotation completion:
rotateFor(double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
If you know that nothing would prevent “on” motor to reach the target position, then your code could look like this:
int main()
{
On.rotateFor(5.35,timeUnits::sec,15,velocityUnits::pct, true);
Main.rotateFor(5,timeUnits::sec,30,velocityUnits::pct,true);
Off.spin(directionType::fwd,30,velocityUnits::rpm);
}
However, if there is a chance that “On” motor could run into something then you will need code like this:
int main()
{
On.rotateFor(5.35,timeUnits::sec,15,velocityUnits::pct, false);
while(On.isSpinning) { vex::task::sleep(5); }
Main.rotateFor(5,timeUnits::sec,30,velocityUnits::pct,false);
while(Main.isSpinning) { vex::task::sleep(5); }
Off.spin(directionType::fwd,30,velocityUnits::rpm);
vex::task::sleep(2000); // let it run for 2 seconds
Off.stop();
}
The reference pages for Task.sleep() and Motor.isSpinning() functions:
https://help.vexcodingstudio.com/#pro/namespacevex/classvex_1_1task/sleep
https://help.vexcodingstudio.com/#cpp/namespacevex/classvex_1_1motor/isSpinning
Also, next time you may want to wrap your code into BBCode [code]...[/code]
tags for better readability (you can even edit your post and add them now).