Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Commander Class Reference

#include <Commander.h>

Inheritance diagram for Commander:

Thread List of all members.

Detailed Description

Activates and switches between the behaviors of the robot (current implementation: Exploring, Pushing, Avoiding, Communicating. Communicating only when using local communication - see system model). The decision which behavior to activate is based on the current state of the commander and the return code it receives from the last activated behavior. Once a behavior has served its purpose it will return with a result code. The commander does not actively interrupt activated behaviors.
Author:
Jia L. Du


Public Member Functions

 Commander ()
void doSleep (int hundredthSeconds)
void doReschedule (void)
bool spawn ()
void initialize (void)

Protected Member Functions

void run (void)

Static Protected Member Functions

void staticRun (void)

Private Attributes

int state
Explorer explorer
Pusher pusher
Avoider avoider
Communicator communicator

Static Private Attributes

Commander * mes [NUMBER_OF_ROBOTS]
const int EXPLORING = 0
const int PUSHING = 1
const int AVOIDING = 2
const int COMMUNICATING = 3


Constructor & Destructor Documentation

Commander::Commander  
 

Constructor for Commander. Standard parameters for Commander are passed to the Thread constructor


Member Function Documentation

void Commander::doReschedule void   
 

Tells the commander that the current behavior has nothing to do right now and would like to cede control to another thread

void Commander::doSleep int    hundredthSeconds
 

Tells the commander that the calling behavior would like to sleep for at least n hundredth seconds

Parameters:
hundredthSeconds 

void Commander::initialize void   
 

The simulator does not allow the usage of RoBIOS functions in class constructors. Therefore we use public initialize methods for classes that need RoBIOS functions for their initializations.

void Commander::run void    [protected]
 

The method is overwritten by the inheritor. When the thread starts the code in this run method is executed

Reimplemented from Thread.

bool Commander::spawn  
 

According to C++ convention, methods cannot be static and virtual at once. In the initial design run was declared as virtual which results in dynamic binding. That means the program determines at run-time which run method to use, the one of the Thread base class or the one of the inheritor. Because we have to use staticRun, we cannot use the virtual keyword anymore. Without the virtual keyword the compiler determines at compile-time which run method is used, always the run method of the Thread base class. To ensure that the inheritor indeed uses its own run method, it is necessary to overwrite the thread initialization method (spawn) as well.

See also:
staticRun
Returns:
true if successful

Reimplemented from Thread.

void Commander::staticRun void    [static, protected]
 

Static wrapper method for run. It does nothing but to call run. That is necessary because the RoBIOS multi-tasking functions expect a pointer to a C-function (not a pointer to a C++ method) containing the code to be executed. Fortunately, pointer-to-static-C++-methods are compatible with regular pointer-to-C-functions. But the problem is that static methods can only use other static methods and variables. The reasons is that a static method, which is shared by all instances, would not know which non-static method or variable to use if there were multiple instances of the same class. Thus, the static property would have to be applied to all used (sub-)methods and (sub-) variables, and propagate through the whole class structure. By using staticRun, we can keep using our non-static run. If static methods cannot call non-static ones, how can staticRun call run? As aforementioned the reason why static method cannot use non-static members is because it is not clear which non-static member to use if there are multiple instances of the same class. That means staticRun needs a pointer to the instance whose run method is to be called. This pointer is stored in a static member variable called me.

See also:
me


Member Data Documentation

Avoider Commander::avoider [private]
 

The Commander switches to the Avoider behavior when necessary

const int Commander::AVOIDING = 2 [static, private]
 

Used by the class to keep track of its own state

const int Commander::COMMUNICATING = 3 [static, private]
 

Used by the class to keep track of its own state

Communicator Commander::communicator [private]
 

The Commander switches to the Communicator behavior when necessary

Explorer Commander::explorer [private]
 

The Commander switches to the Explorer behavior when necessary

const int Commander::EXPLORING = 0 [static, private]
 

Used by the class to keep track of its own state

Commander * Commander::mes [static, private]
 

Stores pointers to instances of Commander

See also:
staticRun

Pusher Commander::pusher [private]
 

The Commander switches to the Pusher behavior when necessary

const int Commander::PUSHING = 1 [static, private]
 

Used by the class to keep track of its own state

int Commander::state [private]
 

Used by the class to keep track of its current state. Possible states are Commander::EXPLORING, Commander::PUSHING, Commander::AVOIDING and Commander::COMMUNICATING (Note: Commander::COMMUNICATING only when local communication is used. See system model)


Generated on Mon Aug 26 18:34:08 2002 for Cube Clustering by doxygen1.3-rc3