|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Tasks?
Can someone explain to me how to do the VxWorks tasks?
Currently our code isnt working. Task loopingTask("SpinTask", (FUNCPTR)(int(PneumaticSystem::lop))); Doesnt work. Get error "error: argument of type `int (PneumaticSystem: ()' does not match `int (*)(...)'" |
|
#2
|
||||
|
||||
|
Re: Tasks?
Quote:
Why did you insert 'int' right in front of the left paren? Are you trying to cast (PneumaticSystem::lop)? The FUNCPTR macro should be all the cast you need. |
|
#3
|
||||
|
||||
|
Re: Tasks?
Quote:
I put an int because thats how i saw it in a previous code. |
|
#4
|
||||
|
||||
|
Re: Tasks?
(FUNCPTR)neumaticSystem::lop should work fine.
|
|
#5
|
||||
|
||||
|
Re: Tasks?
you need to make the function static, or you can add tons of gobbeldygook (I would add static in front of the function)
also, if you are in your class, you can just use Task loopingTask("SpinTask", (FUNCPTR)lop); |
|
#6
|
||||
|
||||
|
Re: Tasks?
You have to be careful when using tasks. Tasks are run concurrently. In a preemptive multi-tasking environment, you need to use semaphores to protect against resources being accessed by concurrent tasks (take a look at the notifier as an example). If you are not familiar with this concept, I would advise against using them. You can easily implement the effect of tasks by using cooperative multi-tasking. IterativeRobot class is such an example. In cooperative multi-tasking, tasks can only be switched away if the task chooses to do so. For example, in IterativeRobot, consider AutonomousPeriodic is a task. It got run in every StartCompetition loop, just like a task got run periodically. But the difference is that you are guaranteed that nobody changes the robot state while you are executing your AutonomousPeriodic code.
|
|
#7
|
||||
|
||||
|
Re: Tasks?
We use several tasks for doing things that need to happen continuously and which have limited interaction with the other portions of the program. For example, we have a task that controls the motor power change rate.
What we do is have a non class based function which we call to start the task. The method used is somewhat similar to that used in the compressor. We create a class for the operation in question to contain the data to be shared and the methods for accessing that data. The class also contains the task variable. class Drive { Task motorControlTask; .... public: Drive(); ~Drive(); Drive(UINT32, UINT32); }; The .cpp file for this class contains a function outside of the class called motorLimitStub which takes as its argument a pointer to the class. The constructor for this class constructs this task. Drive: rive(UINT32 leftChan, UINT32 rightChan) :motorControlTask ("Motor Control Task", (FUNCPTR)motorLimitStub), The stub function that is called when the task is started looks like: static void motorLimitStub(Drive *bd) { bd->motorLimitTask(); } In this case, the drive class/task has complete ownership of the drive motor speed controls and monitors/adjusts the rate at which the motor speeds are allowed to change. No other part of the robot is allowed to adjust drive motor power levels. Instead, they post requests to the task, for a desired power level which the drive task will get to over some period of time. Last edited by ericand : 27-02-2010 at 14:32. Reason: Error in initial posting |
|
#8
|
||||
|
||||
|
Re: Tasks?
Quote:
Its always the simplest of things isnt it? -.- |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error creating tasks that use encoders | tbinns | C/C++ | 5 | 14-02-2010 10:28 |
| What are RobotC tasks? | daltore | Programming | 4 | 01-07-2009 08:59 |
| Periodic Tasks | Luke Pike | NI LabVIEW | 1 | 04-02-2009 01:14 |
| RobotC tasks | ratcateme | Programming | 1 | 07-11-2008 00:58 |
| First logo and tasks | Denman | Rumor Mill | 21 | 19-04-2005 11:32 |