28#include <smacc2_msgs/msg/smacc_status.hpp>
29#include <smacc2_msgs/msg/smacc_transition_log_entry.hpp>
33using namespace std::chrono_literals;
37: currentState_(nullptr), stateSeqCounter_(0)
39 rclcpp::NodeOptions node_options;
46 nh_ = rclcpp::Node::make_shared(stateMachineName, node_options);
48 nh_->get_logger(),
"Creating State Machine Base: " <<
nh_->get_fully_qualified_name());
54 if (
nh_->get_parameter(
"run_mode", runMode))
56 if (runMode ==
"debug")
60 else if (runMode ==
"release")
66 RCLCPP_ERROR(
nh_->get_logger(),
"Incorrect run_mode value: %s", runMode.c_str());
77 RCLCPP_INFO(
nh_->get_logger(),
"Finishing State Machine");
88const std::map<std::string, std::shared_ptr<smacc2::ISmaccOrthogonal>> &
96 std::lock_guard<std::recursive_mutex> lock(
m_mutex_);
101 nh_->get_logger(),
"[StateMachine] setting state active "
107 std::list<const SmaccStateInfo *> ancestorList;
110 for (
auto & ancestor : ancestorList)
112 status_msg_.current_states.push_back(ancestor->toShortName());
120 status_msg_.global_variable_names.push_back(entry.first);
122 entry.second.first());
133 smacc2_msgs::msg::SmaccTransitionLogEntry transitionLogEntry;
134 transitionLogEntry.timestamp = this->
nh_->now();
145 auto ros_clock = rclcpp::Clock::make_shared();
152 RCLCPP_WARN_STREAM(
nh_->get_logger(),
"State machine base creation:" << shortname);
155 shortname +
"/smacc/state_machine_description", 1);
157 nh_->create_publisher<smacc2_msgs::msg::SmaccStatus>(shortname +
"/smacc/status", 1);
159 shortname +
"/smacc/transition_log", 1);
163 shortname +
"/smacc/transition_log_history",
166 std::placeholders::_2, std::placeholders::_3));
170 const std::shared_ptr<rmw_request_id_t> ,
171 const std::shared_ptr<smacc2_msgs::srv::SmaccGetTransitionHistory::Request> ,
172 std::shared_ptr<smacc2_msgs::srv::SmaccGetTransitionHistory::Response> res)
175 nh_->get_logger(),
"Requesting Transition Log History, current size: %ld",
176 this->transitionLogHistory_.size());
182 std::lock_guard<std::recursive_mutex> lock(
m_mutex_);
184 smacc2_msgs::msg::SmaccStateMachine state_machine_msg;
188 state_machine_msg.states.begin(), state_machine_msg.states.end(),
189 [](
auto & a,
auto & b) { return a.index < b.index; });
219 "[StateMachine] Disconnecting scoped-lifetime SmaccSignal "
224 this->stateCallbackConnections.clear();
std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > orthogonals_
smacc2::SMRunMode runMode_
virtual ~ISmaccStateMachine()
std::string getStateMachineName()
void publishTransition(const SmaccTransitionInfo &transitionInfo)
rclcpp::Publisher< smacc2_msgs::msg::SmaccStateMachine >::SharedPtr stateMachinePub_
std::shared_ptr< SmaccStateInfo > currentStateInfo_
rclcpp::Node::SharedPtr getNode()
std::map< std::string, std::pair< std::function< std::string()>, boost::any > > globalData_
rclcpp::Service< smacc2_msgs::srv::SmaccGetTransitionHistory >::SharedPtr transitionHistoryService_
virtual void onInitialize()
this function should be implemented by the user to create the orthogonals
void disposeStateAndDisconnectSignals()
std::vector< smacc2_msgs::msg::SmaccTransitionLogEntry > transitionLogHistory_
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & getOrthogonals() const
std::recursive_mutex m_mutex_
rclcpp::Publisher< smacc2_msgs::msg::SmaccStatus >::SharedPtr stateMachineStatusPub_
ISmaccStateMachine(std::string stateMachineName, SignalDetector *signalDetector)
ISmaccState * currentState_
rclcpp::Node::SharedPtr nh_
rclcpp::TimerBase::SharedPtr timer_
rclcpp::Publisher< smacc2_msgs::msg::SmaccTransitionLogEntry >::SharedPtr transitionLogPub_
void checkStateMachineConsistence()
SignalDetector * signalDetector_
rclcpp::Logger getLogger()
void initializeROS(std::string smshortname)
smacc2_msgs::msg::SmaccStatus status_msg_
std::list< boost::signals2::connection > stateCallbackConnections
void state_machine_visualization()
std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo_
void updateStatusMessage()
void getTransitionLogHistory(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Request > req, std::shared_ptr< smacc2_msgs::srv::SmaccGetTransitionHistory::Response > res)
void initialize(ISmaccStateMachine *stateMachine)
std::string demangleSymbol(const std::string &name)
void transitionInfoToMsg(const SmaccTransitionInfo &transition, smacc2_msgs::msg::SmaccTransition &transitionMsg)