-
Notifications
You must be signed in to change notification settings - Fork 7
Can we simplify time-based transitions? #4
Comments
P.S. Here's the line where I get compiler errors (https://github.com/mrisher/alien_escape/blob/refactor-pulsarFSM/src/matrixPulsarFsm.cpp#L13)
|
Hi @mrisher 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 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 |
Thank you for your response! I agree, I wasn't super happy adding an
additional variable, but I wasn't sure whether we can treat the MAXTIME as
the highest priority. If so, then I could simply check whether the time has
expired before looking at `Condition` and avoid adding the additional
member variable. Do you like that implementation?
…On Mon, Jul 25, 2022, 7:40 AM Tolentino Cotesta ***@***.***> wrote:
Hi @mrisher <https://github.com/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 do not think there was a need to
add dedicated property and method to the YA_FSM class.
—
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABVHNXA357S5SMAPV22OT3VV2RMXANCNFSM54GDZLMA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
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.
|
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... |
> state must last for a maximum of XXX milliseconds, what is the point of
binding the transition to an external condition
Agreed, that's how I was interpreting "Maximum" as well, so then the
sequence you have here makes sense to me (but if timeout sets
`_trigger=true` then we'd skip the condition checks). In pseudocode because
I'm on email
if (maxTime is set && timeout has occurred) then trigger;
else if (Condition callback returns true) then trigger;
else if (ConditionVar is true) then trigger;
/* else don't trigger */
I hadn't noticed the Wokwi link you shared, thank you for pointing it out.
… Message ID: ***@***.***>
|
I've updated the library as you suggest (if, else if). I'm going to close this issue if you agree. |
Awesome, thanks! Really appreciate your work here.
…On Wed, Aug 10, 2022, 6:55 AM Tolentino Cotesta ***@***.***> wrote:
Closed #4 <#4> as completed.
—
Reply to this email directly, view it on GitHub
<#4 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABVHNULDE6QSRR3KIYHNR3VYOYELANCNFSM54GDZLMA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
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 anAddTimedTransition(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.
The text was updated successfully, but these errors were encountered: