How do you guys move multiple servos at the same time?

How do you guys move multiple servos at the same time? i was doing some testing with a arduino mega using the code (below) and they are way out of sync… just wondering how you guys do it???

pst: I know it is because the current servo.h library takes 20ms to write to each servo, but still wondering =) also i know that it will be very unlikely for me to move 14 servos at the same time… But i even tried with 3 (which i may do) and they dont move at the same time)

Will the SSC-32 have the same problem?

#include <Servo.h> 

Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
Servo myservo8;
Servo myservo9;
Servo myservo10;
Servo myservo11;
Servo myservo12;
Servo myservo13;
Servo myservo14;

void setup()
{  
  myservo1.attach(14); 
  myservo2.attach(15);
  myservo3.attach(16);
  myservo4.attach(17);
  myservo5.attach(18);
  myservo6.attach(19);
  myservo7.attach(20);
  myservo8.attach(21);
  myservo9.attach(22);
  myservo10.attach(23);
  myservo11.attach(24);
  myservo12.attach(25);
  myservo13.attach(26);
  myservo14.attach(27);
}

void loop()
{
  myservo1.write(160);
  myservo2.write(160);
  myservo3.write(160);
  myservo4.write(160);
  myservo5.write(160);
  myservo6.write(160);
  myservo7.write(160);
  myservo8.write(160);
  myservo9.write(160);
  myservo10.write(160);
  myservo11.write(160);
  myservo12.write(160);
  myservo13.write(160);
  myservo14.write(160);
  delay(2500);                       
  myservo1.write(20);
  myservo2.write(20);
  myservo3.write(20);
  myservo4.write(20);
  myservo5.write(20);
  myservo6.write(20);
  myservo7.write(20);
  myservo8.write(20);
  myservo9.write(20);
  myservo10.write(20);
  myservo11.write(20);
  myservo12.write(20);
  myservo13.write(20);
  myservo14.write(20);
  delay(2500);
}

Again looking at the Servo code I do not see anything inherent that each write should take 20ms… All it does is to map the degrees into microseconds and then stuffs the value out into appropriate channel number for that servo. However since the actual servo code that generates the pulses runs off of the timers associated with 16 bit timers, it is very possible that your one write for one servo may not all start within the same 20ms servo cycle (that is you may find that your first N writes happen within one servo period and the next N start in the next period.

Also I assume you know that even after you tell the all the servos to move, the pulses for each cycle do not happen all at the same time, they are staggered in the servo period. That is each clock is responsible for a certain number of servos, it starts the first one it is responsible for, wait’s until it completes and then starts the next one…

One form or another of staggering is done by probably every servo controller, for a variety of reasons, including not hopefully having the current spikes all at the same time. This is true of the SSC-32 as well.

But, what the SSC-32 is really good at is to be able to tell all your 14 servos to go to new locations and have them all get to their new locations at the same time. We make use of this a lot for example with our hexapods, with their walking code. On Arduinos, I wrote my own version of this code, that I call ServoEx, which works pretty well, but using the SSC-32 has it’s advantages, as doing the code like I did on the Arduino is susceptible to having the servos jitter, when the pulses for a servo are not exactly always the same width. This is likely to happen anytime you do something else that causes the Arduino to either process other interrupts or if your code should disable interrupts. One culpret to this is if you use something like SoftwareSerial code. This code disables interrupts while it outputs each character. So during this time the code is outputting a character, the servo code will not be able to properly generate pulses.

Hope I answered your questions and sorry if my answer is somewhat convoluted.

Kurt

supermiguel - you can stagger your single writes into multiple smaller writes to achieve what you are trying to do. Of course total time to get to target location for all servos will be higher, not sure if that is a problem for you.