C++ Non-Blocking time units

How do I use non-blocking code to make a motor spin for time (timeUnits not rotationUnits)?

Whenever I write: LeftFrontDrive.rotateFor(2.5,timeUnits::sec,100, velocityUnits::pct, false);

I get the error

/vexv5/include/vex_motor.h:221:23: note: candidate function not viable: requires at most 6 arguments, but 7 were provided
bool rotateFor( directionType dir, double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );

Is there a reason why you are stating velocityUnits::pct twice? I’m not a skilled programmer so I don’t know but that could be your problem.

If it’s not why not just use like
or something like that then wait 2.5 secs with
then just stop the motor with
or however you want to stop.

Easy way - use tasking.

looking at the VCS API, this isn’t possible the way you want to do it.
You’ll have to use a separate task, switch to using rotation units, or do some fancy timer-based stuff in the same task.

I don’t know how. Please enlighten me.

This would go outside of any loops, like any other function would.

int taskName()
   while(1) {
        /*Task stuff in here, for example a button if pressed loop*/
        vex::this_thread::sleep_for(25); /*prevent wasted resources*/

You then put this in the driver loop(if you want to use during driver)

        vex::task t(pulltask);

I am unfortunately old school and don’t know anything about V5 or VEX C++ so I can’t really help but in general whatever it is you want to do while the motor is running should go in another task. Tasks are scheduled in the blocks of time when other tasks are blocked by the framework.

Tasks are not really ANSI C, they’re added for VEX hardware in ROBOTC, PROS, VCS, whatever. It’s part of the API and you’ll need to learn the specifics and the semantics.

You are adding a second velocityunits , which is unnecessary and throws syntax errors.
LeftFrontDrive.rotateFor(2.5,vex::timeUnits:sec,50,velocityUnits::pct) should be all you need. The false is not needed since the motor defaults to forward when a Boolean is not supplied.

You could set a timeout, then startRotateTo to a large number:

    Motor1.startRotateTo(20,rotationUnits::rev, 100, velocityUnits::pct );