Page 1 of 1

Creating Modules with Ruby for Unsuported USB Hardware

Posted: Thu May 02, 2013 5:26 pm
by granta1969
Hello. I've been working on a little project which uses Servo controlles. Flowstone supports servos by a company called Phidgets. When I went to the Phidgets website I was disapointed to see that their cheapest usb servo controller was about £40 and it only supported one servo. If you want to control up to 6 you're looking at nearly £200. I noticed on the phidgets website that they provided programming examples and saw they even provided samples for Ruby.

After searching the web I found an ideal usb servo controller by the Polulu company for £15 which supports 6 independant servos. The Micro Maestro 6-Channel USB Servo ControllerPerfect. It's a company based in Las Vegas Nevada but Proto-Pic here in the U.K. sells it. Only one problem though. How do I use Flowstone to control it? Well the people at Polulu have considered this sort of problem. They have designed it to work with a Com Port to usb converter driver. and since flowstone supports a Com Port module it should be easy to send com port commands to the usb device via the com port converter driver. It's not really an ideal solution though. ideally you want flowstone to directly control the device.

the question here is this. Is it possible for Ruby to work with any unkown usb device that you might install onto your system? I'm assuming of course that you have the driver for the device and it's installed. Would ruby be able to directly control The Micro Maestro without using the Com Port driver and the com port module? You would think it would.. I'm still learning it though and I havent' gotten very far.

I'm going to buy the Maestro and experiment with the com port driver at first just to get things up and running.. But does anyone here have knowledge if it's possible to get Ruby to control the device itself? the Maestro comes with lots of documentation and all that. it comes with programming examples, but unfortunately not ruby examples.

any insights would be greatly appreciated!

Grant

Re: Creating Modules with Ruby for Unsuported USB Hardware

Posted: Thu May 02, 2013 6:27 pm
by fixstuff555
As far as I know, Pololu's protocol is the same among their other modules. I tested out their 24V23 modules, and made a 4ch FS project a while back. If you look in the module itself, you'll see 4 modules on the right labeled "Front Left", Rear Left", etc. Inside those modules is the way I used to communicate with the Pololu hardware over the COM port. Porting it over to Ruby shouldn't be to tough.

Here is the previous post with it:

http://www.dsprobotics.com/support/viewtopic.php?f=3&t=608

Re: Creating Modules with Ruby for Unsuported USB Hardware

Posted: Thu May 02, 2013 6:37 pm
by fixstuff555
Belay that. I used the ASCII protocol, and the Maestro doesn't have that one...

Re: Creating Modules with Ruby for Unsuported USB Hardware

Posted: Thu May 02, 2013 8:47 pm
by trogluddite
granta1969 wrote:ideally you want flowstone to directly control the device.

It looks like that may be possible - Pololu also have a USB SDK available for direct USB comm's, so that you can access the features not available through the serial interface.
Such an SDK usually just consists of a bunch of .dll files containing the necessary functions - and Ruby is able to call any .dll function using it's Win32API class.
Without looking at the SDK doc's in much more detail, it's hard to tell how difficult this would be - but .dll calls have a fairly standard format so long as the SDK describes the functions in adequate detail. You can then define a bunch of Ruby methods to "wrap" the dll calls to make them more user-friendly for day-to-day use.

Don't dismiss the serial interface though. Serial-via-USB is used by a lot of devices out there because it does make life mush simpler - you can typically communicate by just building strings of encoded characters (something else Ruby is very good at). And the Pololu hardware handles all the tricksy PWM for you, so the number and speed of commands you send would be dramatically less than if you had to generate those signals yourself - meaning that the relatively slow speed of serial would be unlikely to cause any serious headaches in practice.

Looks like a very nice bit of kit - especially at that price!

Re: Creating Modules with Ruby for Unsuported USB Hardware

Posted: Tue Aug 27, 2013 2:29 am
by brighton36
Try the newer phidgets_native gem instead of the phidgets-ffi gem. There's no ffi requirement, it's faster, and way more stable. Probably that will help you out tremendously.