SMACC2
Loading...
Searching...
No Matches
smacc_state_machine_base.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
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/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20#pragma once
21#include <smacc2/common.hpp>
22
25
26namespace smacc2
27{
29template <typename DerivedStateMachine, typename InitialStateType>
31: public ISmaccStateMachine,
33 DerivedStateMachine, InitialStateType, SmaccFifoScheduler, SmaccAllocator>
34{
35public:
37 my_context ctx, SignalDetector * signalDetector,
38 rclcpp::NodeOptions node_options = rclcpp::NodeOptions())
40 smacc2::utils::cleanShortTypeName<DerivedStateMachine>(), signalDetector, node_options),
41 sc::asynchronous_state_machine<
43 {
44 }
45
47 {
48 //updateCurrentState<InitialStateType>(false);
49 }
50
51 void reset() override
52 {
54 this->terminate();
56 }
57
58 void stop() override
59 {
61 this->terminate();
62 }
63
64 void eStop() override
65 {
67 this->terminate();
68 }
69
70 void initiate_impl() override
71 {
72 globalNh_ = this->getNode();
73
74 // this is before because this creates orthogonals
75 this->onInitialize();
76
77 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] Introspecting state machine via typeWalker");
79
80 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] initiate_impl");
82
84
85 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] Initializing ROS communication mechanisms");
86 this->onInitialized();
87
88 // publish startup state machine transition info
89 auto transitionInfo = std::make_shared<SmaccTransitionInfo>();
90 transitionInfo->destinyState = this->stateMachineInfo_->getState<InitialStateType>();
92
93 RCLCPP_INFO(getLogger(), "[SmaccStateMachine] Initializing state machine");
94 sc::state_machine<DerivedStateMachine, InitialStateType, SmaccAllocator>::initiate();
95 }
96};
97} // namespace smacc2
void publishTransition(const SmaccTransitionInfo &transitionInfo)
rclcpp::Node::SharedPtr getNode()
virtual void onInitialize()
this function should be implemented by the user to create the orthogonals
void initializeROS(std::string smshortname)
std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo_
boost::statechart::processor_container< boost::statechart::fifo_scheduler<>, boost::function0< void >, std::allocator< boost::statechart::none > >::processor_context my_context
Definition common.hpp:49
rclcpp::Node::SharedPtr globalNh_
std::allocator< boost::statechart::none > SmaccAllocator
std::string cleanShortTypeName()
Definition common.hpp:62
boost::statechart::fifo_scheduler< SmaccFifoWorker, SmaccAllocator > SmaccFifoScheduler
SmaccStateMachineBase(my_context ctx, SignalDetector *signalDetector, rclcpp::NodeOptions node_options=rclcpp::NodeOptions())