I’d like to make a kind of cross between a function, and a task. A function is easy to use, and can take parameters. A task cannot take parameters, but can use waits in parallel to a main control task. Is there a simple way to make a function run in parallel to the main task?
I think the answer is a state machine, which I have had no experience with before. I looked at this thread on the RobotC forums, and I think I can make a simple one for my purposes. This brings me to my next question; should I create a struct/array for each different movement (drive/catapult) or create two to three global variables for each different movement.
These are simple questions, but I couldn’t find anything on the forums already, maybe I wan’t using the right search terms. Any links to helpful threads are also very appreciated
It sounds to me like you want a thread or process.
Good news and bad news. Bad news is that without an operating system you’re not getting processes or threads. Good news is that tasks can work like that and in fact do in PROS.
Can be a pointer to anything you want, an int, char, array index, or even a struct. This is exactly how I used it in my Toss Up code.
typedef struct GoOnwardPayload {
int speed;
bool lock;
Time timeout;
bool success;
char * name;
} GoOnwardPayload;
Later…
void goOnwardTask(void * payload) {
// Cast the void * to something usable
GoOnwardPayload * data = (struct GoOnwardPayload*) payload;
// ...
// Call goOnward in this task
data->success = goOnward(data->axle, data->distance, data->loop, data->speed, data->timeout);
// ...
}
Later (in a Spongebob narrator accent)…
// Calculate the speed proportions
GoOnwardPayload * a = malloc(sizeof(GoOnwardPayload));
GoOnwardPayload * b = malloc(sizeof(GoOnwardPayload));
// ...
// Spawn two tasks, one for the F-L & R-R Axle, and one for the R-L & F-R
taskCreate(goOnwardTask, TASK_DEFAULT_STACK_SIZE, a, TASK_PRIORITY_DEFAULT);
taskCreate(goOnwardTask, TASK_DEFAULT_STACK_SIZE, b, TASK_PRIORITY_DEFAULT);
So you have a task, which accepts a payload pointer (in my case it’s a GoOnwardPayload struct).
You call that task (goOnwardTask(void * payload)) which in my case does some setup and calls into a function called goOnward().
Thanks for the quick reply My robotics teacher doesn’t want us to use PROS because apparently at a previous worlds there was a last minute firmware update that meant that PROS didn’t function properly. Add that to the fact that RobotC is now free and he wants us to stick to RobotC.
Do you have any suggestions on how it might work for RobotC?
Thanks, but I was more asking how to run a state machine, or threads or processes in RobotC. I am already using a separate task to operate the catapult in user control.
p.s. use the URL tags like this, (@curiousworx your link goes to www.example.com, not the RobotC wiki)
@DarkMatterMatt I know you are referring to Worlds 2015 - Vex Skyrise, Vex’s updated firmware that was released, and subsequent issues that occurred for the Purdue team at worlds. We diagnosed the issue and found the root cause of the issue. When the PROS projects were initially created for our robots Westinghouse & Otis, an alpha build of the PROS kernel was checked into their git repos. This alpha kernel did not have the overhaul of the SPI communication between the master processor and Cortex-m3 in addition to updated PWM drivers that you find in the current 2b10 kernel. Due to these missing updates we were plagued by what appeared to be “malfunction motors” but in fact was just he wrong code being executed.
After this discovery I have extensively vetted the 2b10 kernel that is currently available and found 0 issues with the Cortex 4.25 firmware & Vexnet 2.0 1.46 firmware. If your mentor has any questions in regards to this I would be more then happy to answer them. Please have him PM me.