19 #include "rclcpp/rclcpp.hpp"
20 #include "tf2/time.hpp"
21 #include "tf2_ros/buffer.hpp"
23 #include "nav2_behavior_tree/plugins/condition/transform_available_condition.hpp"
25 using namespace std::chrono_literals;
27 namespace nav2_behavior_tree
30 TransformAvailableCondition::TransformAvailableCondition(
31 const std::string & condition_name,
32 const BT::NodeConfiguration & conf)
33 : BT::ConditionNode(condition_name, conf),
36 node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
37 tf_ = config().blackboard->get<std::shared_ptr<tf2_ros::Buffer>>(
"tf_buffer");
42 RCLCPP_DEBUG(node_->get_logger(),
"Shutting down TransformAvailableCondition BT node");
47 getInput(
"child", child_frame_);
48 getInput(
"parent", parent_frame_);
50 if (child_frame_.empty() || parent_frame_.empty()) {
52 node_->get_logger(),
"Child frame (%s) or parent frame (%s) were empty.",
53 child_frame_.c_str(), parent_frame_.c_str());
54 throw std::runtime_error(
"TransformAvailableCondition: Child or parent frames not provided!");
57 RCLCPP_DEBUG(node_->get_logger(),
"Initialized an TransformAvailableCondition BT node");
62 if (!BT::isStatusActive(status())) {
67 return BT::NodeStatus::SUCCESS;
71 bool found = tf_->canTransform(
72 child_frame_, parent_frame_, tf2::TimePointZero, &tf_error);
76 return BT::NodeStatus::SUCCESS;
80 node_->get_logger(),
"Transform from %s to %s was not found, tf error: %s",
81 child_frame_.c_str(), parent_frame_.c_str(), tf_error.c_str());
83 return BT::NodeStatus::FAILURE;
88 #include "behaviortree_cpp/bt_factory.h"
89 BT_REGISTER_NODES(factory)