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

Behavior Tree Callback Not Running

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

enyuin gravatar image

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

osilva gravatar image

Hi,

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
{

IsRecoveredCondition::IsRecoveredCondition(
  const std::string & condition_name,
  const BT::NodeConfiguration & conf)
: BT::ConditionNode(condition_name, conf),
bypass_topic_("/is_recovered_bypass")
{
   getInput("bypass_topic", bypass_topic_);
   node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
   recovered_sub_ = node_->create_subscription<std_msgs::msg::Bool>(
      bypass_topic_,
      rclcpp::SystemDefaultsQoS(),
      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"
BT_REGISTER_NODES(factory)
{
      factory.registerNodeType<nav2_behavior_tree::IsRecoveredCondition>("InitialPoseReceived");
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Comments

1

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 -0600 )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 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 354 times

Last updated: Jan 13 '22