|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to use tasks
I read the task section in the WPILib manual and the class help file, but when I'm having difficulty getting anything working. The example I'm giving has everything extra cut out. (spelling and code punctuation might not be right)
Code:
class 4174robot : public InterativeRobot
{
public:
4174robot();
...(Interative Robot Overrides)...
void TestTaskFunction();
...
private:
Task *task1;
...
};
4174robot:4174robot()
{
task1 = new Task("testtask", (VOIDFUNCPTR) TestTaskFunction();
}
...
4174robot:Teleopinit
{
task1->start;
}
...
4174robot:Disabledinit
{
task1->stop;
}
...
4174robot:TestTaskFunction()
{
std::cout<<"task has been started"<<endl;
}
Last edited by agartner01 : 07-02-2012 at 20:13. |
|
#2
|
||||
|
||||
|
Re: How to use tasks
Why do you need to use task? Are you comfortable with multi-tasking programming? To deal with multiple tasks, you need to understand the concept of protecting share resources when accessing them from different tasks (e.g. using semaphores). If you are not familiar with the concept, you may want to avoid using task.
Having said that, our team is using task to offload the vision processing so it doesn't bog down the main robot task. We have done some performance tests and found out that analyzing a frame takes about 150-200 msec. So if you are doing vision processing in your main robot task, you may need to set the safety expiration longer than the time required to process a frame. |
|
#3
|
|||
|
|||
|
Re: How to use tasks
1. The main reason I want to use a task is so that I can tell one system to do something while continuing to do something else.
2. No, I'm not really comfortable with multi-tasked programming. But what I'm trying to do won't be subject to multiple tasks trying to access the same systems. The task that I create will be the only one accessing the systems. |
|
#4
|
||||
|
||||
|
Re: How to use tasks
Code:
class 4174robot : public IterativeRobot
{
public:
...(Interative Robot Overrides)...
Task *task1;
4174robot();
~4174robot();
...
};
static void TestTaskFunction(void)
{
std::cout<<"task has been started"<<endl;
}
4174robot::4174robot()
{
task1 = new Task("testtask", (VOIDFUNCPTR) TestTaskFunction);
}
4174robot::~4174robot()
{
delete task1;
}
...
4174robot::Teleopinit()
{
task1->Start();
}
...
Disabledinit()
{
task1->Stop();
}
Last edited by mikets : 07-02-2012 at 22:17. |
|
#5
|
|||
|
|||
|
Re: How to use tasks
Alright, thanks alot... I'll try it tomorrow. I wish they would have put more of this in the WPILib Manual.
In addition to that, I noticed that you added the destructor. In a lot of other [FRC] examples, it seems like it is pretty much ignored. Just good coding practices or something more? Last edited by agartner01 : 07-02-2012 at 21:43. |
|
#6
|
||||
|
||||
|
Re: How to use tasks
Quote:
You will be surprise. It may not be obvious that you are accessing shared resources. Sometimes, you may be accessing it indirectly through calling another function or even the WPI library. That's why when there is a problem, it's very hard to debug. |
|
#7
|
|||
|
|||
|
Re: How to use tasks
I wasn't aware of the "cooperative multitasking" think. I'm just not sure how to go about it...
And replace all the absolutes (won't, never, etc) with shouldn't and such. I really do have absolutely no idea what I'm talking about... ![]() |
|
#8
|
|||
|
|||
|
Re: How to use tasks
Now I get this ->
|
|
#9
|
||||
|
||||
|
Re: How to use tasks
Ah, try this instead.
Code:
static void TestTaskFunction(void)
{
std::cout<<"task has been started"<<endl;
}
4174robot::4174robot()
{
task1 = new Task("testtask", (FUNCPTR) TestTaskFunction);
}
|
|
#10
|
|||
|
|||
|
Re: How to use tasks
Alright that works... I don't get it (FUNCPTR vs VOIDFUNCPTR), but it works.
Then I was like, why am I getting no output on my console. Then I remembered that the windriver console only works for the current task. (or something like that) Last edited by agartner01 : 08-02-2012 at 15:29. |
|
#11
|
||||
|
||||
|
Re: How to use tasks
No, not true. we printed debug output from a different task. I don't know if the picture showed the whole code but it doesn't seem to have the task1->Start() call. I don't think the task get started automatically when created. You need to explicitly start it.
|
|
#12
|
||||
|
||||
|
Re: How to use tasks
BTW, FUNCPTR and VOIDFUNCPTR are custom types. I don't have Wind River in front of me at the moment so I can't find the definitions of FUNCPTR and VOIDFUNCPTR for you. But I think VOIDFUNCPTR defines a function that returns void and FUNCPTR defines a function that returns an integer. Apparent, the task function should be returning an integer. Probably wouldn't matter but more correctly:
Code:
static int TestTaskFunction(void)
{
std::cout<<"task has been started"<<endl;
return 0;
}
4174robot::4174robot()
{
task1 = new Task("testtask", (FUNCPTR) TestTaskFunction);
}
Code:
Task(const char* name, FUNCPTR function, INT32 priority = kDefaultPriority, UINT32 stackSize = 20000); Last edited by mikets : 08-02-2012 at 15:38. |
|
#13
|
|||
|
|||
|
Re: How to use tasks
yeah, I have it later on. I'm using wtx console in windriver, not netconsole. If I put a mechanical task in the funcion it works, but not a cout. I'm trying printf now.
|
|
#14
|
||||
|
||||
|
Re: How to use tasks
Oh yeah, cout doesn't work, either printf or cerr will work.
|
|
#15
|
|||
|
|||
|
Re: How to use tasks
huh... printf dosen't work either. Are you using the wtx console in windriver?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|