19 #include "nav2_behavior_tree/plugins/condition/transform_available_condition.hpp"
21 using namespace std::chrono_literals;
23 namespace nav2_behavior_tree
26 TransformAvailableCondition::TransformAvailableCondition(
27 const std::string & condition_name,
28 const BT::NodeConfiguration & conf)
29 : BT::ConditionNode(condition_name, conf),
32 node_ = config().blackboard->get<rclcpp::Node::SharedPtr>(
"node");
33 tf_ = config().blackboard->get<std::shared_ptr<tf2_ros::Buffer>>(
"tf_buffer");
38 RCLCPP_DEBUG(node_->get_logger(),
"Shutting down TransformAvailableCondition BT node");
43 getInput(
"child", child_frame_);
44 getInput(
"parent", parent_frame_);
46 if (child_frame_.empty() || parent_frame_.empty()) {
48 node_->get_logger(),
"Child frame (%s) or parent frame (%s) were empty.",
49 child_frame_.c_str(), parent_frame_.c_str());
50 throw std::runtime_error(
"TransformAvailableCondition: Child or parent frames not provided!");
53 RCLCPP_DEBUG(node_->get_logger(),
"Initialized an TransformAvailableCondition BT node");
58 if (!BT::isStatusActive(status())) {
63 return BT::NodeStatus::SUCCESS;
67 bool found = tf_->canTransform(
68 child_frame_, parent_frame_, tf2::TimePointZero, &tf_error);
72 return BT::NodeStatus::SUCCESS;
76 node_->get_logger(),
"Transform from %s to %s was not found, tf error: %s",
77 child_frame_.c_str(), parent_frame_.c_str(), tf_error.c_str());
79 return BT::NodeStatus::FAILURE;
84 #include "behaviortree_cpp/bt_factory.h"
85 BT_REGISTER_NODES(factory)