![]() ![]() *Assuming your joystick and jaguar are members of In your main robot class, create an instance of this struct and set its members to point to their respective Joystick and Jaguar classes. Notice how the function takes the integer argument and casts it into a pointer for your use. SpinTaskArgs struct you passed into the function*/ *Do stuff with args, which is now a pointer to the SpinTaskArgs* args = (SpinTaskArgs*)argPtr We’ll also write our function for the task: The entire process would be something like this:Ĭreate a struct that contains all the data you’d need (in this case pointers to a Joystick and a Jaguar class). Say you want a separate that spins a motor using a jaguar based on a joystick input (there’s no reason why you couldn’t just put it in the main task, but it’s just an example). This works because the operating system the robot uses is a 32-bit OS, which means that its pointers are the same length as a 32-bit integer. You set an integer argument to the address of what you want to pass in, and cast it back to a pointer in the function. If you’re careful, you can trick your way around this and still do the same thing. However, for whatever reason, VxWorks (the robot’s Operating System) only allows you to pass in integers. This lets you pass in a pointer to anything you want, and then use it in your function by just casting it back to its correct type. Normally (in any other multithreading library I’ve used), thread/task functions take a void pointer as an argument. Start can take anywhere from 0 to 10 integer values, which are passed as arguments to the task function. ![]() To start your task, call the Start() method of the Task class you created. The defaults will work fine, and messing with the task priority can cause the program to behave unexpectedly. Leave the task priority and stack size (the last two arguments in the constructor) alone unless you know what you’re doing. This provides the memory address of where your function is located in the program so that the task can call it when it starts up. Use (FUNCPTR)myFunction, where myFunction is the name of your task function. The second argument is a function pointer to your task function. The constructor takes a name for the class (pick whatever you want - this is just the name the task will have once created) as the first argument. To actually start the function in a different thread, create a Task class. I’ll go over how to pass data into your function in a second. Note that this function will not automatically loop, so you’ll need a loop structure unless you want it to do its work and exit immediately. ![]() To create a task, first write a task function (the function that will run in the separate thread). Someone asked for help with Task creation and semaphores here, but I think this warrants its own thread.ĭue to my work in other systems, I’m using task and thread interchangeably in this explanation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |