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
Ruby Ticker
8 posts
• Page 1 of 1
Ruby Ticker
Hi, I have been using the ruby ticker without understanding the code, and now I have to write a description for it (for a report), could anybody give me a hand? I´d highly appreciate.
-Alex
-Alex
- Code: Select all
def init
# Time step in secs
@step = 0.1
# Whether the timer has started ticking
@ticking = false
end
def event i,v,t
case i
when 0
if !@ticking && @state
@ticking = true
input 100,nil,t+@step
end
when 100
if @state
@step = 0.001 if @step <= 0
output 0
input 100,nil,t+@step
else
@ticking = false
end
end
end
- Alexandre
- Posts: 19
- Joined: Tue Oct 07, 2014 2:57 am
Re: Ruby Ticker
Key to understanding it are:
1) The 'event' method is called every time an input changes. It knows which input changed (i), a value (v: not used here), and the time when the event happened (t).
2) The 'input' method creates an input event that looks exactly the same as if a real input had changed. The input in this case is number 100 - this doesn't really exist as a component input, but Ruby doesn't care about that. The final value 't + @step' says when this new event should happen (it's bigger than t, so must be in the future).
So every time a 'tick' happens, the Ruby code sends out an input event to make another 'tick' happen a little bit in the future. The rest is just logic for turning the ticker on and off.
1) The 'event' method is called every time an input changes. It knows which input changed (i), a value (v: not used here), and the time when the event happened (t).
2) The 'input' method creates an input event that looks exactly the same as if a real input had changed. The input in this case is number 100 - this doesn't really exist as a component input, but Ruby doesn't care about that. The final value 't + @step' says when this new event should happen (it's bigger than t, so must be in the future).
So every time a 'tick' happens, the Ruby code sends out an input event to make another 'tick' happen a little bit in the future. The rest is just logic for turning the ticker on and off.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Ruby Ticker
Thanks, I think I got it now.
It also helped me understand some other examples ("Ticker - Custom" included with FS, and also AdamzCounter found elsewhere in this forum).
Funny that the input cannot be 1 on the example above (has to be 100, or 10, or 2, but not 1).
It also helped me understand some other examples ("Ticker - Custom" included with FS, and also AdamzCounter found elsewhere in this forum).
Funny that the input cannot be 1 on the example above (has to be 100, or 10, or 2, but not 1).
- Alexandre
- Posts: 19
- Joined: Tue Oct 07, 2014 2:57 am
Re: Ruby Ticker
You're welcome!
In fact, it could be, so maybe you understand more than you give yourself credit for! It just has to be a number bigger than the last "real" input (100 actually wastes a bit of memory in the RubyEdit, because the array of input data [@ins] takes up space for the missing inputs 1..99).
Alexandre wrote:Funny that the input cannot be 1 on the example above (has to be 100, or 10, or 2, but not 1)
In fact, it could be, so maybe you understand more than you give yourself credit for! It just has to be a number bigger than the last "real" input (100 actually wastes a bit of memory in the RubyEdit, because the array of input data [@ins] takes up space for the missing inputs 1..99).
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Ruby Ticker
Just for clarity: It can be any input that is not used already. So, if you have 2 inputs in use, index 0 and 1 can't be used, but index 2 would be available. In the DSPR modules, a high index was chosen probably to prevent any multiple use of an input (a user might add inputs to extend functionality, etc)
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Ruby Ticker
Yes, now I got it, 100%
Thanks trog and tulamide!
Simplest possible Ruby ticker below.
Thanks trog and tulamide!
Simplest possible Ruby ticker below.
- Alexandre
- Posts: 19
- Joined: Tue Oct 07, 2014 2:57 am
Re: Ruby Ticker
Consider the first example. If it´s set to a period of 60 seconds and we change it to 1 second then it can take up to 60 seconds to update.
To fix this I will use the attached one for my project.
Thanks,
Alex
To fix this I will use the attached one for my project.
Thanks,
Alex
- Attachments
-
- Alexandre Ticker 3.fsm
- (27.34 KiB) Downloaded 788 times
- Alexandre
- Posts: 19
- Joined: Tue Oct 07, 2014 2:57 am
Re: Ruby Ticker
Somehow I forgot about the usual "trigger div" component... I could have just used a trigger div instead of what I did above
- Alexandre
- Posts: 19
- Joined: Tue Oct 07, 2014 2:57 am
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 56 guests