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 code for Machine Controller
9 posts
• Page 1 of 1
Ruby code for Machine Controller
Included is a code file for my machine controller that will use 2 Phidgets 1063 stepper motor controllers and the Phidgets 1019 8/8/8 I/O board with USB hub.
My question involves how to use Ruby with this controller. I have separate test control panels for the I/O board and stepper motors 1 and 2 already written and working fine (see the attached file). My next step is to write Ruby code that will interact with the I/O panel and steppers 1 and 2 and operate them in a complicated sequential manner. So the Ruby code needs to sense inputs and control outputs on the I/O board and move stepper motors 1 and 2. If you look at the I/O board schematic you can see I already attached a Ruby component that connects to the inputs and outputs on the I/O board. Can I add Ruby components to the Stepper 1 and Stepper 2 schematics and have the 3 Ruby windows communicate with each other? Or does there need to be only 1 Ruby window that connects to the 3 boards? Please advise as it is not so clear how to proceed.
My question involves how to use Ruby with this controller. I have separate test control panels for the I/O board and stepper motors 1 and 2 already written and working fine (see the attached file). My next step is to write Ruby code that will interact with the I/O panel and steppers 1 and 2 and operate them in a complicated sequential manner. So the Ruby code needs to sense inputs and control outputs on the I/O board and move stepper motors 1 and 2. If you look at the I/O board schematic you can see I already attached a Ruby component that connects to the inputs and outputs on the I/O board. Can I add Ruby components to the Stepper 1 and Stepper 2 schematics and have the 3 Ruby windows communicate with each other? Or does there need to be only 1 Ruby window that connects to the 3 boards? Please advise as it is not so clear how to proceed.
- Attachments
-
- cc saw15.fsm
- (60.74 KiB) Downloaded 3677 times
- jerry
- Posts: 20
- Joined: Tue Nov 01, 2011 8:06 pm
- Location: Schaumburg, Illinois, USA
Re: Ruby code for Machine Controller
I added an image file for the controller.
- Attachments
-
- controller.PNG (56.09 KiB) Viewed 78765 times
- jerry
- Posts: 20
- Joined: Tue Nov 01, 2011 8:06 pm
- Location: Schaumburg, Illinois, USA
Re: Ruby code for Machine Controller
You can have as many Ruby components as you like.
They can only communicate with each other if you connect them.
Also your selector buttons are a bit over complicated, here is a better way:
They can only communicate with each other if you connect them.
Also your selector buttons are a bit over complicated, here is a better way:
- Attachments
-
- cc saw15b.fsm
- Selector Buttons
- (201.09 KiB) Downloaded 3728 times
- DSP
- Posts: 150
- Joined: Fri May 14, 2010 10:55 pm
Re: Ruby code for Machine Controller
Thanks for the tip on Ruby and providing a less complicated menu selector. I agree my menu selector was overly complicated and getting more so as I added more menu items!
- jerry
- Posts: 20
- Joined: Tue Nov 01, 2011 8:06 pm
- Location: Schaumburg, Illinois, USA
Re: Ruby code for Machine Controller
DSP wrote:You can have as many Ruby components as you like.
They can only communicate with each other if you connect them.
Hmm..
I thought I read about global vars between not only ruby code moduals, but all instances of your program too.. ?
- VPDannyMan
- Posts: 118
- Joined: Mon Jan 04, 2010 4:50 am
Re: Ruby code for Machine Controller
VPDannyMan wrote:I thought I read about global vars between not only ruby code moduals, but all instances of your program too.. ?
That's right, global and class variables are all shared across modules and instances. But without some fiddling with object bindings, changing their values won't trigger new events in other modules - the new values will just sit there waiting to be read by something. Maybe that's what DSP was getting at when he said 'not communicating' - you need the link there to trigger something to happen at the other end.
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 code for Machine Controller
OK so globals are useless as a communication/Interop mechanism would you say?
- VPDannyMan
- Posts: 118
- Joined: Mon Jan 04, 2010 4:50 am
Re: Ruby code for Machine Controller
VPDannyMan wrote:OK so globals are useless as a communication/Interop mechanism would you say?
Not necessarily - I've been making some use of them for the Debugger tool that I'm working on. And there are ways to trigger events between Rubies - but sometimes with strange side effects.
Here's a simple example...
Put two Ruby primitives into a schematic and connect a text readout to the standard default string output on each of them.
In the first one make a global variable that refers to the RubyEdit instance pointer...
- Code: Select all
$THIS_RUBY = @this
In the second Ruby instance, now call any of the RubyEdit methods, giving the Global reference as an explicit receiver...
- Code: Select all
$THIS_RUBY.output 0,"Hello"
...and the text magically appears at the output of the first Ruby instance.
You can achieve similar things in other ways; for example, passing around blocks of code as "Proc" objects that store the context in which the code block was declared. New Classes and Modules are also global, so it's also possible to define Module and Class methods that can be called from anywhere, but produce output in a particular place...
- Code: Select all
# RUBY 1
$THIS_RUBY = @this
module Foo
def self.output(value)
$THIS_RUBY.output 0,value,0
end
end
- Code: Select all
# RUBY 2
Foo::output("Hello")
However, here's the weird thing that I've noticed...
The easiest way to trigger events in another Ruby is by calling the input and output methods. But each Ruby instance also has it's own instance of the clock that is used for event scheduling.
When you call an event between different Ruby instances, the difference between the clocks messes with the timing of the triggers - they seem to get 'jet lagged' by the time difference between the two Ruby instance start times.
If you want the event to happen right now, you can seemingly get around this by setting the 'time' argument of the method to zero...
$THIS_RUBY.output 0,"hello",0
...but if you want to schedule an event for later, I've yet to find a reliable way to compensate for the time differences.
I've certainly had some useful results working with this stuff, but you do have to be very careful. Using objects with global scope, and the 'persistence' of values and definitions, makes for lots of opportunity for unexpected results when a variable is being targetted from all angles. This is more critical, I think, for those of us making VST plugins, as it is very common to run several instances of the same one within a music project - but they will are share the same set of global variables, classes and modules. I'm looking into this at the moment to see if there some way that instances could be indexed- but nothing reliable so far.
One other little tip - when working with globals that might be set from several places, the 'OR equals' method is very handy...
- Code: Select all
$MY_GLOBAL ||= [] # Global 'Or equals' empty array
$MY_GLOBAL << This value # New item into the array
The '||=' means "If this variable isn't set yet, use this value, otherwise keep the existing value". So in this case, the first time it is run, the global var' gets set to an empty array and a start value is fed in. Every other time it is called, a new value is added to the array without disturbing what is there already.
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 code for Machine Controller
Hmm. I will be doing some playin around later I think..
Very interesting, thanks.
Very interesting, thanks.
- VPDannyMan
- Posts: 118
- Joined: Mon Jan 04, 2010 4:50 am
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 3 guests