Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State Machine Options (Library, Framework, Generator, Compiler, etc) #10584

Open
dagar opened this issue Sep 27, 2018 · 13 comments
Open

State Machine Options (Library, Framework, Generator, Compiler, etc) #10584

dagar opened this issue Sep 27, 2018 · 13 comments

Comments

@dagar
Copy link
Member

dagar commented Sep 27, 2018

I've been casually looking for a good solution to handle state machines throughout the system.

Requirements

  • declarative
  • generate documentation (either tables or a graph)
    • SCXML would also be nice
  • if a generator or compiler it needs to be easily accessible, cross platform, and have an acceptable license
  • likely need to support HSM (TBD)
  • entry and exit Actions
  • transition guards
  • error handling/reporting (think about feedback from denied arming or mode change)

Options

@dagar
Copy link
Member Author

dagar commented Oct 29, 2018

FYI @simonegu @julianoes

@tstellanova
Copy link
Contributor

FWIW, Yakindu statechart tools can be run headless (without running Eclipse UI), and moving charts between Qt and Yakindu somewhat works.
https://github.com/Yakindu/statecharts

@dagar dagar mentioned this issue Feb 13, 2019
13 tasks
@dakejahl
Copy link
Contributor

dakejahl commented Mar 4, 2019

@dagar I made a dumb little example in PX4 that uses this library https://github.com/amaiorano/hsm
See https://github.com/PX4/Firmware/tree/hsm_example

It's essentially the state_args.cpp with a few modifications. I wouldn't even know where to begin with trying to implement this in something like Commander... Hopefully this is somewhat helpful.

make px4_sitl_default jmavsim
pxh > hsm_example

Right now the plotHsm.py doesn't work, but I was able to manually generate the chart:

python $PX4_DIR/src/lib/hsm/tools/hsmToDot.py $PX4_DIR/src/modules/hsm_example/hsm_example.h > hsm_example.dot
dot hsm_example.dot -Tpng -o hsm_example.png

hsm_example
Output

pxh> hsm_example
HSM_1_TestHsm: Init    : Alive
HSM_1_TestHsm:  Entry   : Locomotion
HSM_1_TestHsm:   Entry   : Stand
HSM_2_TestHsm:   Pop     : Stand
HSM_1_TestHsm:   Sibling : Move
HSM_2_TestHsm:   Pop     : Move
HSM_2_TestHsm:  Pop     : Locomotion
HSM_1_TestHsm:  Sibling : Attack
>>> Attacking: 0
>>> Attacking: 0
>>> Attacking: 0
HSM_2_TestHsm:  Pop     : Attack
HSM_1_TestHsm:  Sibling : Attack
>>> Attacking: 1
>>> Attacking: 1
>>> Attacking: 1
HSM_2_TestHsm:  Pop     : Attack
HSM_1_TestHsm:  Sibling : Attack
>>> Attacking: 2
>>> Attacking: 2
>>> Attacking: 2
>>> Attacking: 2

I have the debug level set to diagnostic, so you can see all state transitions and their relationships.

@dagar
Copy link
Member Author

dagar commented Jun 25, 2019

Julian's state machine in PX4/avoidance. PX4/PX4-Avoidance#418

@julianoes
Copy link
Contributor

Thanks @dakejahl and @jkflying. That's helpful, however, I still believe the hard part is capturing the intended behaviour and put it into a diagram than to actually implement the state machine. I have implemented a state machine like this in the past as well but was struggling with formulating the actual behaviour without having to do it using hierarchical state machines.

@jkflying
Copy link
Contributor

jkflying commented Jul 1, 2019

Maybe a first step would be drawing a high level state transition diagram and refactoring into that, even if inside the different states there is still a lot of ad-hoc implicit state code?

@AuterionWrikeBot
Copy link

➤ David Sidrane commented:

Have a look at https://www.visual-paradigm.com/
It is a great tool and there is a comunity edition

@dagar
Copy link
Member Author

dagar commented Jul 1, 2019

I have implemented a state machine like this in the past as well but was struggling with formulating the actual behaviour without having to do it using hierarchical state machines.

Why without hierarchical state machines?

@julianoes
Copy link
Contributor

Right so for hierarchical state machines you either need to extend the implementations or combine them manually.

@dagar
Copy link
Member Author

dagar commented Jul 2, 2019

Added https://github.com/andrew-gresyk/HFSM2 to the list to investigate.

@wluker
Copy link

wluker commented Jul 18, 2019

You might consider a language @fsantanna created called ceu. http://ceu-lang.org/index.html

It generates C code that you would have to integrate into an event loop.

It's not a state machine generator, but I find the semantics easier on my brain than state machines, even hierarchical.

@stale stale bot added stale and removed stale labels Oct 16, 2019
@PX4 PX4 deleted a comment from stale bot Mar 31, 2020
@dagar dagar pinned this issue Jul 13, 2020
@BazookaJoe1900 BazookaJoe1900 unpinned this issue Jul 14, 2020
@dinomani
Copy link
Contributor

dinomani commented Jan 6, 2021

@dagar
Anybotic uses something like that to switch the robot to and from different modes with safety fallback.
https://docs.leggedrobotics.com/rocoma_doc/page_features.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests