esc - dtex/johnny-five GitHub Wiki
The ESC
class constructs objects that represent a single ESC attached to the physical board. ESC
objects are similar to Servo
objects as they both use PWM pins to communicate with the physical ESC. Currently, this class assumes the ESC is pre-calibrated.
If you are interested in working with multiple ESCs, see the ESCs page.
-
pin A Number or String address for the ESC pin (PWM).
var esc = new five.ESC(9);
-
Options An object of property parameters.
Property Type Value/ Description Default Required pin Number, String Any PWM Pin. The address of the PWM pin the ESC is attached to yes range Array [ lower, upper ]
. The range of speed in percent.[0, 100]
no startAt Number Initial speed, 0-100% 0
no controller String DEFAULT, PCA9685. Controller interface type. "DEFAULT" no device String FORWARD, FORWARD_REVERSE. Device capability type. "FORWARD" no neutral Number Neutral point, 0-100. 0 no -
PCA9685 Options (
controller: "PCA9685"
)Property Type Value/Description Default Required address Number I2C device address. 0x40
no
Property Name | Description | Read Only |
---|---|---|
id |
A user definable id value. Defaults to a generated uid | No |
pin |
The pin address that the ESC is attached to | No |
range |
The range of speed as an array of fractional percent values. Defaults to [0, 100] | No |
value |
The value of the last/current speed. | Yes |
new five.ESC(9);
// Limited speed range to 0-80%
new five.ESC({
pin: 9,
range: [ 0, 80 ]
});
new five.ESC({
controller: "PCA9685",
pin: 1
});
new five.ESC({
pin: 9,
device: "FORWARD_REVERSE",
neutral: 50
});
Standard ESC
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var esc = new five.ESC(11);
// Set to top speed. (this can be physically dangerous, you've been warned.)
esc.max();
});
-
speed(value) Set the speed of the ESC, any fractional number value from 0...100 as a percentage value. If the specified speed is the same as the current speed, no commands are sent.
var esc = new five.ESC(11); // Set the motor's speed to 50% esc.speed(50);
-
min() Set ESC to minimum speed. Defaults to 0%, respects explicit range.
var esc = new five.ESC(11); esc.min();
Or
var esc = new five.ESC({ pin: 11, range: [ 10, 100 ] }); // Minimum speed at 10% esc.min();
-
max() Set ESC to maximum speed. Defaults to 100%, respects specified range.
var esc = new five.ESC(11); esc.max();
Or
var esc = new five.ESC({ pin: 11, range: [ 0, 80 ] }); // Max at 80% esc.max();
-
stop() Stop a moving esc.
var esc = new five.ESC(12); esc.stop();
This isn't a requirement, but if you experience issues with your ESCs, it might prove helpful
Load the following sketch onto your Arduino, via the Arduino IDE follow the instructions.
This requires that the ESC's power source is off or disconnected at the start of the calibration process. You will be prompted to turn on/reconnect the power during the process.
#include <Servo.h>
#define MAX_SIGNAL 2000
#define MIN_SIGNAL 700
#define MOTOR_PIN 12
Servo motor;
void setup() {
Serial.begin(9600);
Serial.println("Program begin...");
Serial.println("This program will calibrate the ESC.");
motor.attach(MOTOR_PIN);
Serial.println("Calibrating Maximum Signal");
Serial.println("Turn on power source, then wait 2 seconds and press any key + <enter>");
motor.writeMicroseconds(MAX_SIGNAL);
// Wait for input
while (!Serial.available());
Serial.read();
// Send min output
Serial.println("Calibrating Minimum Signal");
motor.writeMicroseconds(MIN_SIGNAL);
}
void loop() {
}