Direct control of a Servo or Speed Controller

Is it possible to control a servo directly from the digital output of the NI USB 6009? I did some rough timing calculations and based on what I determined I believe the NI USB 6009 system does not have a fine enough timing resolution to accurately control a servo.

Here’s what I’ve got:
The standard servo signal pulse width varies from 1mS to 2mS to correlate from a 0 position to a full-deflection position. I’ve also measured systems that use a 2mS to 4mS and 4mS to 8mS pulse but it’s not critical for this discussion. Assuming 256 steps of resolution and a 1mS to 2mS pulse width there is 3.9uS of time per step.

Unless I’m doing something wrong (which is highly possible), the fastest timed loop I could create was 1kHz (1mS loop time). This is about an order of magnitude slower than I was hoping to obtain.

I have two questions:

  1. Has anybody tried to directly control the servos from the digital output of the USB 6009?
  2. If so, can you either post your code or point me in the direction of sample code to complete this?

The end goal was to work with Josh (a student on Team 93) to create a stand-alone control system with the custom gyro board. At this point we can effectively read the analog and digital feedback signals from the custom board, but without effective servo (or in this case speed controller) output from the USB 6009 we still need a robot controller involved in the loop. This is less than ideal because of the added delays that will be added into the control loop that are caused by conversions of data within the robot controller.

Once we’ve got the control loop optimized through the USB 6009 the plan is to implement a similar loop though software on the robot controller. If we get this to function we will gladly present any/all data along with the custom gyro board information.

At this point any feedback would be greatly appreciated.

As you’ve learned, it doesn’t appear that the USB-6009 can directly create the requisite servo control signals (maybe the NI guys can shed a bit more light?). You’ll either need a voltage-to-PWM signal generator (I haven’t found a really easy circuit but a 555 timer is a good starting point) or some other PWM signal generator. My recommendation is to use either the CMUcam2 as a servo control or buy an off-the-shelf servo signal generator. If you really want to get down-and-dirty, you could even spin your own microcontroller-based solution to convert either a voltage output (from the USB-6009, for example) or an RS232 command to a PWM signal.

The CMUcam2 GUI app and its underlying VIs provide access to the 5 servo control signal generators.

The other option is to use an inexpensive signal generator such as the Mini-SSC II (serial servo controller). You can buy these from Jameco for about $40. Very simple RS232 serial string to control up to 8 servos.

Good Luck!

At this point I think we’re going to write a small app using one of our old robot controllers that basically does an analog to PWM conversion. We’re going to use the USB-6009 to generate a 0-5V analog voltage that the robot controller can read and convert the analog voltage to a servo command. It’s going to possibly introduce a 26mS delay because of the internal timed loop in the robot controller, but I think we’ll need to take this into account in the real system anyway.

My main reason for this approach is that we don’t want to add any extra external circuitry (555 timer or analog-to-PWM converter) that could introduce additional errors to the system. We’re trying to mimic what is going to be present in the final system. With all that said I will still definitely keep the Jameco part in mind if we start running into problems with the robot controller.

I’m still hoping I’ve messed something up in the LabView software and we can actually get a much faster timed loop. Since we’re operating at the mercy of the internal timer on the PC (and the non-real-time Windows operating system) I don’t think I’ll get much better than a 1mS loop. As a test I had one of the digital outputs toggle every time it entered the 1mS loop. The signal clearly had a large amount of cycle-to-cycle jitter when I viewed it on an oscilloscope.

The USB-6009 and LabView definitely have their places where they’re extremely versatile as a learning tool but I don’t think directly controlling a servo is one of them. If anybody has gotten this to work I would be very intersted in seeing how they did it.

Thanks again!

LabVIEW running under Windows definitely cannot be relied upon to produce the timing necessary to create 17ms period PWM signals with on-time variable between 1 and 2ms. BUT… If you’re using a data acquisition module with a “full” timer/counter module (ie not the simple event counter that exists in the USB-6008/9 but a full-blown counter as in most PCI-based cards from NI), it’s very easy to generate PWM signals with hardware-based timing and microsecond precision and accuracy. Because most USB-based DAQ modules are lower-cost systems, they tend to have limited counter capabilities.

There are also LabVIEW Real-Time variants that can produce the necessary timing but that’s a big step up in cost and complexity.