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
How to properly use delays in a ruby module?
12 posts
• Page 1 of 2 • 1, 2
How to properly use delays in a ruby module?
How to properly use delays in a ruby module?
I have been trying to create a delay in a ruby case statement by using 'sleep', but it does not work as expected.
One of the main problems is that 'sleep' is affecting another ruby module's timing, that is supplying data to the ruby module with the delay.
Example:
State = @in
case State
when "VA"
sleep(0.6)
output 0,@in
break
end
What I am trying to do is read the streaming data at the input 0.6 seconds after "VA" is detected.
I have been trying to create a delay in a ruby case statement by using 'sleep', but it does not work as expected.
One of the main problems is that 'sleep' is affecting another ruby module's timing, that is supplying data to the ruby module with the delay.
Example:
State = @in
case State
when "VA"
sleep(0.6)
output 0,@in
break
end
What I am trying to do is read the streaming data at the input 0.6 seconds after "VA" is detected.
-
Subquantum - Posts: 24
- Joined: Tue Mar 11, 2014 10:20 pm
- Location: USA
Re: How to properly use delays in a ruby module?
is this what you are after?
the "stream of seconds" module basically uses ticker and counter to create a rough clock that counts seconds (with fractional part too).
The ruby module has 3 inputs, one is the stream, second is the trigger to schedule the reading (the "if i==1" part) and third triggers the reading (the "if i==2" part)
you may change all of inputs and outputs to ruby value connectors and it should work too.
the "stream of seconds" module basically uses ticker and counter to create a rough clock that counts seconds (with fractional part too).
The ruby module has 3 inputs, one is the stream, second is the trigger to schedule the reading (the "if i==1" part) and third triggers the reading (the "if i==2" part)
you may change all of inputs and outputs to ruby value connectors and it should work too.
- Attachments
-
- ruby delayed read.fsm
- (667 Bytes) Downloaded 827 times
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: How to properly use delays in a ruby module?
actually I already tried using "def event (i,v,t)" and it just gave me a delay of the entire input.
I am receiving a stream of : VA 1010 VB 632 VA 1009 VB 631 VA 1011 VB 633....etc
with a half second delay between data sets. I'm using a case statement to check if a VA or a VB is received. When one is received, I would like to then capture the single numerical value that follows it(1009), which should arrive a half second later.
I suppose I can also use an if then statement, but I still have a problem with the delayed capture.
the "def event (i,v,t)" just gives the same value at the output 0.6 seconds later.
I am receiving a stream of : VA 1010 VB 632 VA 1009 VB 631 VA 1011 VB 633....etc
with a half second delay between data sets. I'm using a case statement to check if a VA or a VB is received. When one is received, I would like to then capture the single numerical value that follows it(1009), which should arrive a half second later.
I suppose I can also use an if then statement, but I still have a problem with the delayed capture.
the "def event (i,v,t)" just gives the same value at the output 0.6 seconds later.
-
Subquantum - Posts: 24
- Joined: Tue Mar 11, 2014 10:20 pm
- Location: USA
Re: How to properly use delays in a ruby module?
Subquantum wrote:I am receiving a stream of : VA 1010 VB 632 VA 1009 VB 631 VA 1011 VB 633....etc
with a half second delay between data sets. I'm using a case statement to check if a VA or a VB is received. When one is received, I would like to then capture the single numerical value that follows it(1009), which should arrive a half second later.
You don't need a delay for that. Also, timing is never 100% accurate, neither on external modules nor on a PC. Never rely on a fixed interval to grab values!
What you need is a switch selector that is active as long as no numerical values are received. Since I don't know what you are doing with the two parts (e.g. "VA" "1010") I can't provide an exactly working solution, but can give you hints, so that you can adapt it to your special needs.
- Code: Select all
@selector = ""
def event i, v
if v == "VA" or v == "VB"
@selector = v
else
case @selector
when "VA"
output 0, v
when "VB"
output 1, v
end
@selector = ""
end
end
This code looks for either VA or VB. only then the 'else' is executed which sends the value (e.g. 1011) to the first output if prior input was "VA", or the second if prior input was "VB". After that @selector is set to an empty string to prevent further sending of values, until input is "VA" or "VB" again.
EDIT: I might have been unclear in my description. 'else' is of course executed on every event, but since @selector only meets the specification, if prior input was either 'VA' or 'VB', there's nothing to execute. That's a ore exact description.
EDIT 2: *sigh* Sometimes the english language is not my best friend. If input is not 'VA' nor 'VB' then 'else' is executed. Since the case statement only reacts to 'VA' or 'VB', nothing is sent if @selector is an empty string. I hope it is now finally described correctly.
- Attachments
-
- Ruby_Switching_VA_VB.fsm
- (453 Bytes) Downloaded 798 times
Last edited by tulamide on Fri Oct 24, 2014 5:54 am, edited 1 time in total.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: How to properly use delays in a ruby module?
Found this interesting,.... so i had at go at it, got a good result too.
My idea was simple, to separate the incoming data into variables so it can be controlled.
I used a counter to count the triggers coming in.
Then, if input is either "VA" or "VB" , both data sets are then counted and put into an array.
The second value is then outputed.
This is followed by one more trigger, to reset array in preparation for next incoming trigger.
(Note: I have set the rest trigger very tight, at 0.61...you may want to experiment with this)
Hope this helps...
My idea was simple, to separate the incoming data into variables so it can be controlled.
I used a counter to count the triggers coming in.
Then, if input is either "VA" or "VB" , both data sets are then counted and put into an array.
The second value is then outputed.
This is followed by one more trigger, to reset array in preparation for next incoming trigger.
(Note: I have set the rest trigger very tight, at 0.61...you may want to experiment with this)
Hope this helps...
BV MUSIC SYDNEY AUSTRALIA..Songwriting and Software development
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
- billv
- Posts: 1157
- Joined: Tue Aug 31, 2010 3:34 pm
- Location: Australia
Re: How to properly use delays in a ruby module?
You guys are Awsome!
I got this all working using a combination from the code KG_is_back provided, and the case statement that I already had. It is similar to what billv posted. But I think tulamide is correct about potential timing issues. I will look further into this. I was thinking pushing and popping data sets into and out of queue. this application needs to be stable over a long period of time.
Tulamide, how do you suggest separating the data from the stream to the inputs of your two index selectors?
I have two power supplies connected in series, I then have a microcontroller reading the voltage off of each one, then I stream the values via RS232 to flowstone where I add them and divide by two. I plan on doing similar for the current. I then plan on graphing them over time, still in the works.
Here is what I have so far, the data is incoming from the Com port:
I got this all working using a combination from the code KG_is_back provided, and the case statement that I already had. It is similar to what billv posted. But I think tulamide is correct about potential timing issues. I will look further into this. I was thinking pushing and popping data sets into and out of queue. this application needs to be stable over a long period of time.
Tulamide, how do you suggest separating the data from the stream to the inputs of your two index selectors?
I have two power supplies connected in series, I then have a microcontroller reading the voltage off of each one, then I stream the values via RS232 to flowstone where I add them and divide by two. I plan on doing similar for the current. I then plan on graphing them over time, still in the works.
Here is what I have so far, the data is incoming from the Com port:
- Attachments
-
- FS_RS232_PScontrol.2.fsm
- (33.6 KiB) Downloaded 845 times
-
Subquantum - Posts: 24
- Joined: Tue Mar 11, 2014 10:20 pm
- Location: USA
Re: How to properly use delays in a ruby module?
Ok,
I used the code provided by tulamide and it works fantastically!! Although the method i had used worked, This is most definitely the proper method for doing this.
tulamide, thanks for the code and the instruction: "Never rely on a fixed interval to grab values!"
I am new to capturing data over RS232 with both flowstone and ruby, this has been quite an education.
Thank you all who contributed. your help is greatly appreciated.
I used the code provided by tulamide and it works fantastically!! Although the method i had used worked, This is most definitely the proper method for doing this.
tulamide, thanks for the code and the instruction: "Never rely on a fixed interval to grab values!"
I am new to capturing data over RS232 with both flowstone and ruby, this has been quite an education.
Thank you all who contributed. your help is greatly appreciated.
-
Subquantum - Posts: 24
- Joined: Tue Mar 11, 2014 10:20 pm
- Location: USA
Re: How to properly use delays in a ruby module?
I'm glad I could be of help. Good luck with your project. And should there be other issues, just ask. I found quite a few people here are always willing to help
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: How to properly use delays in a ruby module?
tulamide,
I have searched through a few Ruby books for more information on selectors, but have not found anything. I have found a few references to selectors for objective-c and visual basic. can you provide a link to their description and use in Ruby?
I have searched through a few Ruby books for more information on selectors, but have not found anything. I have found a few references to selectors for objective-c and visual basic. can you provide a link to their description and use in Ruby?
-
Subquantum - Posts: 24
- Joined: Tue Mar 11, 2014 10:20 pm
- Location: USA
Re: How to properly use delays in a ruby module?
What sort of data to you want switch between?
A simple selector(ie. a replacement of the selector primitive)
should be no sweat I think
A simple selector(ie. a replacement of the selector primitive)
should be no sweat I think
-
nix - Posts: 817
- Joined: Tue Jul 13, 2010 10:51 am
12 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 57 guests