00001 /* 00002 * SystemBehaviorContainer.cpp 00003 * 00004 * Created on: Nov 12, 2011 00005 * Author: mriedel 00006 */ 00007 00008 #include <tk_behavior/SystemBehaviorContainer.hpp> 00009 00010 namespace TELEKYB_NAMESPACE { 00011 00012 SystemBehaviorContainer::SystemBehaviorContainer() 00013 { 00014 // Unneeded, but out of correctness. 00015 normalBrake = NULL; 00016 hover = NULL; 00017 ground = NULL; 00018 00019 // Load SystemBehaviors 00020 loadSystemBehaviors(); 00021 } 00022 00023 SystemBehaviorContainer::~SystemBehaviorContainer() 00024 { 00025 00026 } 00027 00028 void SystemBehaviorContainer::loadSystemBehaviors() 00029 { 00030 // OK this is NOT done dynamically. Adding and modifying of SystemBehaviors is done here! 00031 00032 // load 00033 normalBrake = static_cast<NormalBrake*>(loadBehavior( "tk_behavior/NormalBrake" )); 00034 hover = static_cast<Hover*>(loadBehavior( "tk_behavior/Hover" )); 00035 ground = static_cast<Ground*>(loadBehavior( "tk_behavior/Ground" )); 00036 00037 emergencyLand = static_cast<EmergencyLand*>(loadBehavior( "tk_behavior/EmergencyLand" )); 00038 00039 // load (not externally visible) 00040 TakeOff* takeOff = static_cast<TakeOff*>(loadBehavior( "tk_behavior/TakeOff" )); 00041 Land* land = static_cast<Land*>(loadBehavior( "tk_behavior/Land" )); 00042 00043 // check MANDATORY! 00044 if (!(normalBrake && hover && ground && emergencyLand && takeOff && land)) { 00045 ROS_FATAL("An Error occured while trying to load essential System Behaviors!"); 00046 //ROS_BREAK(); 00047 ros::shutdown(); 00048 } 00049 00050 // init TODO? 00051 00052 // set follow up behaviors 00053 normalBrake->setNextBehavior(hover); 00054 land->setNextBehavior(ground); 00055 emergencyLand->setNextBehavior(ground); 00056 } 00057 00058 Behavior* SystemBehaviorContainer::loadBehavior(const std::string& behaviorClassName) 00059 { 00060 if ( systemBehaviorMap.count(behaviorClassName) > 0 ) { 00061 ROS_ERROR_STREAM("Tried to load System Behavior with Name " << behaviorClassName << " twice!"); 00062 return NULL; 00063 } 00064 00065 Behavior* b = BehaviorContainer::loadBehavior(behaviorClassName); 00066 // if != NULL -> add 00067 if ( b ) { 00068 systemBehaviorMap[ behaviorClassName ] = b; 00069 } 00070 return b; 00071 } 00072 00073 Hover* SystemBehaviorContainer::getHover() const 00074 { 00075 return hover; 00076 } 00077 Ground* SystemBehaviorContainer::getGround() const 00078 { 00079 return ground; 00080 } 00081 NormalBrake* SystemBehaviorContainer::getNormalBrake() const 00082 { 00083 return normalBrake; 00084 } 00085 00086 EmergencyLand* SystemBehaviorContainer::getEmergencyLand() const 00087 { 00088 return emergencyLand; 00089 } 00090 00091 Behavior* SystemBehaviorContainer::getBehaviorByName(const std::string& behaviorClassName) const { 00092 Behavior* b = NULL; 00093 if ( systemBehaviorMap.count(behaviorClassName) > 0 ) { 00094 b = systemBehaviorMap.at(behaviorClassName); 00095 } 00096 return b; 00097 } 00098 00099 00100 } /* namespace telekyb */