@@ -183,41 +183,17 @@ class BtActionNode : public BT::ActionNodeBase
183183 send_new_goal ();
184184 }
185185
186- // if new goal was sent and action server has not yet responded
187- // check the future goal handle
188- if (future_goal_handle_) {
189- auto elapsed = (node_->now () - time_goal_sent_).to_chrono <std::chrono::milliseconds>();
190- if (!is_future_goal_handle_complete (elapsed)) {
191- // return RUNNING if there is still some time before timeout happens
192- if (elapsed < server_timeout_) {
193- return BT::NodeStatus::RUNNING;
194- }
195- // if server has taken more time to respond than the specified timeout value return FAILURE
196- RCLCPP_WARN (
197- node_->get_logger (),
198- " Timed out while waiting for action server to acknowledge goal request for %s" ,
199- action_name_.c_str ());
200- future_goal_handle_.reset ();
201- return BT::NodeStatus::FAILURE;
202- }
203- }
204-
205- // The following code corresponds to the "RUNNING" loop
206- if (rclcpp::ok () && !goal_result_available_) {
207- // user defined callback. May modify the value of "goal_updated_"
208- on_wait_for_result ();
209-
210- auto goal_status = goal_handle_->get_status ();
211- if (goal_updated_ && (goal_status == action_msgs::msg::GoalStatus::STATUS_EXECUTING ||
212- goal_status == action_msgs::msg::GoalStatus::STATUS_ACCEPTED))
213- {
214- goal_updated_ = false ;
215- send_new_goal ();
186+ try {
187+ // if new goal was sent and action server has not yet responded
188+ // check the future goal handle
189+ if (future_goal_handle_) {
216190 auto elapsed = (node_->now () - time_goal_sent_).to_chrono <std::chrono::milliseconds>();
217191 if (!is_future_goal_handle_complete (elapsed)) {
192+ // return RUNNING if there is still some time before timeout happens
218193 if (elapsed < server_timeout_) {
219194 return BT::NodeStatus::RUNNING;
220195 }
196+ // if server has taken more time than the specified timeout value return FAILURE
221197 RCLCPP_WARN (
222198 node_->get_logger (),
223199 " Timed out while waiting for action server to acknowledge goal request for %s" ,
@@ -227,12 +203,48 @@ class BtActionNode : public BT::ActionNodeBase
227203 }
228204 }
229205
230- callback_group_executor_.spin_some ();
206+ // The following code corresponds to the "RUNNING" loop
207+ if (rclcpp::ok () && !goal_result_available_) {
208+ // user defined callback. May modify the value of "goal_updated_"
209+ on_wait_for_result ();
210+
211+ auto goal_status = goal_handle_->get_status ();
212+ if (goal_updated_ && (goal_status == action_msgs::msg::GoalStatus::STATUS_EXECUTING ||
213+ goal_status == action_msgs::msg::GoalStatus::STATUS_ACCEPTED))
214+ {
215+ goal_updated_ = false ;
216+ send_new_goal ();
217+ auto elapsed = (node_->now () - time_goal_sent_).to_chrono <std::chrono::milliseconds>();
218+ if (!is_future_goal_handle_complete (elapsed)) {
219+ if (elapsed < server_timeout_) {
220+ return BT::NodeStatus::RUNNING;
221+ }
222+ RCLCPP_WARN (
223+ node_->get_logger (),
224+ " Timed out while waiting for action server to acknowledge goal request for %s" ,
225+ action_name_.c_str ());
226+ future_goal_handle_.reset ();
227+ return BT::NodeStatus::FAILURE;
228+ }
229+ }
231230
232- // check if, after invoking spin_some(), we finally received the result
233- if (!goal_result_available_) {
234- // Yield this Action, returning RUNNING
235- return BT::NodeStatus::RUNNING;
231+ callback_group_executor_.spin_some ();
232+
233+ // check if, after invoking spin_some(), we finally received the result
234+ if (!goal_result_available_) {
235+ // Yield this Action, returning RUNNING
236+ return BT::NodeStatus::RUNNING;
237+ }
238+ }
239+ } catch (const std::runtime_error & e) {
240+ if (e.what () == std::string (" send_goal failed" ) ||
241+ e.what () == std::string (" Goal was rejected by the action server" ))
242+ {
243+ // Action related failure that should not fail the tree, but the node
244+ return BT::NodeStatus::FAILURE;
245+ } else {
246+ // Internal exception to propogate to the tree
247+ throw e;
236248 }
237249 }
238250
0 commit comments