Coder Social home page Coder Social logo

igor-krechetov / hsmcpp Goto Github PK

View Code? Open in Web Editor NEW
58.0 5.0 7.0 7.15 MB

C++ based Hierarchical / Finite State Machine library oriented for embedded and RTOS systems.

Home Page: https://hsmcpp.readthedocs.io

License: MIT License

CMake 8.27% C++ 72.26% Shell 0.45% Python 11.31% Batchfile 0.07% C 7.63%
finite-state-machine hierarchical-state-machine fsm hsm fsm-library state-machine embedded-systems rtos uml-state-machine embedded

hsmcpp's People

Contributors

igor-krechetov avatar yoowonsuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hsmcpp's Issues

Unable to build FreeRTOS posix example

Hi @igor-krechetov,

I am trying to build hsmcpp library for Renesas Cortex M33 MCU. As a start I tried building the freertos posix port example/08_freertos. The build fails at linking stage. Its failing to link following libraries.

  • freertos_kernel
  • freertos_kernel_port

Where can i find these libraries? They are not available in the FreeRTOS souce directory as well. I have attached the build log. Please have a look.
build-log.txt

Regards,
Harsha

freertos/Mutex.hpp: No such file or directory

Hello, I'm trying to use this library in platformio with my ESP32 WROOM.

I tried to create a minimum repro. Here is my platform.ini:

[env:sparkfun_thing_bluetooth]
platform = espressif32
board = sparkfun_esp32s2_thing_plus_c
framework = arduino
lib_deps = 
	igor-krechetov/hsmcpp@^1.0.1

custom_hsm_files=./blink.scxml:BlinkHsm:Base
custom_hsm_gendir=./src

Other than the platform and board, I believe this is identical to the example.

It generated the BlinkHsmBase cpp and header files (very cool!) but fails to compile:

Compiling .pio\build\sparkfun_thing_bluetooth\liba67\hsmcpp\HsmEventDispatcherArduino.cpp.o
Compiling .pio\build\sparkfun_thing_bluetooth\liba67\hsmcpp\HsmEventDispatcherBase.cpp.o
In file included from .pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp/HsmEventDispatcherBase.hpp:13,
                 from .pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp/HsmEventDispatcherArduino.hpp:10,
                 from .pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp.hpp:8,
                 from src/main.cpp:5:
.pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp/os/Mutex.hpp:9:11: fatal error: freertos/Mutex.hpp: No such file or directory
  #include "freertos/Mutex.hpp"
           ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\sparkfun_thing_bluetooth\src\main.cpp.o] Error 1

#if defined(FREERTOS_AVAILABLE)

I tried digging into this error and found that INC_FREERTOS_H is being defined here:
~.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\include\freertos\include\freertos\FreeRTOS.h:

Apparentl this board is using freeRTOS under the hood. But like the error message suggests, I'm not able to find any associated file freertos/Mutex.hpp.

Any ideas what I should try? Thanks!

History transition removes leaf states on parallel state machines

So far this library has been awesome, I'd really like to get this one feature working but for some reason transitioning back to a history state is mangling some of my parallel state machines.

I have four parallel state machines running under the "Main" state machine:
image

My button state machine is pretty straightforward and looks something like this:
image

When the button is released, it will transition my "Workout" state machine from "Workout__Active__Running" to "Workout__Active__Paused" and vice versa. "Workout__Active__Running" has some nested states that I'd like to restore when coming back from "Workout__Active__Paused":

image

Here's my workoutActive.scxml with the irrelevant bits removed (note that I'm using the xi:include feature so these states all get preprended with "Workout__Active__" in my generated state machine):

<scxml initial="SetUp" version="1.0" xmlns="http://www.w3.org/2005/07/scxml"    >    
    <state id="Running" initial="Running_Squeezing">        
        <transition event="HW_BUTTON_RELEASED" target="Paused" type="external" />
        <state id="Running_Squeezing" >
            ...
        </state>
        <state id="Running_Resting" >
            ...
        </state>    
        <history type="deep" id="RunningHistory" />    
    </state>
    <state id="Paused">
        <transition event="HW_BUTTON_RELEASED" target="RunningHistory" type="external" />
        <invoke srcexpr="on0301_Paused" />
    </state>
</scxml>

