Reputation: 171
I was wondering whether or not it's possible to implement the following.
What do I want to do?. Imagine the Big Ben's melody. I want to play a fourth of the melody every quarter of an hour. I want a FSM which has the following states:
(xx = dont care)
For each state, i have another FSM. This FSM will make sure the music will play correctly.
If(state = whole hour)
{
switch music_state
case A
{ play 1 sec, next_music_state = F}
case and so on ......
Does this work? Can I make a FSM which has the different states of an hour, and for each state have another FSM?
If something is unclear, let me know, and I will try to clarify it. I know this part is not that hard, but I am still wondering whether or not this implementation will work. I hope, and also think, it will, though I want to be certain of it.
Thanks a lot in advance!
Upvotes: 1
Views: 88
Reputation:
Meta-state machines with both an "inner state" and an "outer state" are certainly possible. I have done something similar for a while but it was only last week that the penny dropped and I finally wrote a state machine with two separate states. In a single process SM, it worked like a dream.
The "inner state machine" runs just like a normal state machine but in its last state, you test the meta-state or outer state, to determine which part of the outer sequence to despatch to next.
Upvotes: 2
Reputation: 5289
You could make single FSM to keep it simple...
The default state will be IDLE: This will check for the time (whole hour, quarters or half past), if one of them happens, you'll just run proper states like: MUSIC_FOR_WHOLE_HOUR, MUSIC_FOR_HALF_PAST ...
Those states will run their different chain of states that will play their music and will return back to the IDLE state to wait for next proper time to play again.
Upvotes: 1