GithubHelp home page GithubHelp logo

Comments (9)

mrisher avatar mrisher commented on August 21, 2024

P.S. Here's the line where I get compiler errors (https://github.com/mrisher/alien_escape/blob/refactor-pulsarFSM/src/matrixPulsarFsm.cpp#L13)

/home/mrisher/src/alien_escape/src/matrixPulsarFsm.cpp: In lambda function:
matrixPulsarFsm.cpp:13:63: error: 'this' was not captured for this lambda function
                                 { return YA_FSM::CurrentState()->timeout; });
                                                               ^
matrixPulsarFsm.cpp:13:63: error: cannot call member function 'FSM_State* YA_FSM::CurrentState()' without object
/home/mrisher/src/alien_escape/src/matrixPulsarFsm.cpp: In member function 'void MatrixPulsarFSM::Setup()':
/home/mrisher/src/alien_escape/src/matrixPulsarFsm.cpp:13:76: warning: invalid user-defined conversion from 'MatrixPulsarFSM::Setup()::<lambda()>' to 'condition_cb {aka bool (*)()}' [-fpermissive]
                                 { return YA_FSM::CurrentState()->timeout; });
                                                                            ^
/home/mrisher/src/alien_escape/src/matrixPulsarFsm.cpp:12:43: note: candidate is: MatrixPulsarFSM::Setup()::<lambda()>::operator void (*)()() const <near match>
   AddTransition(PULSAR_ON, PULSAR_OFF, []()
                                           ^
/home/mrisher/src/alien_escape/src/matrixPulsarFsm.cpp:12:43: note:   no known conversion from 'void (*)()' to 'condition_cb {aka bool (*)()}'
In file included from /home/mrisher/src/alien_escape/src/matrixPulsarFsm.h:4:0,
                 from /home/mrisher/src/alien_escape/src/matrixPulsarFsm.cpp:1:
/home/mrisher/src/libraries/YA_FSM/src/YA_FSM.h:73:11: note:   initializing argument 3 of 'uint8_t YA_FSM::AddTransition(uint8_t, uint8_t, condition_cb)'
  uint8_t  AddTransition(uint8_t inputState, uint8_t outputState, condition_cb condition);
           ^~~~~~~~~~~~~

from ya_fsm.

mrisher avatar mrisher commented on August 21, 2024

Created a pull request: #5 #5

from ya_fsm.

cotestatnt avatar cotestatnt commented on August 21, 2024

Hi @mrisher
I'm sorry for late reply, I was on vacation last week.

I am glad you are satisfied with this library, I have developed it mainly for my benefit and for this reason it is unfortunately not very well documented.

Regarding your request, it actually makes sense that if I define a maximum timeout time for the state, this then automatically go to the next one (according to the defined transitions) without the need to add a callback function or a dedicated variable.

However, I am not entirely convinced of the way in which you have implemented the functionality because I don't think there was a need to add dedicated property and method to the YA_FSM class.

Take a look at how I implemented the functionality. It's only in testing for now, but I think I'll officially add it to the repository soon

from ya_fsm.

mrisher avatar mrisher commented on August 21, 2024

from ya_fsm.

cotestatnt avatar cotestatnt commented on August 21, 2024

I could simply check whether the time has expired

That's more or less what I did in the wokwi example I linked you to.

If a trigger variable or callback function is not defined, the transition will be triggered on timeout, but this condition is the "weakest" because it is evaluated first.

By default, now both the callback pointer and the variable pointer are == nullptr so, when they are assigned, the local _trigger bool variable will be overwritten regardless of the timeout state.

     bool _trigger = false;

     // If a max time was defined check if current state is on timeout      
     if (_currentState->maxTime) {        
       _currentState->timeout = millis() - _currentState->enterTime > _currentState->maxTime;              
       // Trigger transition on timeout
       if (_currentState->timeout)    
         _trigger = true;        
     }  
   
     // Trigger transition on callback function result if defined
     if (actualtr->Condition != nullptr)
       _trigger = actualtr->Condition();    

     // Trigger transition on bool variable value == true
     if (actualtr->ConditionVar != nullptr) 
       _trigger =  *(actualtr->ConditionVar);   

from ya_fsm.

cotestatnt avatar cotestatnt commented on August 21, 2024

Thinking about it, maybe it would be the case that instead the timeout is a priority by putting the relative if statement as last position...
I'm not sure about it: after all, if I decide that a state must last for a maximum of XXX milliseconds, what is the point of binding the transition to an external condition if it arrives late? What's your opinion?

from ya_fsm.

mrisher avatar mrisher commented on August 21, 2024

from ya_fsm.

cotestatnt avatar cotestatnt commented on August 21, 2024

I've updated the library as you suggest (if, else if). I'm going to close this issue if you agree.
I've modified also the examples.

from ya_fsm.

mrisher avatar mrisher commented on August 21, 2024

from ya_fsm.

Related Issues (3)

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.