Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "yocs_navigator/semantic_navigator.hpp"
00007
00008 namespace yocs_navigator {
00009
00010 SemanticNavigator::SemanticNavigator(ros::NodeHandle& n)
00011 : nh_(n), basic_move_(n),
00012 as_navi_(nh_, SemanticNavigatorDefaultParam::AS_NAVI, false),
00013 ac_move_base_(nh_, SemanticNavigatorDefaultParam::AC_MOVE_BASE, true)
00014 {
00015 sub_waypointlist_topic_= SemanticNavigatorDefaultParam::SUB_WAYPOINTLIST;
00016 }
00017
00018 SemanticNavigator::SemanticNavigator(ros::NodeHandle& n, const std::string& as_navigator_topic, const std::string& sub_waypointlist_topic)
00019 : nh_(n), basic_move_(n),
00020 as_navi_(as_navigator_topic, false),
00021 ac_move_base_(SemanticNavigatorDefaultParam::AC_MOVE_BASE, true)
00022 {
00023 sub_waypointlist_topic_= sub_waypointlist_topic;
00024 }
00025
00026 SemanticNavigator::~SemanticNavigator()
00027 {
00028 }
00029
00030 bool SemanticNavigator::init()
00031 {
00032 ros::NodeHandle pnh("~");
00033
00034 pnh.param("global_frame", global_frame_, std::string("map"));
00035
00036 distance_to_goal_ = 0.0f;
00037 waypoint_received_ = false;
00038 navigation_in_progress_ = false;
00039
00040 loginfo("Wait for move_base");
00041 ac_move_base_.waitForServer();
00042
00043 loginfo("Wait for waypoint lists");
00044 sub_waypointlist_ = nh_.subscribe(sub_waypointlist_topic_, 1, &SemanticNavigator::processWaypointList, this);
00045 while(ros::ok() && !waypoint_received_) {
00046 ros::spinOnce();
00047 ros::Duration(0.5).sleep();
00048 }
00049
00050 loginfo("Initialized");
00051 as_navi_.registerGoalCallback(boost::bind(&SemanticNavigator::processNavigateToGoal, this));
00052 as_navi_.registerPreemptCallback(boost::bind(&SemanticNavigator::processPreemptNavigateTo, this));
00053 as_navi_.start();
00054
00055 return true;
00056 }
00057
00058 void SemanticNavigator::processWaypointList(const yocs_msgs::WaypointList::ConstPtr& msg)
00059 {
00060 waypointlist_ = *msg;
00061 waypoint_received_ = true;
00062 }
00063
00064 void SemanticNavigator::processNavigateToGoal()
00065 {
00066 if(navigation_in_progress_)
00067 {
00068 as_navi_.acceptNewGoal();
00069 terminateNavigation(false, "Navigation under progress yet.. Ignoring");
00070 return;
00071 }
00072
00073 navigation_in_progress_ = true;
00074 order_process_thread_ = boost::thread(&SemanticNavigator::processNavigation, this, as_navi_.acceptNewGoal());
00075 }
00076
00077 void SemanticNavigator::processPreemptNavigateTo()
00078 {
00079 logwarn("Navigation Preemption Requested");
00080 as_navi_.setPreempted();
00081 }
00082
00083 void SemanticNavigator::spin()
00084 {
00085 ros::Rate r(2);
00086
00087 init();
00088
00089 while(ros::ok())
00090 {
00091 ros::spinOnce();
00092 r.sleep();
00093 }
00094 }
00095
00096 }