ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Behavior Tree Callback Not Running

asked 2022-01-12 09:57:19 -0500

enyuin gravatar image

updated 2022-01-13 06:59:57 -0500

osilva gravatar image


Currently, I am modifying one of the condition behavior tree inside nav2 which is the initial_pose_received condition. The code is running fine before I send any callback to update the blackboard inside the behaviour tree. Every tick is running good.

But, for the first time, I sent the cmd of "ros2 topic pub -1 /is_recovered_bypass xxxx", the callback inside the behavior tree will be triggered, and gave me the correct result. Yet, when I sent the same cmd afterwards, none of the cmd can reach the callback sequence. Yet, the tick info logs are still showing, but with old data.

Anyone has any idea on this?

#include <string>

#include "amr_behaviour_tree_plugins/condition/is_recovered_condition.hpp"

namespace nav2_behavior_tree

  const std::string & condition_name,
  const BT::NodeConfiguration & conf)
: BT::ConditionNode(condition_name, conf),
   getInput("bypass_topic", bypass_topic_);
   node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
   recovered_sub_ = node_->create_subscription<std_msgs::msg::Bool>(
      std::bind(&IsRecoveredCondition::isRecoveredCallback, this, std::placeholders::_1));

BT::NodeStatus IsRecoveredCondition::tick()
   auto initPoseReceived = config().blackboard->get<bool>("initial_pose_received");
   RCLCPP_INFO(node_->get_logger(), "Received pose; %s", initPoseReceived? "true": "false");
   if (initPoseReceived) {
       return BT::NodeStatus::SUCCESS;
   return BT::NodeStatus::FAILURE;

void IsRecoveredCondition::isRecoveredCallback(std_msgs::msg::Bool::SharedPtr msg)
     RCLCPP_INFO(node_->get_logger(), "Recover Callback: '%s'", msg->data? "true": "false");
     config().blackboard->template set<bool>("initial_pose_received", true);

}  // namespace nav2_behavior_tree

#include "behaviortree_cpp_v3/bt_factory.h"
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-01-13 16:10:06 -0500

Is that part of the BT being reticked after you return the tick condition of success? Also, you're not spinning the node to process the callbacks.

edit flag offensive delete link more



Hi steve, thanks for your comment. After I added the callback, it works as expected now. Thanks a lot.

enyuin gravatar image enyuin  ( 2022-01-14 07:05:12 -0500 )edit

Can you elaborate on your "added the callback" comment? It seems your example code posted has the callback. I found this post have having a similar issue where the callback is not getting called, and curious of your particular resolution.

dcconner gravatar image dcconner  ( 2022-05-18 21:02:11 -0500 )edit

Question Tools



Asked: 2022-01-12 09:57:19 -0500

Seen: 194 times

Last updated: Jan 13 '22