Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Tasks? (http://www.chiefdelphi.com/forums/showthread.php?t=83497)

DjMaddius 23-02-2010 20:18

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 (*)(...)'"

gvarndell 23-02-2010 20:39

Re: Tasks?
 
Quote:

Originally Posted by DjMaddius (Post 927456)
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 (*)(...)'"

Looks like you've got a smiley face in there somewhere.:ahh:

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.

DjMaddius 23-02-2010 21:11

Re: Tasks?
 
Quote:

Originally Posted by gvarndell (Post 927480)
Looks like you've got a smiley face in there somewhere.:ahh:

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.

Should i make it void?

I put an int because thats how i saw it in a previous code.

slavik262 23-02-2010 23:12

Re: Tasks?
 
(FUNCPTR)neumaticSystem::lop should work fine.

byteit101 27-02-2010 08:17

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);

mikets 27-02-2010 09:58

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.

ericand 27-02-2010 14:27

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::Drive(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.

DjMaddius 28-02-2010 13:31

Re: Tasks?
 
Quote:

Originally Posted by byteit101 (Post 929329)
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);

Thanks! This fixed my problem.

Its always the simplest of things isnt it? -.-


All times are GMT -5. The time now is 13:07.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi