Wait needed to avoid hogging CPU when multitasking?

Hello,

When multitasking, do I have to put the wait command in each of my tasks? How does this work?

Thanks in advance.

You will want some sort of delay inside the while loops of each of your tasks. Adding the delay gives the cortex time to run other tasks, from the other ones you’ve created to the cortex’s own tasks that do things like update the motors or read the joystick. Without a delay, the cortex will have no time to do anything else. For example, if you set a motor to a certain speed in a task loop, but have no delay, the cortex will not have time to run its own task that actually gives the motor that level of power.

I’d say that usually, just putting some size of delay at the end of the while loop in each of your tasks will be enough. My own tasks will mostly have a delay from 25-100 milliseconds, depending on what they do.

ROBOTC is very tolerant to not using a delay in loops, however, it’s generally good practice to do that as it will help the task scheduler keep everything running smoothly. There a long discussion of how the ROBOTC scheduler works in this thread but in general all you really need to do is place a 10mS wait in loops that are waiting on sensors or driving motors.

https://vexforum.com/t/discussion-on-using-tasks-in-robotc/33025/1

Giving time back to the scheduler is more important in PROS and ConVEX, some of the background processing will stop if you don’t do that.