EDIT 2: Now i’m trying Jojo’s Queue idea but now i’m struggling trying to put function calls inside queues, I make a queue with:
Queue<std::function<void()>, 4> movementCommandQueue;
and try to put a no input void()
function like:
movementCommandQueue.put(fwd, 10);
and I get the error:
argument of type "void (*)()" is incompatible with parameter of type "std::function<void ()> *"
Using a function as a parameter like this works when I look at std docs for functions as parameters but not with Queue? Also, I tried to change queue to different format I saw for using functions as parameters like:
Queue<(void(*)), 4> movementCommandQueue;
but then I get the error:
expected a type specifier
EDIT: no longer trying to put a function inside a function inside a thread, but now I have a new runtime error trying to run a thread by its self
Im trying to call a command to move my wheels in a separate thread, but allow it to be interrupted with a new command/lack of new command being executed in the main thread, but I get this memory related error at runtime. Is there something I forgot to do?
Im using an LPC1768 if that’s relevant
Code:
//placeholder function to erase previously queued command
void placeholder(){
}
//function i’m trying to call
void fwd() {
//Allows wheels to move
xEN = 0;
yEN = 0;
//Sets direciton to hopefully forward
xDIR = 1;
yDIR = 0;
while(1){
xSTP = 1;
ySTP = 1;
delayus(usPulseSpeed);
xSTP = 0;
ySTP = 0;
delayus(usPulseSpeed);
}
}
//In command manager function
moveThread.terminate();
moveThread.start(fwd);
//In main
moveThread.start(placeholder);