Something gets screwed up when trying to transition to "RunningHistory" from the "Paused" state. I've printed out the active states during the transition:

1) Main, Button, Workout, Led, Haptics, Haptics__Off, Workout__Active, Workout__Active__Paused, Led__Blinking, Led__Blinking_Off, Button__Pressed

---  TRANSITION TO HISTORY (event: HW_BUTTON_RELEASED, state: Workout__Active__RunningHistory, previously active: Workout__Active__Running_Squeezing) ---

2) Main, Button, Workout, Led, Haptics, Workout__Active, Led__Blinking, Workout__Active__Running, 
3) Main, Workout, Led, Workout__Active, Workout__Active__Running, Workout__Active__Running_Squeezing,
  1. Is right before the transition back to the history, and all seems good.
  2. It re-enters the "Workout__Active__Running" state, but for some reason "Haptics__Off", "Led__Blinking_Off", and "Button_Released" (the new button state) get removed.
  3. It re-enters the "Workout__Active__Running_Squeezing" but now the "Button", "Haptics" and "Led_Blinking" states are gone

So it seems like it is popping off the leaf states on the parallel state machines for each history state it restores.

My expected final state:

Main, Button, Workout, Led, Haptics, Haptics__Off, Led__Blinking, Led__Blinking_Off, Button__Pressed, Workout__Active, Workout__Active__Running, Workout__Active__Running_Squeezing, 

Hopefully this makes sense. Let me know if it doesn't and I'll try to provide more information.

HSM_LOGGING_MODE_STRICT_VERBOSE on arduino

I tried turning debug logging on with HSM_LOGGING_MODE_STRICT_VERBOSE and it failed to find serialPrintf (using arduino).

Should this line

#if defined(PLATFORM_ARDUINO) && defined(HSM_DISABLE_TRACES)

be this:

#if defined(PLATFORM_ARDUINO) && !defined(HSM_DISABLE_TRACES)

MCU compilation

Hello,

I am trying to implement your HSM inside a STM32G4, ARM MCU.
However i need to write a scheduler as i can't use the std::thread posix stuff on a Cortex-M4 CPU.

FreeRTOS can be used as OS to maintain asynchrony with the lib cpp_freertos wrote by Mickael Becker. This keep things very similar to the std::thread POSIX environnement. The major difference is the way threads are created and launched as cpp_freertos use a java like pattern with subclass and virtual run() method for threads.

I have (not so) sucessfully ported the HsmEventDispatcherBase.hpp/cpp files to HsmEventDispatcherBaseFREERTOS.hpp/cpp, also HsmEventDispatcherSTD.hpp/cpp files to HsmEventDispatcherFREERTOS.hpp/cpp with the cpp_freertos threading API.

I am now stuck with the hsm.hpp file here :

template <typename HsmStateEnum, typename HsmEventEnum>
void HierarchicalStateMachine<HsmStateEnum, HsmEventEnum>::PendingEventInfo::wait(const int timeoutMs)
{
    if (isSync())
    {
        std::unique_lock<std::mutex> lck(*cvLock);

        if (timeoutMs > 0)
        {
            syncProcessed->wait_for(lck, std::chrono::milliseconds(timeoutMs),
                                    [=](){return (HsmEventStatus_t::PENDING != *transitionStatus);});
        }
        else
        {
            syncProcessed->wait(lck, [=](){return (HsmEventStatus_t::PENDING != *transitionStatus);});
        }
    }

With cpp_freertos API that could become (i don't need the timeout) :

template <typename HsmStateEnum, typename HsmEventEnum>
void HierarchicalStateMachine<HsmStateEnum, HsmEventEnum>::PendingEventInfo::wait()
{
    if (isSync())
    {
        cpp_freertos::LockGuard lck(cvLock);
        Wait(syncProcessed, cvLock);
    }
}

You call syncProcessed->wait and that's a std::condition_variable method usable outside a thread (on a bare metal POSIX the main loop is also a thread indeed, not on a MCU).
However, my cpp_freertos::Thread::Wait method need to be called inside the scope of a thread.
So here i'm stuck, i don't know how i can fix it.

Maybe i can subclass HierarchicalStateMachine to run it inside a thread ?

Looking for help on this.

To Ask for Adding a Tag

Hello, Igor Krechetov.

Would you like to add a tag to this project??
I will be glad if you do.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.