GithubHelp home page GithubHelp logo

cotestatnt / ya_fsm Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 7.0 190 KB

Simple state machine. Implements a "Petri net" (GRAFCET/SFC) inspired state machine with states, transitions and actions

License: Apache License 2.0

C++ 100.00%
arduino state-machine arduino-library finite-state-machine fsm

ya_fsm's People

Contributors

cotestatnt avatar tcwilliamson avatar tutagomes 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

Watchers

 avatar  avatar  avatar

ya_fsm's Issues

Can we simplify time-based transitions?

Hi: I love your library and have a project that needs to instantiate multiple, independent state machines. For code cleanliness and to avoid global variables, I tried to subclass YA_FSM to encapsulate the shared settings, a la

class PulsarStateMachine : public YA_FSM {public: int pulsarTimeout = 100; ...}

and then I have a PulsarStateMachine::Setup() function that defines the states, actions, and transitions.

However, I'm getting stuck following your timed transition pattern from within that Setup() function, because the lambda doesn't know how to find the CurrentState()->timeout. Your recommended pattern is:

this->AddTransition(ON_STATE, OFF_STATE, [](){return stateMachine.CurrentState()->timeout;} );

...but I'm wondering whether we could simplify by adding something to YA_FSM::Update() that directly checks _currentState->timeout; Is there a reason you implemented with lambdas that I'm overlooking or could we add an AddTimedTransition(FROM_STATE, TO_STATE) function and skip the complexity of lambdas and function pointers?

Thank you for humoring me, and apologies if I'm missing something subtle for why you designed it this way. I'm not super familiar with lambda syntax and after a day of fighting with various captures and compiler warnings, wondered if this might be a simpler solution.

Bug in GetTimeout

YA_FSM::GetTimeout returns _currentState-YmaxTime as bool
Timout handling not working

Should be:

// Return true if timeout
bool YA_FSM::GetTimeout(uint8_t index){
	FSM_State* state = GetStateAt(index);
	if(state != nullptr ){
		return _currentState->timeout;
	}
	return false;
}

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.