AutoAPMS
Resilient Robot Mission Management
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
ros_node_context.hpp
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <chrono>
18#include <string>
19
20#include "auto_apms_behavior_tree_core/node/node_registration_options.hpp"
21#include "behaviortree_cpp/tree_node.h"
22#include "rclcpp/rclcpp.hpp"
23
25{
26
31{
32 template <typename>
33 friend class RosActionNode;
34 template <typename>
35 friend class RosServiceNode;
36 template <typename>
37 friend class RosSubscriberNode;
38 template <typename>
39 friend class RosPublisherNode;
40
41public:
51 rclcpp::Node::SharedPtr ros_node, rclcpp::CallbackGroup::SharedPtr tree_node_waitables_callback_group,
52 rclcpp::executors::SingleThreadedExecutor::SharedPtr tree_node_waitables_executor,
53 const NodeRegistrationOptions & options);
54
59 std::string getROSNodeName() const;
60
65 std::string getFullyQualifiedRosNodeName() const;
66
71 rclcpp::Logger getBaseLogger() const;
72
78 rclcpp::Logger getChildLogger(const std::string & name);
79
84 rclcpp::Time getCurrentTime() const;
85
92 std::string getFullyQualifiedTreeNodeName(const BT::TreeNode * node, bool with_class_name = true) const;
93
94private:
95 BT::Expected<std::string> getCommunicationPortName(const BT::TreeNode * node) const;
96
97 const std::string ros_node_name_;
98 const std::string fully_qualified_ros_node_name_;
99 rclcpp::Logger base_logger_;
100
102 rclcpp::Node::WeakPtr nh_;
104 rclcpp::CallbackGroup::WeakPtr cb_group_;
106 rclcpp::executors::SingleThreadedExecutor::WeakPtr executor_;
108 const NodeRegistrationOptions registration_options_;
109};
110
111} // namespace auto_apms_behavior_tree::core
std::string getROSNodeName() const
Get the name of the ROS 2 node passed to the constructor.
rclcpp::Logger getChildLogger(const std::string &name)
Get a child logger created using the associated ROS 2 node.
rclcpp::Time getCurrentTime() const
Get the current time using the associated ROS 2 node.
RosNodeContext(rclcpp::Node::SharedPtr ros_node, rclcpp::CallbackGroup::SharedPtr tree_node_waitables_callback_group, rclcpp::executors::SingleThreadedExecutor::SharedPtr tree_node_waitables_executor, const NodeRegistrationOptions &options)
Constructor.
std::string getFullyQualifiedTreeNodeName(const BT::TreeNode *node, bool with_class_name=true) const
Create a string representing the detailed name of a behavior tree node.
std::string getFullyQualifiedRosNodeName() const
Get the fully qualified name of the ROS 2 node passed to the constructor.
rclcpp::Logger getBaseLogger() const
Get the logger of the associated ROS 2 node.
Core API for AutoAPMS's behavior tree implementation.
Definition builder.hpp:30
Parameters for loading and registering a behavior tree node class from a shared library using e....