gandhimonik / DroneJS

A Node.js based library for controlling a Parrot minidrone. This library also provides the feature to take pictures from the drone, download them all at a time and delete them whenever required.
Apache License 2.0
20 stars 5 forks source link
bluetooth bluetooth-low-energy noble nodejs parrot parrot-mini-drone parrot-rolling-spider

DroneJS

A Node.js based library for controlling a Parrot minidrone. The library also provides the feature to take pictures from the drone, download them all at a time and delete them whenever required. The library follows Bluetooth LE networking protocol to connect to the drone.

Drones Supported

Prerequisites

Install


npm install dronejs

Usage

Connect

To connect to drone, you need to instantiate the MiniDrone class and then call its connect method.

var minidrone = require('dronejs');

minidrone.connect('RS_')
        .then()
        .catch((e) => {
            console.log('Error occurred: ' + e);
        });

Setup Navdata Stream

To listen to the navigation data from the drone, you need to call the getNavDataStream function and then subscribe to the object returned from it.

var minidrone = require('dronejs');

var navDataStream = minidrone.getNavDataStream();
navDataStream.subscribe((data) => {
        console.log(data);
    },
    err => debug(err),
    () => debug('complete'));

minidrone.connect('RS_')
    .then(() => minidrone.checkAllStates())
    .then()
    .catch((e) => {
        console.log('Error occurred: ' + e);
    });

Basic Maneuvers

var minidrone = require('dronejs');

var navDataStream = minidrone.getNavDataStream();
navDataStream.subscribe((data) => {
        console.log(data);
    },
    err => debug(err),
    () => debug('complete'));

minidrone.connect('RS_')
    .then(() => minidrone.flatTrim())
    .then(() => minidrone.takeOff())
    .then(() => minidrone.flatTrim())
    .then(() => minidrone.forward(50, 5))
    .then(() => minidrone.flatTrim())
    .then(() => minidrone.land())
    .then()
    .catch((e) => {
        console.log('Error occurred: ' + e);
    });

Take Picture

var minidrone = require('dronejs');

var navDataStream = minidrone.getNavDataStream();
navDataStream.subscribe((data) => {
        console.log(data);
    },
    err => debug(err),
    () => debug('complete'));

minidrone.connect('RS_')
    .then(() => minidrone.flatTrim())
    .then(() => minidrone.takeOff())
    .then(() => minidrone.flatTrim())
    .then(() => minidrone.takePicture())
    .then(() => minidrone.flatTrim())
    .then(() => minidrone.land())
    .then()
    .catch((e) => {
        console.log('Error occurred: ' + e);
    });

Download Pictures

var minidrone = require('dronejs');

minidrone.connect('RS_')
    .then(() => minidrone.listAllPictures())
    .then(pictures => minidrone.downloadPicture(pictures[0], 'output'))
    .then(response => {
        if (response === 'success') {
            console.log('picture downloaded successfully...');
        }
    })
    .catch((e) => {
        console.log('Error occurred: ' + e);
    });

Delete Picture

var minidrone = require('dronejs');

minidrone.connect('RS_')
    .then(() => minidrone.listAllPictures())
    .then(pictures => minidrone.deletePicture(pictures[0]))
    .then(response => {
        if (response === 'success') {
            console.log('picture deleted successfully...');
        }
    })
    .catch((e) => {
        console.log('Error occurred: ' + e);
    });

API