Electronic speed control (most commonly known as ESC) are nasty beasts: not from the controlling software point of view but for the way they need to be powered up, and because they need to be calibrated.
Especially the calibration is important because otherwise the ESC doesn’t know which are the limits of the transmitter, and it cannot control precisely the speed of the motor.
Before putting a ESC in any complex Arduino project, it is better to get used to how a ESC works using a very simple sketch.
But before seeing the code, let’s see how to wire it up, because care must be taken otherwise nothing will work.
Wiring up the circuit and powering the ESC
Usually ESCs need a voltage higher than the one provided by the Arduino from his 5V pin: typically they need 2 LiPo cells (around 8V). To achieve that all the circuit must be powered from an external power supply connected directly to the ESC and not via the Arduino, which will be powered by the BEC circuit of the ESC. To make that happen it’s enough to connect the red and black of the control connector to the 5V and GDN of the Arduino board.
The rest of the circuit is pretty easy: from pin 9 of the Arduino we have the signal for the ESC, and into pin 0, the voltage reading from the potentiometer comes in.
Let’s now see the code.
Arduino code
A ESC is made to receive inputs from a R/C transmitter, so it works as a servo: to control it you can use the Arduino Servo Library, so the test code is based on the servo library basic example published on the Arduino site.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| #include <Servo.h> Servo esc; int throttlePin = 0; void setup() { esc.attach(9); } void loop() { int throttle = analogRead(throttlePin); throttle = map(throttle, 0, 1023, 0, 179); esc.write(throttle); } |
It just takes the reading of the “throttle”, maps it from 0-1023 to 0-179 (analog reading to servo “degrees”) and then sends it to the ESC via the Servo library. Even in its extreme simplicity this sketch it very useful when you want to calibrate a new ESC to work with the Servo library of Arduino.
Calibration
Now that everything is setup, chances are that you motor might not rotate, or might rotate only forward, or might rotate only to 80% of the throttle (forward and reverse) and then stop: all these are symptoms of lack of calibration, or a calibration done with a different range of PWM signals.
More or less all ESCs have a similar calibration procedure:
- Power up the ESC while the having maximum forward throttle applied
- You’ll hear a tone and some beeps and after a while (usually 2 seconds) you’ll hear a confirmation tone and the led will blink a few times with a different color: this indicates that the ESC has measured the wavelenght of max throttle.
- At this point apply zero throttle (in a fwd/reverse ESC this means full throttle reverse), wait again few seconds for the tones and led to blink: full reverse measured.
- Then move to central (only for fwd/reverse ESCs) and wait again for the tone and blinks.
- Have fun with the motors
Another possibility is that even after that procedure, the motor will not turn immediately in reverse, or will only go 50% of forward speed: that’s because ESCs are programmable, and you can change many of their behaviors via either a programming card or via, again as with the calibration, hearing and decoding beeps and blinks.
0 comments:
Post a Comment