sml icon indicating copy to clipboard operation
sml copied to clipboard

auto transition with guard

Open marcpawl opened this issue 4 years ago • 2 comments

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]                                 |
 |                                                                              |
 |                                                                              |
 +------------------------------------------------------------------------------+
      

marcpawl avatar Mar 19 '20 20:03 marcpawl

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

marcpawl avatar Mar 20 '20 14:03 marcpawl

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

GuiCodron avatar Jul 29 '20 15:07 GuiCodron