I have a fun robot project pretty much wrapped. The last thing to do is work out this bug running multiple servos. I have six HiTec HS-311 servos powered externally. My circuit is definitely good. It runs perfectly from an Arduino Uno. When I run the exact same software on the Galileo Gen 2, the servos freak out. I've done a lot of research and looked through the forums. Here's what I've done so far:
- The first thing I did was go down to a single servo, powered by the Galileo. Still didn't work. Just jittered at 0°.
- I tried Mikal Hart's servo library. No dice. Didn't even jitter.
- I switched from write to writeMicroseconds. The HS-311 has a range of 900 - 2100μs. I have a degrees to μs mapper function. This made a single servo function mostly correctly; with some jitter.
- I powered the servo externally. No change (yay! power is fine).
- I changed the μs range in the Servo library to match my servos (900 - 2100). This got rid of the jitter for a single servo. I now have one servo, powered externally; working perfectly. Woohoo!
- I hooked up the other servos, but only operated one. The one still works great. So far, so good...
- I start operating two servos. They both move smoothly to 90°, jitter for awhile, and come back to 0°. A third servos twitches a little even though I'm not sending anything to it.
- I try it on the Arduino Uno...
- I copy my Servo library changes from Galileo Arduino 1.5.3 to Arduino 1.5.8.
- I run the exact same software on the Arduino Uno.
- The power settings have not changed on the power supply.
- All six servos work perfectly.
So I know my software is written correctly for Arduino. I know there are differences between the Servo libraries on each. I know I can make one servo work perfectly on the Galileo Gen 2. How do I operate multiple servos successfully? I don't mind treading into some advanced territory or straight wire operation, but I don't want to go down a path that won't work.
I've attached a video of the same software running on the Arduino Uno and the Galileo. I made little terminals to make it easy to plug the system into either board. In this case, I'm running a test loop which operates all the servos and LEDs every few seconds. The LEDs work the same on both. The first part of the video shows the robots running off the Arduino, with all their servos working in unison. After switching over to the Galileo, you'll see the servos sort of trying to work, but really just jittering and freaking out.
Here is the stripped down test code I'm using for just operating the servos. Upping to more than one causes problems.
#include <Servo.h> const int kNumServos = 1; Servo servo[ kNumServos ]; int pos = 0; void setup() { servo[ 0 ].attach( 3 ); //servo[ 1 ].attach( 5 ); //servo[ 2 ].attach( 9 ); } void loop() { for ( pos = 0; pos < 180; ++pos ) { for ( int i = 0; i < kNumServos; ++i ) { servo[ i ].writeMicroseconds( degreesToMicroseconds( pos ) ); } delay( 20 ); } for ( pos = 180; pos >= 0; --pos ) { for ( int i = 0; i < kNumServos; ++i ) { servo[ i ].writeMicroseconds( degreesToMicroseconds( pos ) ); } delay( 20 ); } } int degreesToMicroseconds( int deg ) { return (int)( ( (float)deg / 90.0f ) * ( 2100.0f - 900.0f ) ); }
Please help! We're done with this project except for this one bug. Hoping to run it before the weekend. They do really cool stuff when it all works.
Thanks in advance.