Multitasking issues in PROS

So I have a function to create some tasks in the beginning of my opcontrol and I get an error:

"Invalid use of void expression"

for both of those lines. I don’t get whats wrong because when I used this at home with my testing cortex, everything compiled 100% fine

void runTasks() { // or some other function
  TaskHandle setDriveVelTask = taskCreate(setDriveVelocities(), TASK_DEFAULT_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT);
  TaskHandle setLiftVelTask = taskCreate(setLiftVelocities(), TASK_DEFAULT_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT);

If someone can help provide some information as to why its not working that would be awesome!

Also, I know this is not very good code for tasks and I didn’t pick good names, this is my just first time trying to use them and figure them out.

I haven’t used PROS in a few months, but from what I remember about multi-tasking in PROS, what’s going wrong here is that when you specify what function you’re going to be running as a task, you add parenthesis at the end, which you’re not supposed to.

The PROS API says that the parameters for the taskCreate function require a TaskCode, which is the name of the function. What you’re giving them by adding parenthesis after the name is the return of the function, which If I’m correct in my assumption is void (the setDriveVelocities and setLiftVelocities are void).

A corrected version should look something like this:

void runTasks() { // or some other function
  TaskHandle setDriveVelTask = taskCreate(setDriveVelocities, TASK_DEFAULT_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT);
  TaskHandle setLiftVelTask = taskCreate(setLiftVelocities, TASK_DEFAULT_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT);

Notice the absence of parenthesis when specifying which function you want to task.

Also, a more generic runTasks function that I remember using:

void runTasks(TaskCode functions]) {
     for(int t = 0, t < arraySize(functions); t++) {
          taskCreate(functions[t], TASK_DEFAULT_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT);

The arraySize() that’s used in there is a custom little
bit that you’ll have to write in as a define or another function:

#define arraySize(a) sizeof(a)/sizeof(a[0])

Because C’s sizeof() method returns the space that something takes up, you can divide the total space the array takes up by the space on of its elements takes up in order t o get how many elements the array has.

I tried this and it still throws the same error. The thing that confuses me is The program worked perfectly fine at home when instead of setting velocities, we flashed LED’s.

I pushed my code last night, pulled it this morning at school and it won’t compile. The PROS Linter on my computer at school doesn’t like it for some reason

As @stephn said, you cannot use parenthesis in tasks. Could you provide the code for one of your functions? The PROS documentation gives the example of a function used in a task like the following:

void myFirstTask(void * parameter) {
  while(true) {
    printf("Hello from another task!\n");

You’ll notice that it takes a parameter

void * parameter

. In C, you are technically supposed to pass void into a function if it does not require any parameters. Obviously in PROS this is not necessary, but it may be when passing it into a task; I would try that and see what happens.

Oh yeah I think you’re right. I remember that now, I’ll try it out in our TSA meeting today and let you know

The reason it takes a


parameter is because you can optionally pass it arguments when you run the task using


. For more on why


is special, see this explanation.

Note that this is different from this function:

// returns nothing, takes no arguments
void function0(void) {
    printf("Hello world!\n");

where providing


is just an explicit way of saying the function takes no arguments. The following function is, in practice, exactly the same as the one above:

// returns nothing, takes an unspecified number of arguments of unspecified type
void function1() {
    printf("Hello world!\n");

The only difference is that calling


will produce an error, while


will produce a warning.