17 #include "nav2_behavior_tree/plugins/action/log_action.hpp"
18 #include "nav2_ros_common/lifecycle_node.hpp"
20 namespace nav2_behavior_tree
25 const auto level = getInput<std::string>(
"level");
26 const auto message = getInput<std::string>(
"message");
27 const auto node = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
28 const auto logger = node->get_logger();
30 if (!level || !message) {
31 RCLCPP_ERROR(logger,
"Log action requires level and message inputs");
32 return BT::NodeStatus::FAILURE;
35 if (level.value() ==
"DEBUG") {
36 RCLCPP_DEBUG(logger,
"%s", message.value().c_str());
37 }
else if (level.value() ==
"INFO") {
38 RCLCPP_INFO(logger,
"%s", message.value().c_str());
39 }
else if (level.value() ==
"WARN") {
40 RCLCPP_WARN(logger,
"%s", message.value().c_str());
41 }
else if (level.value() ==
"ERROR") {
42 RCLCPP_ERROR(logger,
"%s", message.value().c_str());
43 }
else if (level.value() ==
"FATAL") {
44 RCLCPP_FATAL(logger,
"%s", message.value().c_str());
46 RCLCPP_ERROR(logger,
"Invalid Log action level: %s", level.value().c_str());
47 return BT::NodeStatus::FAILURE;
50 return BT::NodeStatus::SUCCESS;
55 #include "behaviortree_cpp/bt_factory.h"
56 BT_REGISTER_NODES(factory)
A BT::SyncActionNode that logs a message through the BT navigator's ROS logger.
BT::NodeStatus tick() override
Logs the input message at the specified level using the blackboard's node.