PROS: Task Usage

My team programmer uses PROS and uses task to run a predefined cap movement at the same time while the robot moves in autonomous mode.

The PROS website on multitasking states that “The most important thing to remember when using tasks is that every task should include an infinite loop ( while(true) ), and every infinite loop needs to include a delay() or task_delay_until() statement.”

She implemented the predefined cap function/task without the while() loop - thinking that the task would just run the code thru completion and exits. The auton program would use the task_create() each time she wants to use the cap function. She does not use task_delete(). The program seems to run fine so far.

Question: Is there a side-effect we do not know about?

Can you post the cap movement task?

I do not have her codes, but it looks something like this:

void capMove (void *parm)  {
    motor_set_zero_position (CAP_PORT);
    motor_move (CAP_PORT, 80);
    while (motor_get_position (CAP_PORT) < some_value) {
        delay (10);
    motor_move (CAP_PORT, 0);

it’s basically fine to leave your tasks like that. when task functions exit, they perform the same cleanup code as would be done when calling task_delete manually.

of course, it’s always possible to refactor the task you have so that it doesn’t have to get re-created every time you want to execute it, even if it’s not strictly necessary :slightly_smiling_face:

Good to know. :grinning:

Thank you for the clarification.

We will look into refactoring the task after that state championship.