AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
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// http://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 friend class RosNodeBase;
33 template <class, typename, bool>
34 friend class NodeRegistrationTemplate;
35
36public:
46 rclcpp::Node::SharedPtr ros_node, rclcpp::CallbackGroup::SharedPtr tree_node_waitables_callback_group,
47 rclcpp::executors::SingleThreadedExecutor::SharedPtr tree_node_waitables_executor,
48 const NodeRegistrationOptions & options);
49
54 std::string getROSNodeName() const;
55
60 std::string getFullyQualifiedRosNodeName() const;
61
66 rclcpp::Logger getBaseLogger() const;
67
73 rclcpp::Logger getChildLogger(const std::string & name);
74
79 rclcpp::Time getCurrentTime() const;
80
87 std::string getFullyQualifiedTreeNodeName(const BT::TreeNode * node, bool with_class_name = true) const;
88
93 YAML::Node getExtraOptions() const;
94
104 rclcpp::Node::SharedPtr getRosNode() const;
105
110 rclcpp::CallbackGroup::SharedPtr getWaitablesCallbackGroup() const;
111
116 rclcpp::executors::SingleThreadedExecutor::SharedPtr getWaitablesExecutor() const;
117
128 BT::Expected<std::string> getTopicName(const BT::TreeNode * node) const;
129
135
136private:
147 void copyAliasedPortValuesToOriginalPorts(const BT::TreeNode * node) const;
148
149 void modifyProvidedPortsListForRegistration(BT::PortsList & ports_list) const;
150
151 const std::string ros_node_name_;
152 const std::string fully_qualified_ros_node_name_;
153 rclcpp::Logger base_logger_;
154
156 rclcpp::Node::WeakPtr nh_;
158 rclcpp::CallbackGroup::WeakPtr cb_group_;
160 rclcpp::executors::SingleThreadedExecutor::WeakPtr executor_;
162 const NodeRegistrationOptions registration_options_;
163};
164
165} // 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::CallbackGroup::SharedPtr getWaitablesCallbackGroup() const
Get the callback group to use when adding ROS 2 waitables (subscriptions, clients,...
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.
rclcpp::Node::SharedPtr getRosNode() const
Get the associated ROS 2 node handle.
const NodeRegistrationOptions & getRegistrationOptions() const
Get the node registration options.
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.
BT::Expected< std::string > getTopicName(const BT::TreeNode *node) const
Resolve the ROS 2 topic name from the node's registration options (node manifest 'topic' feature),...
std::string getFullyQualifiedRosNodeName() const
Get the fully qualified name of the ROS 2 node passed to the constructor.
YAML::Node getExtraOptions() const
Get the extra YAML options provided during node registration.
rclcpp::Logger getBaseLogger() const
Get the logger of the associated ROS 2 node.
rclcpp::executors::SingleThreadedExecutor::SharedPtr getWaitablesExecutor() const
Get the executor used for spinning the tree node's waitables.
Core API for AutoAPMS's behavior tree implementation.
Definition behavior.hpp:32
Parameters for loading and registering a behavior tree node class from a shared library using e....