Expand|Select|Wrap|Line Numbers
- Behavior * myBeh = new Wander;
Expand|Select|Wrap|Line Numbers
- void *hndl = dlopen(filename.c_str(), RTLD_LAZY); // dynamically load the library, we'll try to handle errors later.
- if(hndl == NULL)
- {
- cerr << "File Boo Boo: " << dlerror() << endl;
- exit(-1);
- }
- cout << "loaded " << name << " behavior." << endl;
- create_t* create_type = (create_t*) dlsym(hndl, "maker"); // run maker function to generate instance
- if (!create_type)
- {
- cerr << "Symbol Boo Boo: " << dlerror() << '\n';
- exit(1);
- }
- beh = create_type();
Expand|Select|Wrap|Line Numbers
- #include "Wander.h"
- Wander::Wander()
- {
- ...
- }
- Wander::~Wander()
- {
- ...
- }
- Behavior * Wander::maker()
- {
- return new Wander;
- };
Expand|Select|Wrap|Line Numbers
- #ifndef _WANDER_H
- #define _WANDER_H
- #include <pthread.h>
- #include <string>
- #include "../../State.h"
- #include "../Action.h"
- #include "../Leaf.h"
- using namespace std;
- #define PI 3.14159265359
- class Wander : public Leaf
- {
- private:
- pthread_mutex_t mutex;
- pthread_t behaviorthread;
- State* curr_state;
- Action* curr_action;
- int turnCounter;
- double velocity;
- double turnrate;
- void Lock();
- void Unlock();
- static void* DummyMain(void*);
- public:
- Behavior * maker();
- Wander();
- virtual ~Wander();
- void StartThread();
- void StopThread();
- void Main();
- Action* updAction(State* curr_state);
- Action* genAction();
- };
- #endif
Expand|Select|Wrap|Line Numbers
- #ifndef LEAF_H
- #define LEAF_H
- #include "Behavior.h"
- #include "Action.h"
- /**
- * A simple behavior, that is, one that is comprised of only a
- * single goal.
- */
- class Leaf: public Behavior
- {
- public:
- virtual Behavior * maker()
- {
- return NULL;
- };
- Leaf(){}
- virtual ~Leaf()
- {}
- virtual Action* genAction()
- {
- return NULL ;
- }
- virtual void StartThread()
- {};
- virtual void StopThread()
- {};
- };
- #endif /* LEAF_H */
Expand|Select|Wrap|Line Numbers
- #ifndef _BEHAVIOR_H
- #define _BEHAVIOR_H
- #include <vector>
- #include <string>
- #include "Action.h"
- using namespace std;
- /**
- * Base class for the robot behaviors.
- */
- class Behavior
- {
- protected:
- string name;
- public:
- virtual Behavior * maker()
- {
- return NULL;
- };
- Behavior()
- {}
- virtual ~Behavior()
- {}
- /**
- * Generate an Action based on the current State.
- */
- virtual Action* genAction()
- {
- return NULL ;
- }
- virtual void StartThread()
- {}
- ;
- virtual void StopThread()
- {}
- ;
- };
- typedef Behavior * create_t();
- #endif /* _BEHAVIOR_H */