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
7 posts
• Page 1 of 1
Ruby: while statement
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.
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
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.
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 1228 times
- Embedded
- Posts: 143
- Joined: Sat Oct 30, 2010 1:42 pm
Re: Ruby: while statement
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.
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
Try this, this uses the FlowStone events system to add a delay to the loop and therefore avoids an infinite loop.
- 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
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
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.
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
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
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: Google [Bot] and 72 guests