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

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

For general discussion related FlowStone

Ruby Ticker

Postby Alexandre » Fri Jan 03, 2020 1:50 am

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
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

Postby trogluddite » Fri Jan 03, 2020 5:26 pm

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.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby Ticker

Postby Alexandre » Thu Jan 09, 2020 2:07 am

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).
Alexandre
 
Posts: 19
Joined: Tue Oct 07, 2014 2:57 am

Re: Ruby Ticker

Postby trogluddite » Thu Jan 09, 2020 10:37 am

You're welcome!
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!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby Ticker

Postby tulamide » Thu Jan 09, 2020 10:56 am

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

Postby Alexandre » Thu Jan 09, 2020 7:10 pm

Yes, now I got it, 100%
Thanks trog and tulamide!
Simplest possible Ruby ticker below.

capture.png
capture.png (20.42 KiB) Viewed 12146 times
Alexandre
 
Posts: 19
Joined: Tue Oct 07, 2014 2:57 am

Re: Ruby Ticker

Postby Alexandre » Thu Jan 09, 2020 11:21 pm

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
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

Postby Alexandre » Fri Jan 10, 2020 2:56 am

Somehow I forgot about the usual "trigger div" component... I could have just used a trigger div instead of what I did above :lol:
Alexandre
 
Posts: 19
Joined: Tue Oct 07, 2014 2:57 am


Return to General

Who is online

Users browsing this forum: Google [Bot] and 75 guests