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

Add flag to not send request in BTServiceNode #3431

Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ class BtActionNode : public BT::ActionNodeBase
// user defined callback, may modify "should_send_goal_".
on_tick();

if (should_send_goal_) {
send_new_goal();
if(!should_send_goal_){
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
return BT::NodeStatus::FAILURE;
}

send_new_goal();
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BtServiceNode : public BT::ActionNodeBase
const BT::NodeConfiguration & conf,
const std::string & service_name = "")
: BT::ActionNodeBase(service_node_name, conf), service_name_(service_name), service_node_name_(
service_node_name)
service_node_name), should_send_request_(true)
tonynajjar marked this conversation as resolved.
Show resolved Hide resolved
{
node_ = config().blackboard->template get<rclcpp::Node::SharedPtr>("node");
callback_group_ = node_->create_callback_group(
Expand Down Expand Up @@ -131,10 +131,20 @@ class BtServiceNode : public BT::ActionNodeBase
BT::NodeStatus tick() override
{
if (!request_sent_) {
// reset the flag to send the request or not, allowing the user the option to set it in on_tick
should_send_request_ = true;

// user defined callback, may modify "should_send_request_".
on_tick();

if(!should_send_request_){
tonynajjar marked this conversation as resolved.
Show resolved Hide resolved
return BT::NodeStatus::FAILURE;
}

future_result_ = service_client_->async_send_request(request_).share();
sent_time_ = node_->now();
request_sent_ = true;

SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
}
return check_future();
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -243,6 +253,9 @@ class BtServiceNode : public BT::ActionNodeBase
std::shared_future<typename ServiceT::Response::SharedPtr> future_result_;
bool request_sent_{false};
rclcpp::Time sent_time_;

// Can be set in on_tick or on_wait_for_result to indicate if a request should be sent.
bool should_send_request_;
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace nav2_behavior_tree
Expand Down