-
Notifications
You must be signed in to change notification settings - Fork 50
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
Updatable loop occasionally fails to start #60
Comments
Looking at it a bit more, I noticed that the ModeState static configuration loop gets executed, along with its runtime configure options, before moving onto the inner initial state's static, runtime and onEntry functions. Is it possible that during the process of executing the outer state's configuration, the guards preventing the CBs from being added are momentarily disabled, allowing the CB list to be prematurely updated? |
You are right. Precisely I fixed that lately in SMACC2. Have a look with this line of code of the run_async branch of SMACC2: does that solution look like it fixed your problem? We have to backport that change to SMACC1 |
@pabloinigoblasco Funnily enough, I tried adding an extra flag, but didn't see the one you linked. This looks like it might work though, I'll apply it on our robot and see if the behaviour is fixed. |
The case is that that flag is only in SMACC2 because some lately issues, so we also need to add it to SMACC1. It should be fast, I will do that asap. |
Sounds good! Feel free to close the issue once the changes are merged in and I'll update our code |
Fixed in #61 |
I'm afraid the guard @pabloinigoblasco added in #61 doesn't seem to be working as expected and this issue is still popping up intermittently (see the log output below)
Note the indented lines - In the case above, we're using a modestate with its inital internal state being the one transitioned into. Could it be that one of the |
Hello @yassierzar, How often does the issue occur in your example? The use of ModeState and Updateable Behaviors might be some untested use case. I suspect that the issue occurs when a child state begins where the stateMachine action switch from STEADY (mode state) TO CONFIGURING (child state). I've created a PR #87 to address this problem. Can you try the patch and let me know if it resolves the issue? Thanks, |
Its quite unpredictable, but happens often enough - at times it works fine for 10 restarts, but other times the bug comes up for the next 4 restarts.
That's exactly what I was thinking too. Thanks for addressing this so quickly, I'll try your patch today and let you know. |
Unfortunately it seems your patch didn't quite do it:
I expect to see log output from the updatable in between the heartbeats |
I managed to hack together something that looks like it might fix the issue. I've opened up PR #88 with more detail, but testing with a more diverse state configuration set is needed to make sure it actually works as expected. Let me know what you think |
From what I understand, your proposal mainly involves avoiding the intermediate STEADY state by skipping the Steady state update for "parent states." Additionally, there are some aesthetic changes that involve the usage of std::atomic, which looks good. My position is to accept your PR because it is good and it fixes a clearly defined use case that crashes. These changes subtly alter the behavior of the state machine during the initialization of mode states, so this PR is important. I believe that the initialization order of parent states and child states is something that has been less tested, so this research work and fix you did here is really welcome. It is unlikely that any of our examples or user developments have faced this issue and I think they will keep working the same I want to test this PR in some of our examples. After doing this validation I will accept the PR and I will migrate these changes to all SMACC and SMACC2 versions. Thank you very much for this research and fix @yassiezar . |
No problem @pabloinigoblasco, hopefully it works as expected and gets pulled in. I'd be curious what the interaction would look like with a deeper state hierarchy (e.g. superstate -> modestate -> child state). Also, some additional refactoring might be necessary, since some configuration calls may no longer triggered when a parent state has completed initialisation (this is something I didn't look at too much). Let me know if I can help with integration or testing. |
Issue:
I have an updatable client behaviour defined which is activated within the state machine's initial state. However, I've noticed that the update loop occasionally fails to begin getting called and the update callback is never entered. This seems to be totally random and I'm not able to trigger it manually
Analysis:
I've taken a look at the update loop here and noticed that, at times, the client behaviour table is updated here before all the client behaviours have finished being added and initialised. Then, at the next loop when the CBs have actually been added, the table is not updated (since now
lastState_ == currentState
) and noupdate()
functions can be executed. The log output below shows the behaviour I'm talking about where the CB table is updated to soon:...
[ INFO] [1658248892.188056645]: [sm::StRest] Configuring orthogonal: sm::OrHttp
[ INFO] [1658248892.188219663]: [PollOnce] current state: 2
[ INFO] [1658248892.188328821]: [PollOnce] last state: 0
[ INFO] [1658248892.188391033]: [PollOnce] detected new state, refreshing updatable client behavior table
[ INFO] [1658248892.188716652]: updatable state elements: 0
[ INFO] [1658248892.188908727]: [Orthogonal sm::OrHttp] adding client behavior: sm::CbRobotStatusUpdate
[ INFO] [1658248892.189014429]: [sm::StRest] Creating static client behavior: sm::CbAthenaTeleopActivate
[ INFO] [1658248892.189069920]: [sm::StRest] Configuring orthogonal: sm::OrAthena
[ INFO] [1658248892.189136324]: [Orthogonal fox_rt::OrAthena] adding client behavior: fox_rt::CbAthenaTeleopActivate
[ INFO] [1658248892.189194567]: [sm::StRest] ---- END STATIC DESCRIPTION
[ INFO] [1658248892.189241322]: [sm::StRest] State runtime configuration
[ INFO] [1658248892.189299437]: [Orthogonal sm::OrAthena] runtimeConfigure, current Behavior: sm::CbAthenaTeleopActivate
[ INFO] [1658248892.189358129]: [Orthogonal sm::OrHttp] runtimeConfigure, current Behavior: sm::CbRobotStatusUpdate
[ INFO] [1658248892.189444054]: [Orthogonal sm::OrTeleop] runtimeConfigure, current Behavior: sm::CbTeleopActivate
[ WARN] [1658248892.189534459]: [StateMachine] setting state active : sm::MsAutonomousOperationMode/sm::StRest
[ INFO] [1658248892.189664259]: [sm::StRest] State OnEntry
[ WARN] [1658248892.189789194]: Required client [sm::ClTeleopSafeStopService] not found in current orthogonal. Searching in other orthogonals.
[ WARN] [1658248892.189890032]: Required client [sm::ClTeleopSafeStopService] found in other orthogonal.
[ WARN] [1658248892.189974741]: Brakes already active
[ INFO] [1658248892.190018167]: In rest state
[ INFO] [1658248892.190064186]: [sm::StRest] State OnEntry code finished
[ INFO] [1658248892.190115645]: [Orthogonal sm::OrAthena] OnEntry, current Behavior: sm::CbAthenaTeleopActivate
[ INFO] [1658248892.190658684]: [StateMachine] life-time constrained smacc signal subscription created. Subscriber is sm::CbAthenaTeleopActivate
[ INFO] [1658248892.190730497]: [Orthogonal sm::OrFollowMe] OnEntry
[ INFO] [1658248892.190783524]: [Orthogonal sm::OrFrontZedCamera] OnEntry
[ INFO] [1658248892.190879113]: [Orthogonal sm::OrGpio] OnEntry
[ INFO] [1658248892.190928492]: [Orthogonal sm::OrHttp] OnEntry, current Behavior: sm::CbRobotStatusUpdate
[ INFO] [1658248892.191234302]: [StateMachine] life-time constrained smacc signal subscription created. Subscriber is sm::CbRobotStatusUpdate
[ INFO] [1658248892.191296961]: [Orthogonal sm::OrMapping] OnEntry
[ INFO] [1658248892.191341444]: [Orthogonal sm::OrNavigation] OnEntry
[ INFO] [1658248892.191384166]: [Orthogonal sm::OrRearZedCamera] OnEntry
[ INFO] [1658248892.191426505]: [Orthogonal sm::OrRfid] OnEntry
[ INFO] [1658248892.191468683]: [Orthogonal sm::OrScales] OnEntry
[ INFO] [1658248892.191517230]: [Orthogonal sm::OrTeleop] OnEntry, current Behavior: fox_rt::CbTeleopActivate
[ INFO] [1658248892.192057838]: [StateMachine] life-time constrained smacc signal subscription created. Subscriber is sm::CbTeleopActivate
[ INFO] [1658248892.192154355]: [Orthogonal sm::OrTimer] OnEntry
[ WARN] [1658248892.192233112]: [StateMachine] setting state active : sm::MsAutonomousOperationMode/sm::StRest
[ INFO] [1658248892.238259719]: [PollOnce] current state: 2
[ INFO] [1658248892.238412271]: [PollOnce] last state: 2
[ INFO] [1658248892.238478035]: updatable state elements: 0
[ INFO] [1658248892.288266301]: [PollOnce] current state: 2
...
Possible fix:
I'm not sure how to approach this. My guess is that the checks here should prevent this behaviour, but its not doing so reliably (at least in this case). The workaround we're using is to start a timer at the CB's initialisation which executes a state transition back into the state to recreate everything, if the timer isn't stopped within an allotted time.
┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: