sml icon indicating copy to clipboard operation
sml copied to clipboard

triggering process_event as an action in a transition table

Open Trenton-Ruf opened this issue 2 years ago • 5 comments

I'm testing the example code:

using namespace sml;
return make_transition_table(
 *"s1"_s + event<my_event> / process_event(other_event{}) = "s2"_s,
  "s2"_s + event<other_event> = X
);

I am getting the error: error: 'process_event' was not declared in this scope

It works fine without the process_event:

using namespace sml;
return make_transition_table(
*"s1"_s + event<my_event> = "s2"_s,
"s2"_s + event<other_event> = X
);

Any Ideas?

Compiling with GCC 5.4.2 Building with PlatformIO for a teensy4.1

Trenton-Ruf avatar Sep 18 '21 07:09 Trenton-Ruf

Hi @Trenton-Ruf

I think you meant to use process instead of process_event?

  • https://github.com/boost-ext/sml/blob/master/example/defer_and_process.cpp

krzysztof-jusiak avatar Sep 18 '21 07:09 krzysztof-jusiak

Alright! That works!

using namespace sml;
return make_transition_table(
 *"s1"_s + event<my_event> / process(other_event{}) = "s2"_s,
  "s2"_s + event<other_event> = X
);

Another question, can process be called within an action? I tried this:

// Action
const auto trigger = []{
sml::process(other_event{});
};

using namespace sml;
return make_transition_table(
 *"s1"_s + event<my_event> / trigger,
  "s2"_s + event<other_event> = X
);

It Compiles but does not process other_event.

Trenton-Ruf avatar Sep 18 '21 17:09 Trenton-Ruf

Yeah, it's possible, you have to use process<events...> Something like

        ,  state + event<e1> / [this](sml::back::process<e2, e3> processEvent) -> void {
            processEvent(e2{});
            processEvent(e3{});
          }

That also requires to inject a process_even storage policy

  sml::sm<c, sml::process_queue<std::queue>> sm{};

Full example

  • https://github.com/boost-ext/sml/blob/master/test/ft/actions_process.cpp#L171

krzysztof-jusiak avatar Sep 18 '21 18:09 krzysztof-jusiak

Sick, Thanks a ton!

Trenton-Ruf avatar Sep 19 '21 17:09 Trenton-Ruf

How can we pass a processEvent to lambda and have it be executed outside the process loop (e.g. a timer event)?

I know it's possible to do that using the full action signature [&](auto&& /*event*/, auto&& sm, auto&& deps, auto&& subs) { but that requires me to capture 4 references, which leads to dynamic memory allocation (not possible in my embedded project).

thanks.

tralamazza avatar Sep 20 '21 12:09 tralamazza