simple state machine in Ruby

Post any examples or modules that you want to share here
Post Reply
fixstuff555
Posts: 151
Joined: Thu Oct 21, 2010 3:24 pm

simple state machine in Ruby

Post by fixstuff555 »

Here is something that I had been wanting to do, as well as others.

It's a simple state machine in a Ruby code block, that illustrates a couple important concepts and uses the event method. The first and second inputs are external event triggers, and the 101st and 102nd are "internal" triggers. The 2nd set of numbering is irrelevant, but is set aside at a high number so that more external events can be added later.

Basically, to transition from state 1 to state 2, input 101 event is triggered by the timer reaching 2 seconds. The states work through accordingly. This also is a good illustration of using timer's in a Ruby block.
Attachments
state machine.fsm
(26.71 KiB) Downloaded 1586 times
DSP
Posts: 150
Joined: Fri May 14, 2010 10:55 pm

Re: simple state machine in Ruby

Post by DSP »

Or another way is to add the t (time) to the output statement: eg: output 1,true,t+2

Here's you example modified to make a set of traffic lights:
Attachments
state machine trafic light.fsm
(26.86 KiB) Downloaded 1558 times
Post Reply