Blog

May
06
2015

Hello, Node Bebop Drone

by Ron Evans

We love drones, and we've had our brand new Parrot Bebop for a little while. However, we did not have any way to control Parrot's new "high-end" consumer drone using JavaScript.

Without further ado, introducing node-bebop, a node module to control the Parrot Bebop quadcopter.

There are already so many wonderful JavaScript code examples out there for the ARDrone, thanks to the fine efforts of the NodeCopter crew.

Our objective was to be able to use the Parrot Bebop with code compatible with NodeCopter. And we wanted to do this, despite the Bebop having an entirely new API, one which is incompatible with the ARDrone, despite both of them being WiFi devices.

So we created node-bebop using a very similar outward-facing API as that pioneered by the NodeCopter team, but calling the new Bebop API within our implementation.

Here is an example of using node-bebop:

var bebop = require('node-bebop');

var drone = bebop.createClient();

drone.connect(function() {
  drone.takeOff();

  setTimeout(function() {
    drone.land();
  }, 5000);
});

This code should look very familiar to any of the thousands of people who attended a NodeCopter event.

Most of the flight commands have already been implemented. In addition, node-bebop can receive basic navigation data, and streaming video data.

In parallel to all of our efforts, @voodootikigod aka Chris Williams has been rallying the forks of node-rolling-spider, a JavaScript module for Parrot's OTHER new drone, the $99 Rolling Spider, into a 1.0 release. The API of the node-rolling-spider project is also "NodeCopter-compatible", and has its own rapidly growing community. Much of their example code will likely work with node-bebop as well.

We have cylon-bebop too

We have also created cylon-bebop as a wrapper around node-bebop, so you can control the Bebop using Cylon.js if you so prefer.

Here is an example that uses cylon-bebop along with cylon-joystick, to control a Bebop using a Dualshock 3 controller:

var cylon = require("cylon");

cylon.robot({
  connections: {
    joystick: { adaptor: "joystick" },
    bebop:  { adaptor: 'bebop' }
  },
  devices: {
    controller: { driver: "dualshock-3", connection: "joystick" },
    drone:      { driver: "bebop", connection: "bebop" }
  },
  work: function() {
    var that = this,
        rightStick = { x: 0.0, y: 0.0 },
        leftStick = { x: 0.0, y: 0.0 };

    that.controller.on("square:press", function() {
      that.drone.takeOff();
    });

    that.controller.on("triangle:press", function() {
      that.drone.stop();
    });

    that.controller.on("x:press", function() {
      that.drone.land();
    });

    that.controller.on("right_x:move", function(data) {
      rightStick.x = data;
    });

    that.controller.on("right_y:move", function(data) {
      rightStick.y = data;
    });

    that.controller.on("left_x:move", function(data) {
      leftStick.x = data;
    });

    that.controller.on("left_y:move", function(data) {
      leftStick.y = data;
    });

    setInterval(function() {
      var pair = leftStick;

      if (pair.y < 0) {
        that.drone.forward(validatePitch(pair.y));
      } else if (pair.y > 0) {
        that.drone.backward(validatePitch(pair.y));
      }

      if (pair.x > 0) {
        that.drone.right(validatePitch(pair.x));
      } else if (pair.x < 0) {
        that.drone.left(validatePitch(pair.x));
      }
    }, 0);

    setInterval(function() {
      var pair = rightStick;

      if (pair.y < 0) {
        that.drone.up(validatePitch(pair.y));
      } else if (pair.y > 0) {
        that.drone.down(validatePitch(pair.y));
      }

      if (pair.x > 0) {
        that.drone.clockwise(validatePitch(pair.x));
      } else if (pair.x < 0) {
        that.drone.counterClockwise(validatePitch(pair.x));
      }
    }, 0);

    setInterval(function() {
      that.drone.stop();
    }, 10);
  }
}).start();

function validatePitch(data) {
  var value = Math.abs(data);
  if (value >= 0.1) {
    if (value <= 1.0) {
      return Math.round(value * 100);
    } else {
      return 100;
    }
  } else {
    return 0;
  }
}

Conclusion

The Parrot Bebop is a very cool new drone, and we're happy to offer up node-bebop and cylon-bebop so you can take flight using JavaScript at the controls.

Please follow us on Twitter at @CylonJS to receive updates as we continue to work on JavaScript-powered drones, robots, and connected devices.