Using servo.h in a quadrotor?

Hello, I’m involved in a project using PID control to maintain horizontal stability in a quadrotor hovercraft. My group is juggling two methods of doing so.

The first method involves using just the timers and the Output Compare Registers to generate the PWM signals to drive the speed controllers and motors.

The second method involves using Servo.h and declaring four servo objects, then assigning the pwm speeds to those motors such that:

#include <Servo.h>

//Declaring servo objects
servo motor1, motor2, motor3, motor4;

void setup(){
/*STUFF HERE*/
}

void loop(){
unsigned int speed[4];
/*Speed calculations go here*/
speed1 = /*something*/;
speed2 = /*something*/;
speed3 = /*something*/;
speed4 = /*something*/;

//PWM signals generated here
motor1.write(speed1);
motor2.write(speed2);
motor3.write(speed3);
motor4.write(speed4);
}

My concern is that, if this second method is chosen, then the motors will be driven one at a time, which is less efficient than the first method and may even contribute to instability. Are my concerns valid?

I don't think the calls to servo.write() are slow enough to bother stability.

You can get better control resolution with servo.writeMicroseconds(). It take a pulse time in microseconds, roughly 1000 to 2000 but the usable range will depend on the ESC.

Thank you, I wasn't quite sure if they'd slow it down or not, but being that this is an important project, I just wanted to be sure.

Your response is greatly appreciated!

servo.write doesn't block, the servo pulses are handled by interrupts. You might want to tinker with the library to run the interrupt routine more often though - perhaps someone's already done this. Quadrotor feedback cycles are 100Hz or so, may be faster than the Servo library...

I’m also trying to keep my quadcopter stable. Direction is easy with a compass. Altitude with pressure sensor. How are you keeping it level?

.. I think it depends on the duration of the calculation within speed1 = /something/; speed2 = /something/; speed3 = /something/; speed4 = /something/;

If all "something" calcs are of the same duration, then all the servos are handled equally fast. No idea what happens with stability if the speed2 will for example be 5xlonger than the others, though..

Guys

The servos are pulsed in sequence about 50 times per second, servo signals are between 1 and 2 milli seconds long so cannot be five times longer - only twice as long and even then not long enough to amke a difference.

I have a simple solution in mind that will bring the refresh rate up to 100 times a second for four servos, I have heard in the past that this can help with quadcopters. I will try my solution and get back to you.

Do you guys all use particular pins for your servos or do you need to be able to choose, if you choose, what are the most common choices ? I.e. Do you need to keep analog pins free, SPI Pins, etc etc ?

Duane B