C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin_viewer_pub.hpp
Go to the documentation of this file.
1// Copyright (C) 2023 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_VIEWER__YASMIN_VIEWER_PUB_HPP
17#define YASMIN_VIEWER__YASMIN_VIEWER_PUB_HPP
18
19#include <map>
20#include <memory>
21#include <string>
22#include <vector>
23
24#include "rclcpp/rclcpp.hpp"
25
27#include "yasmin/state.hpp"
29#include "yasmin_msgs/msg/state.hpp"
30#include "yasmin_msgs/msg/state_machine.hpp"
31#include "yasmin_msgs/msg/transition.hpp"
32
33namespace yasmin_viewer {
34
40
41public:
49 YasminViewerPub(const rclcpp::Node::SharedPtr &node,
50 std::shared_ptr<yasmin::StateMachine> fsm,
51 const std::string &fsm_name);
52
59 YasminViewerPub(std::shared_ptr<yasmin::StateMachine> fsm,
60 const std::string &fsm_name);
61
68 YasminViewerPub(const rclcpp::Node::SharedPtr &node,
69 std::shared_ptr<yasmin::StateMachine> fsm);
70
76 YasminViewerPub(std::shared_ptr<yasmin::StateMachine> fsm);
77
85 std::vector<yasmin_msgs::msg::Transition>
86 parse_transitions(const std::map<std::string, std::string> &transitions);
87
94 std::map<std::string, std::vector<yasmin_msgs::msg::Transition>>
96 std::shared_ptr<yasmin::Concurrence> concurrence);
97
107 void parse_state(const std::string &name,
108 std::shared_ptr<yasmin::State> state,
109 const std::map<std::string, std::string> &transitions,
110 std::vector<yasmin_msgs::msg::State> &states_list,
111 int parent);
112
118 void publish_data();
119
120private:
122 rclcpp::Node::SharedPtr node_;
124 rclcpp::Publisher<yasmin_msgs::msg::StateMachine>::SharedPtr publisher;
126 rclcpp::TimerBase::SharedPtr timer;
127
129 std::shared_ptr<yasmin::StateMachine> fsm;
131 std::string fsm_name;
132};
133
134} // namespace yasmin_viewer
135
136#endif // YASMIN_VIEWER__YASMIN_VIEWER_PUB_HPP
std::string fsm_name
Name of the finite state machine.
Definition yasmin_viewer_pub.hpp:131
YasminViewerPub(const rclcpp::Node::SharedPtr &node, std::shared_ptr< yasmin::StateMachine > fsm, const std::string &fsm_name)
Constructs YasminViewerPub with a given ROS 2 node, state machine name, and state machine instance.
Definition yasmin_viewer_pub.cpp:35
rclcpp::TimerBase::SharedPtr timer
Timer for periodic publishing.
Definition yasmin_viewer_pub.hpp:126
std::vector< yasmin_msgs::msg::Transition > parse_transitions(const std::map< std::string, std::string > &transitions)
Parses transitions from a map of transitions and returns a list of Transition messages.
Definition yasmin_viewer_pub.cpp:67
std::map< std::string, std::vector< yasmin_msgs::msg::Transition > > parse_concurrence_transitions(std::shared_ptr< yasmin::Concurrence > concurrence)
Parses concurrence transitions from outcome map to transition-like information.
Definition yasmin_viewer_pub.cpp:87
std::shared_ptr< yasmin::StateMachine > fsm
Shared pointer to the state machine.
Definition yasmin_viewer_pub.hpp:129
void publish_data()
Publishes the data of the finite state machine to the associated ROS topic.
Definition yasmin_viewer_pub.cpp:205
rclcpp::Node::SharedPtr node_
Shared pointer to the ROS 2 node.
Definition yasmin_viewer_pub.hpp:122
rclcpp::Publisher< yasmin_msgs::msg::StateMachine >::SharedPtr publisher
Publisher for StateMachine messages.
Definition yasmin_viewer_pub.hpp:124
void parse_state(const std::string &name, std::shared_ptr< yasmin::State > state, const std::map< std::string, std::string > &transitions, std::vector< yasmin_msgs::msg::State > &states_list, int parent)
Parses a state and its transitions to add it to the list of state messages.
Definition yasmin_viewer_pub.cpp:118
Definition yasmin_viewer_pub.hpp:33