Skip to content

Commit

Permalink
Merge pull request #13 from logivations/add-flag-to-not-send-goal-in-…
Browse files Browse the repository at this point in the history
…BTactionnode

Add-flag-to-not-send-goal-in-BTactionnode
  • Loading branch information
Tony Najjar authored Feb 28, 2023
2 parents 22a3498 + 4386cba commit f8fdce3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions nav2_behavior_tree/include/nav2_behavior_tree/bt_action_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BtActionNode : public BT::ActionNodeBase
const std::string & xml_tag_name,
const std::string & action_name,
const BT::NodeConfiguration & conf)
: BT::ActionNodeBase(xml_tag_name, conf), action_name_(action_name)
: BT::ActionNodeBase(xml_tag_name, conf), action_name_(action_name), should_send_goal_(true)
{
node_ = config().blackboard->template get<rclcpp::Node::SharedPtr>("node");
callback_group_ = node_->create_callback_group(
Expand Down Expand Up @@ -188,10 +188,15 @@ class BtActionNode : public BT::ActionNodeBase
// setting the status to RUNNING to notify the BT Loggers (if any)
setStatus(BT::NodeStatus::RUNNING);

// user defined callback
// reset the flag to send the goal or not, allowing the user the option to set it in on_tick
should_send_goal_ = true;

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

send_new_goal();
if (should_send_goal_) {
send_new_goal();
}
}

try {
Expand Down Expand Up @@ -223,7 +228,8 @@ class BtActionNode : public BT::ActionNodeBase
feedback_.reset();

auto goal_status = goal_handle_->get_status();
if (goal_updated_ && (goal_status == action_msgs::msg::GoalStatus::STATUS_EXECUTING ||
if (goal_updated_ &&
(goal_status == action_msgs::msg::GoalStatus::STATUS_EXECUTING ||
goal_status == action_msgs::msg::GoalStatus::STATUS_ACCEPTED))
{
goal_updated_ = false;
Expand Down Expand Up @@ -444,6 +450,9 @@ class BtActionNode : public BT::ActionNodeBase
std::shared_ptr<std::shared_future<typename rclcpp_action::ClientGoalHandle<ActionT>::SharedPtr>>
future_goal_handle_;
rclcpp::Time time_goal_sent_;

// Can be set in on_tick or on_wait_for_result to indicate if a goal should be sent.
bool should_send_goal_;
};

} // namespace nav2_behavior_tree
Expand Down

0 comments on commit f8fdce3

Please sign in to comment.