Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BT Service Node to throw if service was not available in time #3256

Merged
merged 5 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
namespace nav2_behavior_tree
{

using namespace std::chrono_literals; // NOLINT

/**
* @brief Abstract class representing an action for cancelling BT node
* @tparam ActionT Type of action
Expand Down Expand Up @@ -87,7 +89,12 @@ class BtCancelActionNode : public BT::ActionNodeBase

// Make sure the server is actually there before continuing
RCLCPP_DEBUG(node_->get_logger(), "Waiting for \"%s\" action server", action_name.c_str());
action_client_->wait_for_action_server();
if (!action_client_->wait_for_action_server(1s)) {
RCLCPP_ERROR(
node_->get_logger(), "\"%s\" action server not available after waiting for 1 s",
action_name.c_str());
throw std::runtime_error(std::string("Action server %s not available", action_name.c_str()));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <string>
#include <memory>
#include <chrono>

#include "behaviortree_cpp_v3/action_node.h"
#include "nav2_util/node_utils.hpp"
Expand All @@ -26,6 +27,8 @@
namespace nav2_behavior_tree
{

using namespace std::chrono_literals; // NOLINT

/**
* @brief Abstract class representing a service based BT node
* @tparam ServiceT Type of service
Expand Down Expand Up @@ -71,7 +74,15 @@ class BtServiceNode : public BT::ActionNodeBase
RCLCPP_DEBUG(
node_->get_logger(), "Waiting for \"%s\" service",
service_name_.c_str());
service_client_->wait_for_service();
if (!service_client_->wait_for_service(1s)) {
RCLCPP_ERROR(
node_->get_logger(), "\"%s\" service server not available after waiting for 1 s",
service_node_name.c_str());
throw std::runtime_error(
std::string(
"Service server %s not available",
service_node_name.c_str()));
}

RCLCPP_DEBUG(
node_->get_logger(), "\"%s\" BtServiceNode initialized",
Expand Down