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: while statement

For general discussion related FlowStone

Ruby: while statement

Postby jerry » Sun Feb 26, 2012 5:23 pm

I wanted to use a while statement to loop in ruby until a limit switch was pressed.
Ruby gives an error : "excessive processing detected"
See code below:

while @ins[0] == false do
end

Please advise how to suspend operation until an event occurs.
jerry
 
Posts: 20
Joined: Tue Nov 01, 2011 8:06 pm
Location: Schaumburg, Illinois, USA

Re: Ruby: while statement

Postby Embedded » Sun Feb 26, 2012 7:55 pm

Yes you have created an infinite loop, which is not good in programming terms. Hence FlowStone catches it before it causes your system to crash.

You should use a:

def event i,v,t

end

with you code inside,not the infinite loop, but what you actually what to do.
Attachments
def event.fsm
(329 Bytes) Downloaded 1227 times
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

Re: Ruby: while statement

Postby jerry » Mon Feb 27, 2012 8:53 pm

I tried the event method you provided and I see how it continuously loops, but is there a way to exit out of that loop? Like a while statement I want to loop until a condition is met, perform an action, then exit out of the loop.

I am converting qbasic code that uses while loops and is working fine but I want to convert it to Flowstone/Ruby.
jerry
 
Posts: 20
Joined: Tue Nov 01, 2011 8:06 pm
Location: Schaumburg, Illinois, USA

Re: Ruby: while statement

Postby Embedded » Wed Feb 29, 2012 12:04 pm

Try this, this uses the FlowStone events system to add a delay to the loop and therefore avoids an infinite loop.

while loop break clip.png
while loop break clip.png (29.04 KiB) Viewed 19780 times
Attachments
while loop break.fsm
(523 Bytes) Downloaded 1168 times
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

Re: Ruby: while statement

Postby jerry » Thu Mar 01, 2012 3:02 pm

Thanks for the very useful code, I see the delay is working and definitely needed, if I reduce it from .01 to .001 flowstone has an error.
jerry
 
Posts: 20
Joined: Tue Nov 01, 2011 8:06 pm
Location: Schaumburg, Illinois, USA

Re: Ruby: while statement

Postby jerry » Sun Mar 04, 2012 3:35 am

I see how the repeating if statement is equivalent to a while statement but I have not found a way to break out of the event method. If I add a "break" statement in the else loop I get an invalid break error. See below.

else
output 0, "Not Looping"
@count = 0
output 1, @count
break if @ins[0] == false
end

Invalid break.
jerry
 
Posts: 20
Joined: Tue Nov 01, 2011 8:06 pm
Location: Schaumburg, Illinois, USA

Re: Ruby: while statement

Postby DSP » Mon Mar 05, 2012 1:00 pm

Thanks for the very useful code, I see the delay is working and definitely needed, if I reduce it from .01 to .001 flowstone has an error.


The ruby part will happily run up to around 20Khz, ( 0.00005) but if you output this into the GUI system to display it you will overload the PC. Hence while it works ok at 100hz (0.01).
Remember FlowStone is a programming language and therefore you can do pretty much what you want, doesn't mean it always good programming though, so you have to think carefully about what it is you are doing.
DSP
 
Posts: 150
Joined: Fri May 14, 2010 10:55 pm


Return to General

Who is online

Users browsing this forum: No registered users and 80 guests