Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <XmlRpcException.h>
00042 #include <boost/exception/diagnostic_information.hpp>
00043
00044 #include <mbf_abstract_nav/abstract_recovery_execution.h>
00045
00046 namespace mbf_abstract_nav
00047 {
00048
00049
00050 AbstractRecoveryExecution::AbstractRecoveryExecution(
00051 const std::string name,
00052 mbf_abstract_core::AbstractRecovery::Ptr recovery_ptr,
00053 const TFPtr &tf_listener_ptr,
00054 const MoveBaseFlexConfig &config,
00055 boost::function<void()> setup_fn,
00056 boost::function<void()> cleanup_fn) :
00057 AbstractExecutionBase(name, setup_fn, cleanup_fn),
00058 behavior_(recovery_ptr), tf_listener_ptr_(tf_listener_ptr), state_(INITIALIZED)
00059 {
00060
00061 reconfigure(config);
00062 }
00063
00064 AbstractRecoveryExecution::~AbstractRecoveryExecution()
00065 {
00066 }
00067
00068
00069 void AbstractRecoveryExecution::reconfigure(const MoveBaseFlexConfig &config)
00070 {
00071 boost::lock_guard<boost::mutex> guard(conf_mtx_);
00072
00073
00074
00075 patience_ = ros::Duration(config.recovery_patience);
00076
00077
00078 }
00079
00080
00081 void AbstractRecoveryExecution::setState(RecoveryState state)
00082 {
00083 boost::lock_guard<boost::mutex> guard(state_mtx_);
00084 state_ = state;
00085 }
00086
00087
00088 typename AbstractRecoveryExecution::RecoveryState AbstractRecoveryExecution::getState()
00089 {
00090 boost::lock_guard<boost::mutex> guard(state_mtx_);
00091 return state_;
00092 }
00093
00094 bool AbstractRecoveryExecution::cancel()
00095 {
00096 cancel_ = true;
00097
00098 if(!behavior_->cancel())
00099 {
00100 ROS_WARN_STREAM("Cancel recovering failed or is not supported by the plugin. "
00101 << "Wait until the current recovery behavior finished!");
00102 return false;
00103 }
00104 return true;
00105 }
00106
00107 bool AbstractRecoveryExecution::isPatienceExceeded()
00108 {
00109 boost::lock_guard<boost::mutex> guard1(conf_mtx_);
00110 boost::lock_guard<boost::mutex> guard2(time_mtx_);
00111 ROS_DEBUG_STREAM("Patience: " << patience_ << ", start time: " << start_time_ << " now: " << ros::Time::now());
00112 return !patience_.isZero() && (ros::Time::now() - start_time_ > patience_);
00113 }
00114
00115 void AbstractRecoveryExecution::run()
00116 {
00117 cancel_ = false;
00118
00119 time_mtx_.lock();
00120 start_time_ = ros::Time::now();
00121 time_mtx_.unlock();
00122 setState(RECOVERING);
00123 try
00124 {
00125 outcome_ = behavior_->runBehavior(message_);
00126 if (cancel_)
00127 {
00128 setState(CANCELED);
00129 }
00130 else
00131 {
00132 setState(RECOVERY_DONE);
00133 }
00134 }
00135 catch (boost::thread_interrupted &ex)
00136 {
00137 setState(STOPPED);
00138 }
00139 catch (...){
00140 ROS_FATAL_STREAM("Unknown error occurred: " << boost::current_exception_diagnostic_information());
00141 setState(INTERNAL_ERROR);
00142 }
00143 condition_.notify_one();
00144 }
00145 }