-3
\$\begingroup\$

I need to design a finite state machine that detects any invalid button sequences for a set of instructions. The scenario is a factory where the person must press POWER, WELD, and than POWER and that is the only valid set of button sequences for the machine to work properly. The instructions that I have state the user must press POWER to begin the machine, than WELD to weld the part, and finally POWER again to to turn off the machine. So for example a button sequence o POWER, POWER, WELD will result in an error. When designing the finite state machine for this scenario to capture only failures I tried to list all of the possibilities of a fail:

P P W

P P P

W W W

W P P

P W W

W W P

W P W

I think I am missing one, but I am not sure? Now when actually designing it I have four state bubbles, with the outputs FAIL=0, FAIL=0, FAIL=0, and FAIL=1 for the last bubble. How can I go about implementing all of these cases without drawing so many lines from bubble to bubble and having a mess? Thank you!

\$\endgroup\$
4
  • \$\begingroup\$ What do you want to happen if the user pushes POWER POWER WELD POWER? \$\endgroup\$
    – The Photon
    Jul 24, 2013 at 16:52
  • \$\begingroup\$ That's an error I believe. The instructions that I have state the user must press POWER to begin the machine, than WELD to weld the part, and finally POWER again to to turn off the machine. So I am assuming pressing POWER twice initially will cause an error and turn off the machine. Sorry for not stating that in my original post. \$\endgroup\$ Jul 24, 2013 at 16:56
  • 1
    \$\begingroup\$ Is this a learning excercise / homework or are you designing a real machine? \$\endgroup\$
    – The Photon
    Jul 24, 2013 at 17:46
  • \$\begingroup\$ It's a learning exercise/homework. \$\endgroup\$ Jul 24, 2013 at 18:36

2 Answers 2

2
\$\begingroup\$

Based on comments (the drawing tool didn't separate out the R and W; W goes to 4, and R goes to S):

enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ Thank you! What do the asterisks * represent in the above model? And I am assuming S is start? So I need 6 state bubbles how many will have an output of F=0 or F=1 for a failure? \$\endgroup\$ Jul 24, 2013 at 17:39
  • \$\begingroup\$ The * represents any input. States 4, 5, and 6 are all failure states. \$\endgroup\$ Jul 24, 2013 at 17:41
  • \$\begingroup\$ Some of these states are redundant, no? S->P->P ends up at 6. S->W ends up at 6, etc \$\endgroup\$
    – dext0rb
    Jul 24, 2013 at 17:41
  • \$\begingroup\$ @dext0rb: Only if not all three presses are required. I inferred from the question that e.g. P -> P -> P would be failure all throughout and not return to the initial state after the second P. \$\endgroup\$ Jul 24, 2013 at 17:45
  • \$\begingroup\$ @CharlesWitiker: If that's how you're representing the input, sure. \$\endgroup\$ Jul 24, 2013 at 17:47
0
\$\begingroup\$

Please see this state transition table (notation explained in http://en.wikipedia.org/wiki/State_transition_table#Two-dimensional_state_tables)

            |    POWER          WELD
            | -----------------------
  ->INITIAL |        P          FAIL
          P |     FAIL            PW
         PW |      PWP          FAIL
        PWP |     FAIL          FAIL
       FAIL |     FAIL          FAIL

State INITIAL is starting state. State PWP is accepting state - if you end up in this state after reading whole input sequence (must be exactly 3 button presses in defined order (power, weld, power)), you are accepting the sequence.

Otherwise if anything unwanted occurs (wrong button, incorrect number of button presses), state machine transitions to the FAIL state, where it stays until forever. If you end up in this state after reading whole input, you know that the user pressed incorrect buttons in incorrect order or whatever.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.