Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

simple state machine in Ruby

Post any examples or modules that you want to share here

simple state machine in Ruby

Postby fixstuff555 » Thu May 03, 2012 2:33 pm

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 1364 times
fixstuff555
 
Posts: 151
Joined: Thu Oct 21, 2010 3:24 pm

Re: simple state machine in Ruby

Postby DSP » Sat May 19, 2012 5:43 am

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 1348 times
DSP
 
Posts: 150
Joined: Fri May 14, 2010 10:55 pm


Return to User Examples

Who is online

Users browsing this forum: No registered users and 45 guests

cron