Motor.spinFor time without blocking program

I’m attempting to get the intake on my robot to spin for a length of time, and I need it to run the rest of the program while the intake spins. However, I can’t seem to get it to work. I’m using VEXcode text, fully up-to-date, and the in-program documentation has barely enough info to even use the command.

The command I’m getting the error on is Motor.spinFor(vex::directionType::fwd, 10, vex::timeUnits::sec, false);, and the error is too many arguments.

Motor.spinFor(vex::directionType::fwd, 10, vex::rotationUnits::rev, false); works fine, as does Motor.spinFor(vex::directionType::fwd, 10, vex::timeUnits::sec);, but adding a false to the timeUnits one so that it will run the next line without blocking the program breaks it.

Is there any way to run for a length of time without blocking the program?

I looked through the files and it does not appear you can run spinFor with a false statement at the end if you are using time units. I would suggest using a task instead or turn on the motor, let it run a couple of other actions, then turn off.

You could just say motor.spin(directionType::fwd,100,velocityUnits::pct); That would run for as long as you don’t give a command to the motor. If you don’t want that, you should probably just find out the rotations that you need and put that in for spinFor.

if the in IDE help is insufficient, you can find the API docs here

using spinFor time without blocking didn’t really make much sense, the logic of a spinFor when blocking would be (in pseudo code)

motor.spin( fwd );
wait for some requested time
motor.stop();
return

so a non blocking form of that which skips the wait is really just

motor.spin( fwd );

you can create another task (or thread, same thing) to run that logic if you need it to be happening at the same time as other commands in the program.

1 Like

That makes sense. I forgot that Motor.spin would run until given a different input. Thank you!

1 Like