abstract_recovery_execution.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018, Magazino GmbH, Sebastian Pütz, Jorge Santos Simón
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * abstract_recovery_execution.cpp
34  *
35  * authors:
36  * Sebastian Pütz <spuetz@uni-osnabrueck.de>
37  * Jorge Santos Simón <santos@magazino.eu>
38  *
39  */
40 
41 #include <boost/exception/diagnostic_information.hpp>
42 
44 
45 namespace mbf_abstract_nav
46 {
47 
49  const std::string &name,
50  const mbf_abstract_core::AbstractRecovery::Ptr &recovery_ptr,
51  const TFPtr &tf_listener_ptr,
52  const MoveBaseFlexConfig &config) :
54  behavior_(recovery_ptr), tf_listener_ptr_(tf_listener_ptr), state_(INITIALIZED)
55 {
56  // dynamically reconfigurable parameters
57  reconfigure(config);
58 }
59 
61 {
62 }
63 
64 
65 void AbstractRecoveryExecution::reconfigure(const MoveBaseFlexConfig &config)
66 {
67  boost::lock_guard<boost::mutex> guard(conf_mtx_);
68 
69  // Maximum time allowed to recovery behaviors. Intended as a safeward for the case a behavior hangs.
70  // If it doesn't return within time, the navigator will cancel it and abort the corresponding action.
71  patience_ = ros::Duration(config.recovery_patience);
72 
73  // Nothing else to do here, as recovery_enabled is loaded and used in the navigation server
74 }
75 
76 
78 {
79  boost::lock_guard<boost::mutex> guard(state_mtx_);
80  state_ = state;
81 }
82 
83 
85 {
86  boost::lock_guard<boost::mutex> guard(state_mtx_);
87  return state_;
88 }
89 
91 {
92  cancel_ = true;
93  // returns false if cancel is not implemented or rejected by the recovery behavior (will run until completion)
94  if (!behavior_->cancel())
95  {
96  ROS_WARN_STREAM("Cancel recovery behavior \"" << name_ << "\" failed or is not supported by the plugin. "
97  << "Wait until the current recovery behavior finished!");
98  return false;
99  }
100  return true;
101 }
102 
104 {
105  boost::lock_guard<boost::mutex> guard1(conf_mtx_);
106  boost::lock_guard<boost::mutex> guard2(time_mtx_);
107  ROS_DEBUG_STREAM("Patience: " << patience_ << ", start time: " << start_time_ << " now: " << ros::Time::now());
108  return !patience_.isZero() && (ros::Time::now() - start_time_ > patience_);
109 }
110 
112 {
113  cancel_ = false; // reset the canceled state
114 
115  time_mtx_.lock();
117  time_mtx_.unlock();
119  try
120  {
121  outcome_ = behavior_->runBehavior(message_);
122  if (cancel_)
123  {
125  }
126  else
127  {
129  }
130  }
131  catch (boost::thread_interrupted &ex)
132  {
133  ROS_WARN_STREAM("Recovery \"" << name_ << "\" interrupted!");
134  setState(STOPPED);
135  }
136  catch (...)
137  {
138  ROS_FATAL_STREAM("Unknown error occurred in recovery behavior \"" << name_ << "\": " << boost::current_exception_diagnostic_information());
140  }
141  condition_.notify_one();
142 }
143 
144 } /* namespace mbf_abstract_nav */
mbf_abstract_nav::AbstractRecoveryExecution::state_
RecoveryState state_
current internal state
Definition: abstract_recovery_execution.h:171
mbf_abstract_nav::AbstractRecoveryExecution::INTERNAL_ERROR
@ INTERNAL_ERROR
An internal error occurred.
Definition: abstract_recovery_execution.h:120
boost::shared_ptr< ::mbf_abstract_core::AbstractRecovery >
mbf_abstract_nav::AbstractExecutionBase::cancel_
bool cancel_
flag for canceling controlling
Definition: abstract_execution_base.h:123
ROS_FATAL_STREAM
#define ROS_FATAL_STREAM(args)
mbf_abstract_nav::AbstractRecoveryExecution::behavior_
mbf_abstract_core::AbstractRecovery::Ptr behavior_
the current loaded recovery behavior
Definition: abstract_recovery_execution.h:144
mbf_abstract_nav::AbstractExecutionBase::outcome_
uint32_t outcome_
the last received plugin execution outcome
Definition: abstract_execution_base.h:126
mbf_abstract_nav::AbstractRecoveryExecution::CANCELED
@ CANCELED
The recovery execution was canceled.
Definition: abstract_recovery_execution.h:118
mbf_abstract_nav::AbstractRecoveryExecution::patience_
ros::Duration patience_
recovery behavior allowed time
Definition: abstract_recovery_execution.h:165
mbf_abstract_nav::AbstractRecoveryExecution::start_time_
ros::Time start_time_
recovery behavior start time
Definition: abstract_recovery_execution.h:168
mbf_abstract_nav::AbstractRecoveryExecution::state_mtx_
boost::mutex state_mtx_
mutex to handle safe thread communication for the current state
Definition: abstract_recovery_execution.h:158
mbf_abstract_nav::AbstractRecoveryExecution::setState
void setState(RecoveryState state)
Sets the current internal state. This method is thread communication safe.
Definition: abstract_recovery_execution.cpp:77
mbf_abstract_nav
Definition: abstract_controller_execution.h:58
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
mbf_abstract_nav::AbstractRecoveryExecution::RECOVERING
@ RECOVERING
The recovery behavior plugin is running.
Definition: abstract_recovery_execution.h:115
ROS_WARN_STREAM
#define ROS_WARN_STREAM(args)
mbf_abstract_nav::AbstractExecutionBase::condition_
boost::condition_variable condition_
condition variable to wake up control thread
Definition: abstract_execution_base.h:114
mbf_abstract_nav::AbstractRecoveryExecution::isPatienceExceeded
bool isPatienceExceeded()
Checks whether the patience was exceeded.
Definition: abstract_recovery_execution.cpp:103
mbf_abstract_nav::AbstractRecoveryExecution::reconfigure
void reconfigure(const MoveBaseFlexConfig &config)
Reconfigures the current configuration and reloads all parameters. This method is called from a dynam...
Definition: abstract_recovery_execution.cpp:65
mbf_abstract_nav::AbstractRecoveryExecution::conf_mtx_
boost::mutex conf_mtx_
dynamic reconfigure and start time mutexes to mutually exclude read/write configuration
Definition: abstract_recovery_execution.h:161
mbf_abstract_nav::AbstractRecoveryExecution::RECOVERY_DONE
@ RECOVERY_DONE
The recovery behavior execution is done.
Definition: abstract_recovery_execution.h:117
abstract_recovery_execution.h
mbf_abstract_nav::AbstractRecoveryExecution::getState
AbstractRecoveryExecution::RecoveryState getState()
Returns the current state, thread-safe communication.
Definition: abstract_recovery_execution.cpp:84
mbf_abstract_nav::AbstractRecoveryExecution::~AbstractRecoveryExecution
virtual ~AbstractRecoveryExecution()
Destructor.
Definition: abstract_recovery_execution.cpp:60
mbf_abstract_nav::AbstractExecutionBase::message_
std::string message_
the last received plugin execution message
Definition: abstract_execution_base.h:129
mbf_abstract_nav::AbstractRecoveryExecution::STOPPED
@ STOPPED
The recovery execution has been stopped.
Definition: abstract_recovery_execution.h:119
mbf_abstract_nav::AbstractRecoveryExecution::AbstractRecoveryExecution
AbstractRecoveryExecution(const std::string &name, const mbf_abstract_core::AbstractRecovery::Ptr &recovery_ptr, const TFPtr &tf_listener_ptr, const MoveBaseFlexConfig &config)
Constructor.
Definition: abstract_recovery_execution.cpp:48
mbf_abstract_nav::AbstractExecutionBase
Base class for running concurrent navigation tasks.
Definition: abstract_execution_base.h:57
mbf_abstract_nav::AbstractRecoveryExecution::RecoveryState
RecoveryState
internal state.
Definition: abstract_recovery_execution.h:111
mbf_abstract_nav::AbstractRecoveryExecution::time_mtx_
boost::mutex time_mtx_
Definition: abstract_recovery_execution.h:162
mbf_abstract_nav::AbstractRecoveryExecution::run
virtual void run()
Main execution method which will be executed by the recovery execution thread_.
Definition: abstract_recovery_execution.cpp:111
ros::Duration
DurationBase< Duration >::isZero
bool isZero() const
mbf_abstract_nav::AbstractExecutionBase::name_
std::string name_
the plugin name; not the plugin type!
Definition: abstract_execution_base.h:132
ros::Time::now
static Time now()
mbf_abstract_nav::AbstractRecoveryExecution::cancel
virtual bool cancel()
Cancel the planner execution. This calls the cancel method of the planner plugin. This could be usefu...
Definition: abstract_recovery_execution.cpp:90


mbf_abstract_nav
Author(s): Sebastian Pütz
autogenerated on Wed Mar 2 2022 00:33:47