C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin_node.hpp
Go to the documentation of this file.
1// Copyright (C) 2024 Miguel Ángel González Santamarta
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16#ifndef YASMIN_ROS__YASMIN_NODE_HPP_
17#define YASMIN_ROS__YASMIN_NODE_HPP_
18
19#include <memory>
20#include <string>
21#include <thread>
22
23#include <rclcpp/rclcpp.hpp>
24
25#include "yasmin/blackboard.hpp"
26#include "yasmin/state.hpp"
28
29namespace yasmin_ros {
30
38class YasminNode : public rclcpp::Node {
39public:
40 using SharedPtr = std::shared_ptr<YasminNode>;
41
42protected:
46 explicit YasminNode();
47
48public:
55 YasminNode(YasminNode &other) = delete;
56
61
67 void operator=(const YasminNode &) = delete;
68
77
81 static void destroy_instance();
82
83private:
87 void stop_executor();
88
90#if __has_include("rclcpp/version.h")
91#include "rclcpp/version.h"
92#if RCLCPP_VERSION_GTE(29, 1, 1) // Jazzy, Kilted and Rolling
93 rclcpp::experimental::executors::EventsExecutor executor;
94#else // Humble, Iron and Jazzy
95 rclcpp::executors::MultiThreadedExecutor executor;
96#endif
97#else // Foxy and Galactic
98 rclcpp::executors::MultiThreadedExecutor executor;
99#endif
101 std::unique_ptr<std::thread> spin_thread;
102};
103
104} // namespace yasmin_ros
105
106#endif // YASMIN_ROS__YASMIN_NODE_HPP_
~YasminNode()
Destructor. Cleans up resources.
Definition yasmin_node.cpp:92
YasminNode()
Default constructor. Initializes the node with a unique name.
Definition yasmin_node.cpp:82
std::unique_ptr< std::thread > spin_thread
Thread for spinning the node.
Definition yasmin_node.hpp:101
YasminNode(YasminNode &other)=delete
Deleted copy constructor to prevent copying of the singleton instance.
static void destroy_instance()
Destroy the singleton instance if it exists.
Definition yasmin_node.cpp:73
rclcpp::executors::MultiThreadedExecutor executor
Executor for managing multiple threads.
Definition yasmin_node.hpp:98
static YasminNode::SharedPtr get_instance()
Provides access to the singleton instance of YasminNode.
Definition yasmin_node.cpp:58
void stop_executor()
Stop the executor thread and remove the node from the executor.
Definition yasmin_node.cpp:99
void operator=(const YasminNode &)=delete
Deleted assignment operator to enforce singleton pattern.
std::shared_ptr< YasminNode > SharedPtr
Definition yasmin_node.hpp:40
Definition action_state.hpp:37