swarms
Version:
The ultimate node.js library for controlling Bitcraze Crazyflie 2.0 drones
51 lines • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("./commander");
const logging_1 = require("./logging");
const parameters_1 = require("./parameters");
const events_1 = require("events");
const path = require("path");
exports.defaultCrazyflieOptions = {
cacheDir: path.join(__dirname, '..', '..', 'cache')
};
class Crazyflie extends events_1.EventEmitter {
/**
* Class for controlling a Crazyflie
*/
constructor(radio) {
super();
this.radio = radio;
this.initialized = false;
this.options = exports.defaultCrazyflieOptions;
this.commander = new commander_1.Commander(this);
this.parameters = new parameters_1.Parameters(this);
this.logging = new logging_1.Logging(this);
// Forward all errors to the global Crazyflie 'error' event
this.parameters.on('error', (err) => {
this.emit('error', err);
});
this.logging.on('error', (err) => {
this.emit('error', err);
});
}
async init() {
if (this.initialized) {
return Promise.reject('Crazyflie already initialized!');
}
// Start interval to make sure Crazyflie maintains it's targetted roll, yaw, pitch, and thrust.
// It dies out after a few seconds otherwise.
this.commander.startSetpointInterval();
// Make absolutely sure that all values are initially set at 0 or else propellers won't move!
await this.commander.setpoint({
roll: 0,
yaw: 0,
pitch: 0,
thrust: 0
});
// Reset any previous logging
await this.logging.reset();
this.initialized = true;
}
}
exports.Crazyflie = Crazyflie;
//# sourceMappingURL=index.js.map