00001 /* 00002 * ActiveBehaviorContainer.hpp 00003 * 00004 * Created on: Mar 13, 2012 00005 * Author: mriedel 00006 */ 00007 00008 #ifndef ACTIVEBEHAVIORCONTAINER_HPP_ 00009 #define ACTIVEBEHAVIORCONTAINER_HPP_ 00010 00011 #include <telekyb_defines/telekyb_defines.hpp> 00012 #include <telekyb_defines/enum.hpp> 00013 00014 #include <telekyb_base/Options.hpp> 00015 00016 #include <tk_state/StateEstimatorController.hpp> 00017 00018 #include <tk_behavior/Behavior.hpp> 00019 #include <tk_behavior/BehaviorControllerOptions.hpp> 00020 00021 // boost 00022 #include <boost/thread.hpp> 00023 00024 // ENUM 00025 TELEKYB_ENUM(TransitionState, 00026 (Active) 00027 (Termination) 00028 (Creation) 00029 ) 00030 00031 00032 // Forward declaration 00033 class BehaviorController; 00034 00035 namespace TELEKYB_NAMESPACE 00036 { 00037 00038 class ActiveBehaviorContainer { 00039 protected: 00040 Behavior* activeBehaviorPtr; // Behavior Pointer. 00041 00042 BehaviorControllerOptions& options; 00043 00044 // StateEstimatorController Instance! 00045 StateEstimatorController& seController; 00046 00047 // BehaviorController Instance for Callbacks 00048 BehaviorController& behaviorController; 00049 00050 // Boost Threading stuff 00051 boost::thread behaviorChangeThread; 00052 boost::mutex behaviorChangeMutex; 00053 // Behavior ChangeRequestMutex. One cannot ask for BehaviorSwitch during Trajectory Callback 00054 boost::mutex behaviorChangeRequestMutex; 00055 00056 // Variables from thread 00057 TransitionState transitionState; 00058 00059 void switchToBehaviorThread(Behavior* newBehavior); 00060 00061 // Interface for Switch from TKTrajectory. 00062 void switchToBehaviorInt(Behavior* newBehavior); 00063 00064 bool checkNewBehavior(Behavior* newBehavior) const; 00065 00066 public: 00067 ActiveBehaviorContainer(Behavior* initialActiveBehavior); 00068 virtual ~ActiveBehaviorContainer(); 00069 00070 // Trajectory Step for active Behavior 00071 void trajectoryStep(const TKState& currentState, TKTrajectory& generatedTrajInput); 00072 00073 // Switch to Behavior. External Request. 00074 bool switchToBehavior(Behavior* newBehavior); 00075 00076 Behavior* getActive() const; 00077 00078 }; 00079 00080 } // namespace 00081 00082 #endif /* ACTIVEBEHAVIORCONTAINER_HPP_ */ 00083