Arduino & ArduMotion and ESC Speed Controllers & Servos

Arduino compatible ESC Motor ControllerBasically ESC (Electronic Speed Controllers) are designed to work with remote controllers using PPM protocol and are similar to how you would control a Servo.

PPM protocol is a “PWM” wave (square wave signal for certain durations consisting of high and low (5v and 0v)) which for typical ESC’s operates at 50hz frequency. By changing the duty cycle of this Pwm wave, different speeds and directions are achieved.
The PWM signal read by the ESC is the same type as a servo signal, meaning the Servo library from Adruino can be used to control the ESC as well as any Servo so long as you have a power supply that is big enough to provide the surge current required by servos.
 
The ESC sets the speed of the motor depending on the ratio of high to low signals. Calibration involves programming the ESC to understand the PWM waves corresponding to the stop and maximum speeds of the motor.

Sample PWM Signals. Borrowed from http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

The default signal range for most servo motors and ESCs is a high signal width between 1000 and 2000 microseconds over a repetition period of 20 milliseconds (a 50hz PWM signal).

ArduMotion WiFi ESC / Servo Shield

ArduMotion (Arduino comptaible board) can generate servo signals with the builtin Servo function. The “Servo” function sets the angle of servo with values 0 to 180.

This angle information interpreted in ESC as: 

Degrees          0   …………90………….   180
Speed       -%100………..%0…………+%100 
 
The – and + shows the direction of motor and 0% (90) is the neutral position where the motor is turned off.
 
void ServoSetup()
{
// Please ensure the servo's dont require more current than the regulator is able to
//supply. otherwise, the board will continuously reset and start over
// Servo and Analog Sensor input connector servo 1 is the leftmost toward the right
// edge of the board). 5VDC for + pin.
// Analog input is the leftmost 3-pin connector when looking from the topside.
// A 1 2 3 4 (yellow, orange or white = Signal)
// + + + + + (+=Orange or Red = Positive)
// - - - - - (-=Brown or Black = Ground)

pinMode(PWM1, OUTPUT); // digitalWrite(PWM1, LOW); // DONOT EVER WRITE LOW TO A
// ESC / SERVO PORT as it will short out and reset the board!!!
servo1.attach(PWM1); // attaches the servo on pin 9 to the servo object
servo1.write(90); // tell servo to go to resting position in case of an ESC controller,
// 90 is the neutral zero speed position so it is safe for either an
// ESC or a Servo hookup
delay(500); // give enough time for the first servo to stabilize

pinMode(PWM2, OUTPUT);
servo2.attach(PWM2); // attaches the servo on pin 3 to the servo object
servo2.write(90);
delay(500);

pinMode(PWM3, OUTPUT);
servo3.attach(PWM3); // attaches the servo on pin 5 to the servo object
servo3.write(90);
delay(500);

pinMode(PWM4, OUTPUT);
servo4.attach(PWM4); // attaches the servo on pin 6 to the servo object
servo4.write(90);
delay(500);
}

Lessons Learnt:
Board resets while using high powered Servos or trying to move multiple high powered servos at the same time is pretty common in electronic systems, especially when they're controlled by microprocessors: while the system is initializing itself, glitches can occur in parts of the system that aren't fully initialized.

Since ArduMotion (Arduino compatible) pins default to "input" on reset, you need to add some external logic that inhibits the servo signals unless a digital pin you choose as the "enable" is outputting an active low. Perhaps a buffer with tri-state outputs that are enabled by a logic 0 input. Make sure your code doesn't pull the enable low until after you're sure the servo outputs are stable. You'll also need to make sure you don't enable them in mid-pulse, or you'll get exactly the sort of glitch you're trying to avoid.

I was trying to control 3 mid-large servos at the same time in one of our projects and here is what i found: With the 3rd connected and all 3 servos trying to move, the ArduMotion board would reset. It would reset almost immediately after the servos started moving. I changed the code to only move 2 of the servos and things went back to working as expected. Every once in a while the board would reset. But adding the 3rd would cause a reset every time. About this time it dawned on me that I might be trying to draw too much power through the board.

So I disconnected the power and ground lines for the 3 servos and connected them to the +5v of an external power supply and ground wires of the power supply. I added a wire connecting the ArduMotion ground with the external 5vdc power supply ground and powered up the ArduMotion. All three servos started moved their control arms back and forth without any more resets of the board.

This entry was published on June 1, 2012 at 7:03 pm. It’s filed under ATMEL Based, Hardware, PWM and tagged , , , , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.

One thought on “Arduino & ArduMotion and ESC Speed Controllers & Servos

  1. Pingback: Technical Information | Arduino Yellowjacket Compatible WiFi Shield, GP-2106 GPS, TB6612FNG DC Motors, ESC, and UAV Drone & Rover Servo Controller for iPhone, iPad, Android or Windows Phone

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: