.. _program_listing_file__tmp_ws_src_SMACC2_smacc2_sm_reference_library_sm_pubsub_1_include_sm_pubsub_1_states_st_state_2.hpp: Program Listing for File st_state_2.hpp ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/SMACC2/smacc2_sm_reference_library/sm_pubsub_1/include/sm_pubsub_1/states/st_state_2.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2021 RobosoftAI Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace sm_pubsub_1 { using namespace std::chrono_literals; // STATE DECLARATION struct StState2 : smacc2::SmaccState, smacc2::ISmaccUpdatable { using SmaccState::SmaccState; // DECLARE CUSTOM OBJECT TAGS struct TIMEOUT : ABORT{}; struct NEXT : SUCCESS{}; struct PREVIOUS : ABORT{}; // TRANSITION TABLE typedef mpl::list< // Transition, StState3, TIMEOUT>, // Transition, StState3>, // Keyboard events Transition, StState1, PREVIOUS>, Transition, StState3, NEXT>, Transition, StState3, NEXT>, Transition, StState3, NEXT> >reactions; static int k; // STATE FUNCTIONS static void staticConfigure() { // configure_orthogonal(10); // configure_orthogonal(); configure_orthogonal(); // configure_orthogonal(); configure_orthogonal(); // Create State Reactor // auto sbAll = static_createStateReactor(); // sbAll->addInputEvent>(); // sbAll->addInputEvent>(); // sbAll->addInputEvent>(); // sbAll->setOutputEvent>(); static_createEventGenerator(ConditionalGeneratorMode::ON_UPDATE); } void runtimeConfigure() { k = 0; auto eg = this->getEventGenerator(); eg->setPredicateFunction([=] { return this->eventGeneratorPredicate(this); }); } bool eventGeneratorPredicate(ISmaccState * st) { auto res = k > 300; RCLCPP_INFO(st->getLogger(), "[State2] checking k: %d > 300 == %d", k, res); rclcpp::sleep_for(10ms); // rclcpp::Duration(10ms).sleep(); return res; } void update() override { k++; RCLCPP_INFO(getLogger(), "[State2] internally updating k: %d", k); } void onEntry() { RCLCPP_INFO(getLogger(), "On Entry!"); } void onExit() { RCLCPP_INFO(getLogger(), "On Exit!"); } }; int StState2::k = 0; } // namespace sm_pubsub_1