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
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
simple state machine in Ruby
2 posts
• Page 1 of 1
simple state machine in Ruby
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.
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 1453 times
- fixstuff555
- Posts: 151
- Joined: Thu Oct 21, 2010 3:24 pm
Re: simple state machine in Ruby
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:
Here's you example modified to make a set of traffic lights:
- Attachments
-
- state machine trafic light.fsm
- (26.86 KiB) Downloaded 1445 times
- DSP
- Posts: 150
- Joined: Fri May 14, 2010 10:55 pm
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 49 guests