anjockey.cpp
Go to the documentation of this file.
00001 #include <featurenav_base/anjockey.h>
00002 
00003 namespace featurenav_base {
00004 
00005 ANJockey::ANJockey(const std::string& name, const std::string& segment_interface_name) :
00006   nh_(),
00007   private_nh_("~"),
00008   segment_interface_name_(segment_interface_name),
00009   learning_(false),
00010   navigating_(false)
00011 {
00012   // Debug log level
00013   if(ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug))
00014   {
00015     ros::console::notifyLoggerLevelsChanged();
00016   }
00017 
00018   if (!initMapSegmentInterface())
00019   {
00020     throw ros::Exception("Initialization error");
00021   }
00022 
00023   ajockey_ptr_.reset(new AJockey(name + "_learner", segment_interface_name_, segment_setter_name_));
00024   // TODO: add segment_getter_name_ parameter.
00025   njockey_ptr_.reset(new NJockey(name + "_navigator", segment_interface_name_, segment_getter_name_));
00026 
00027   // Initialize the clients for the LaserScan getter and setter services (interface to map).
00028   ajockey_ptr_->canDo = (can_do_function_ptr) boost::bind(&ANJockey::canDo, this, _1);
00029   njockey_ptr_->canDo = (can_do_function_ptr) boost::bind(&ANJockey::canDo, this, _1);
00030   ajockey_ptr_->startDo = (start_do_function_ptr) boost::bind(&ANJockey::startDo, this, _1);
00031   njockey_ptr_->startDo = (start_do_function_ptr) boost::bind(&ANJockey::startDo, this, _1);
00032 }
00033 
00034 /* Create the getter and setter services for Segment messages.
00035  */
00036 bool ANJockey::initMapSegmentInterface()
00037 {
00038   ros::ServiceClient client = nh_.serviceClient<lama_interfaces::AddInterface>("interface_factory");
00039   ROS_DEBUG_STREAM(ros::this_node::getName() << ": waiting for service /interface_factory");
00040   client.waitForExistence();
00041   lama_interfaces::AddInterface srv;
00042   srv.request.interface_name = segment_interface_name_;
00043   srv.request.interface_type = lama_interfaces::AddInterfaceRequest::SERIALIZED;
00044   srv.request.get_service_message = "featurenav_base/GetSegment";
00045   srv.request.set_service_message = "featurenav_base/SetSegment";
00046   if (!client.call(srv))
00047   {
00048     ROS_ERROR_STREAM("Failed to create the Lama interface " << segment_interface_name_);
00049     return false;
00050   }
00051   segment_getter_name_ = srv.response.get_service_name;
00052   segment_setter_name_ = srv.response.set_service_name;
00053   return true;
00054 }
00055 
00056 std::string ANJockey::getLearningJockeyName() const
00057 {
00058   if (ajockey_ptr_ == NULL)
00059   {
00060     return "";
00061   }
00062   return ajockey_ptr_->getName();
00063 }
00064 
00065 std::string ANJockey::getNavigatingJockeyName() const
00066 {
00067   if (njockey_ptr_ == NULL)
00068   {
00069     return "";
00070   }
00071   return njockey_ptr_->getName();
00072 }
00073 
00074 void ANJockey::setExtractFeaturesFunction(feature_extractor_function_ptr f)
00075 {
00076   ajockey_ptr_->setExtractFeaturesFunction(f);
00077   njockey_ptr_->setExtractFeaturesFunction(f);
00078 }
00079 
00080 void ANJockey::setDescriptorMatcherFunction(descriptor_matcher_function_ptr f)
00081 {
00082   ajockey_ptr_->setDescriptorMatcherFunction(f);
00083   njockey_ptr_->setDescriptorMatcherFunction(f);
00084 }
00085 
00086 bool ANJockey::canDo(const action_type action)
00087 {
00088   if (learning_ && (action == NAVIGATE))
00089     return false;
00090   if (navigating_ && (action == LEARN))
00091     return false;
00092   return true;
00093 }
00094 
00095 void ANJockey::startDo(const action_type action)
00096 {
00097   learning_ = (action == LEARN);
00098   navigating_ = (action == NAVIGATE);
00099 }
00100 
00101 } // namespace featurenav_base
00102 
00103 


featurenav_base
Author(s): Gaƫl Ecorchard
autogenerated on Sat Jun 8 2019 19:52:22