sml
sml copied to clipboard
auto transition with guard
I am trying to figure out how to do an automatic transition an entry where there is a condition based on a guard.
Below is a small state machine I am using for testing.
On entry the starting state should transition to either "heater on" or "heater off" depending on a data value.
However, I do not see that be an available option in the grammar: https://boost-experimental.github.io/sml/tutorial.html
+------------------------------------------------------------------------------+
| |
| |
| [t<=100] |
| :-----------------------------------: |
| | | |
| v | |
| [ t < 100 ] +-----------+ power | |
| o------------------>| heater on |-------------->O | |
| | +-----------+ ^ | |
| | ^ | | | |
| | Temp reading | | Temp reading | power o |
| | [t<=90] | | [ t>100 ] | | |
| | | v | | |
| | +------------+ | | |
| |------------------> | heater off | -------------: | |
| +------------+ | |
| ^ | |
| | | |
| :----------------------------------: |
| [t>=100] |
| |
| |
+------------------------------------------------------------------------------+
Documentation should demonstrate how to perform such an item as it is a gotcha. I am working on something that I can push.
https://wandbox.org/permlink/WbvV9HsIyiPkCFw7
Key parts are return make_transition_table( (*start) + on_entry<> / [](Hardware& hardware){ std::cout << "ENTER PowerOnStateMachine::start t=" << hardware.degrees_celcius << "\n";} ,start + sml::on_exit<> / [](Hardware& hardware){ std::cout << "EXIT PowerOnStateMachine::start t=" << hardware.degrees_celcius << "\n";} ,start [guard_hot_enough] =heater_off ,start [! guard_hot_enough] =heater_on
and
,power_on [ guard_is_cool] = idle_state
,power_on [ ! guard_is_cool] = cooling
I use the syntax
,power_on [ guard_is_cool] = idle_state
,power_on [ ! guard_is_cool] = cooling
and it operates as expected.
However, for automatic transition with guard, there is currently a bug that will cause your guard to be checked an exponential number of times based on sm depth. It should be fixed by https://github.com/boost-ext/sml/pull/331