Thread: Tasks?
View Single Post
  #7   Spotlight this post!  
Unread 27-02-2010, 14:27
ericand's Avatar
ericand ericand is offline
Registered User
AKA: Eric Anderson
FRC #3765 (Terrabots)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: St. Paul, MN
Posts: 148
ericand is a jewel in the roughericand is a jewel in the roughericand is a jewel in the rough
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
Reply With Quote