explore_action.cpp
Go to the documentation of this file.
00001 #include <explore_hrl/explore_action.h>
00002 
00003 #include <boost/thread.hpp>
00004 #include <boost/bind.hpp>
00005 
00006 using namespace explore_hrl;
00007 
00008 namespace explore {
00009 
00010 ExploreAction::ExploreAction( std::string name ) :
00011   node_(),
00012   e_( NULL ),
00013   action_name_( name ),
00014   as_( nh_, name, boost::bind( &ExploreAction::executeCB, this, _1 ), false )
00015 {
00016   ros::NodeHandle private_nh("~");
00017   //e_ = new Explore();
00018   as_.start();
00019 }
00020 
00021 ExploreAction::~ExploreAction() {
00022   if(e_ != NULL)
00023     delete e_;
00024 }
00025 
00026 void ExploreAction::executeCB( const explore_hrl::ExploreGoalConstPtr &goal ){
00027   ROS_INFO( "%s: Action Initiated with radius %3.2f", action_name_.c_str(), goal->radius );
00028   bool success = true;
00029 
00030   if(e_ != NULL)
00031     ROS_INFO("%s: Action Destroying old explore", action_name_.c_str());
00032     delete e_;
00033 
00034   ROS_INFO( "%s: Action modifying parameters", action_name_.c_str(), goal->radius );
00035 
00036   ros::NodeHandle private_nh("~");
00037   private_nh.setParam("explore_costmap/raytrace_range", goal->radius + 0.1 );
00038   private_nh.setParam("explore_costmap/obstacle_range", goal->radius );
00039 
00040   // Give everything a second to settle before reinitializing.
00041   ros::Duration(1.0).sleep();
00042 
00043   ROS_INFO("%s: Action Creating new explore", action_name_.c_str());
00044   e_ = new Explore();
00045 
00046   ros::spinOnce();
00047   e_ -> setPreemptFlag( false );
00048   boost::thread t(boost::bind( &Explore::execute, e_ ));
00049 
00050   ros::Rate r(10.0);
00051   while (node_.ok() && (!e_->doneExploring())) {
00052     if (as_.isPreemptRequested() || !ros::ok()){
00053         ROS_INFO("%s: Action Preempted", action_name_.c_str());
00054         as_.setPreempted();
00055         e_ -> setPreemptFlag( true );
00056         success = false;
00057         break;
00058     }
00059     r.sleep();
00060   }
00061 
00062   if (success){
00063     ROS_INFO("%s: Action Succeeded", action_name_.c_str());
00064     as_.setSucceeded();
00065   }
00066 
00067   t.join();
00068 
00069   ROS_INFO("%s: Action Exiting", action_name_.c_str());
00070   //ros::spin();
00071   //e_ -> spin();
00072   //as_.setSucceeded();
00073 }
00074 
00075 }
00076 
00077 int main(int argc, char** argv){
00078   ros::init(argc, argv, "explore");
00079 
00080   explore::ExploreAction explore_action( ros::this_node::getName() );
00081   ros::spin();
00082 
00083   return(0);
00084 }
00085 


explore_hrl
Author(s): Travis Deyle
autogenerated on Wed Nov 27 2013 11:48:01