Behavior.cpp
Go to the documentation of this file.
00001 /*
00002  * Behavior.cpp
00003  *
00004  *  Created on: Nov 15, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <telekyb_interface/Behavior.hpp>
00009 
00010 #include <boost/lexical_cast.hpp>
00011 using boost::lexical_cast;
00012 
00013 // ROS Services
00014 #include <telekyb_srvs/BehaviorInput.h>
00015 #include <telekyb_srvs/BehaviorOutput.h>
00016 #include <telekyb_srvs/BoolInput.h>
00017 
00018 
00019 #include <telekyb_interface/BehaviorController.hpp>
00020 
00021 namespace TELEKYB_INTERFACE_NAMESPACE {
00022 
00023 Behavior::Behavior()
00024 {
00025         setNull();
00026 }
00027 
00028 Behavior::Behavior(uint64_t behaviorID_, const std::string& behaviorName_, BehaviorController* behaviorController_)
00029         : behaviorID(behaviorID_),
00030           behaviorName(behaviorName_),
00031           behaviorController(behaviorController_),
00032           behaviorNodeHandle(behaviorController->getNodeHandle(), lexical_cast<std::string>(behaviorID_))
00033 {
00034 
00035 }
00036 
00037 Behavior::~Behavior()
00038 {
00039 
00040 }
00041 
00042 void Behavior::setNull()
00043 {
00044         behaviorID = (uint64_t)NULL;
00045         behaviorName = "";
00046         // nodeHandle is default.
00047 }
00048 
00049 uint64_t Behavior::getBehaviorID() const
00050 {
00051         return behaviorID;
00052 }
00053 
00054 std::string Behavior::getBehaviorName() const
00055 {
00056         return behaviorName;
00057 }
00058 
00059 void Behavior::setNextBehavior(const Behavior& behavior)
00060 {
00061         ros::ServiceClient client = behaviorNodeHandle.serviceClient<telekyb_srvs::BehaviorInput>(BEHAVIOR_SETNEXTBEHAVIOR);
00062         telekyb_srvs::BehaviorInput service;
00063         service.request.behaviorID = behavior.getBehaviorID();
00064         service.request.behaviorName = behavior.getBehaviorName();
00065         if (! client.call(service) ) {
00066                 ROS_ERROR_STREAM("Failed to call: " << client.getService());
00067         }
00068 }
00069 
00070 Behavior Behavior::getNextBehavior()
00071 {
00072         ros::ServiceClient client = behaviorNodeHandle.serviceClient<telekyb_srvs::BehaviorOutput>(BEHAVIOR_GETNEXTBEHAVIOR);
00073         telekyb_srvs::BehaviorOutput service;
00074         if (! client.call(service) ) {
00075                 ROS_ERROR_STREAM("Failed to call: " << client.getService() << "! Returning NULL-Behavior.");
00076                 return Behavior();
00077         }
00078         return Behavior(service.response.behaviorID, service.response.behaviorName, behaviorController);
00079 }
00080 
00081 void Behavior::setParameterInitialized(bool initialized_)
00082 {
00083         ros::ServiceClient client = behaviorNodeHandle.serviceClient<telekyb_srvs::BoolInput>(BEHAVIOR_SETPARAMINIT);
00084         telekyb_srvs::BoolInput service;
00085         service.request.input = initialized_;
00086         if (! client.call(service) ) {
00087                 ROS_ERROR_STREAM("Failed to call: " << client.getService());
00088         }
00089 }
00090 
00091 // get OptionContainer
00092 OptionContainer Behavior::getOptionContainer()
00093 {
00094         // returns the OptionContainer associated with the Behavior
00095         return OptionContainer(behaviorController->getOptionController(), behaviorName + "/" + lexical_cast<std::string>(behaviorID));
00096 
00097 }
00098 
00099 bool Behavior::isNull() const
00100 {
00101         return (behaviorID == (uint64_t)NULL);
00102 }
00103 
00104 // Operators
00105 bool operator==(Behavior& lhs, Behavior& rhs)
00106 {
00107         //ROS_INFO("called Behavior == Behavior");
00108         // Temp implementation // only IDs matter
00109         return (lhs.behaviorID == rhs.behaviorID);
00110 }
00111 bool operator!=(Behavior& lhs, Behavior& rhs)
00112 {
00113         return !(lhs == rhs);
00114 }
00115 
00116 } /* namespace telekyb_interface */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_interface
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:12:47