taskCreate not working?

Hello, I’m trying to initialize a task using taskCreate, but getting the error "use of undeclared identifier taskCreate. Here is the declaration code I am using.

    pros::task_t LBThread = taskCreate (moveLBDrive, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT);

Try this pros::Task Threadname(Yourfunction, (void*)"PROS", TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task");

2 Likes

Ok, I tried doing this. Now, it’s saying: "No matching constructor for initialization of pros::Task

  `pros::Task LBThread(moveLBDrive, (void*)"PROS", TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task");`

put this in your function paramiters “void* param” it should look like this moveLBDrive(void* param) {

Why, that seems to have fixed it! Thank you so much for your help!

NP, make sure to mark this as solved.

To recap, here is a simple task creation example:

void myTaskFnc(void* ignore) {
  //the void* is there to provide a way to pass a 
  //generic value or structure to the task if needed
  //pros needs this parameter in your function even if you don't use it
  while(true) {
    pros::delay(20);
  }
}

void opcontrol() {
  pros::Task myTask(myTaskFnc); //starts the task
  // no need to provide any other parameters

  pros::task_t myTask = taskCreate(myTaskFnc); 
  // alternative C-style way of starting task
}
3 Likes

Thank you! This is a very good summary and example for anyone else who was confused as I was :smile:

2 Likes