Control the Parrot ARDrone with the Leap Motion in Cylon.js

cylon-drone-leapmotion

Following my tutorial on controlling the Sphero using the Leap Motion, I thought I would keep on converting my Node.js projects to Cylon.js and work on controlling the Drone with the Leap Motion.

If you’ve had a look at my last tutorial, you probably noticed that using Cylon.js makes it really easy to program for hardware and connect multiple devices together.

Below is the usual setup of any Cylon project:


var Cylon = require('cylon');

Cylon.robot({
  connections:{
    leapmotion: {adaptor: 'leapmotion'},
    ardrone: {adaptor: 'ardrone', port: '192.168.1.1'}
  },

  devices: {
    leapmotion: {driver: 'leapmotion', connection: 'leapmotion'},
    drone: {driver: 'ardrone', connection: 'ardrone'}
  },
 

As you can see, you simply need to specify which devices you are using, the more interesting bit comes in the rest of the code…

work: function(my){
   my.leapmotion.on('hand', function(hand){
     my.drone.takeoff();
     after((5).seconds(), function(){
       my.drone.land();
     })
   })
 }
}).start();

This code only makes the Drone take off when the Leap Motion senses a hand over it and land after 5 seconds (just in case it decides to go crazy…).

Then, if you want to make it do more interesting things, you will have to play around with what the Leap Motion has to offer; different types of gestures, distance, hands, fingers, etc… The Drone actions themselves are pretty straightforward:

  • my.drone.up();
  • my.drone.down();
  • my.drone.forward();
  • my.drone.back();
  • my.drone.left();
  • my.drone.right();

You can also make the drone rotate clockwise or counterclockwise but what I found the most awesome thing is that the cylon-ardrone module makes the ‘flip’ movement really easy to execute. On a ‘keyTap’ for example, your drone could do a backflip!!

The code for that would look like this:

 work: function(my){
   my.leapmotion.on('gesture', function(gesture){
     if(gesture){
       my.drone.takeoff();
       if(gesture.type === 'keyTap'){
         my.drone.backFlip();
         after((6).seconds(), function(){
          my.drone.land();
         }
       }
     } else {
       my.drone.stop();
     };
   };
 }
}).start();

If you wanna see the difference with Node.js, you can find my original Github repo here, otherwise here is the repo with more commands!

If you have any question, don’t hesitate!

Published by

Charlie Gerard

Software Developer @ThoughtWorks, I am passionate about programming, Generative Art, Robotics, the Internet of Things and anything related to creative innovations.

4 thoughts on “Control the Parrot ARDrone with the Leap Motion in Cylon.js”

  1. Hey!

    I’m not sure what you mean by “what do I need” but if you wanna recreate this project, you’ll need a Parrot AR Drone and a Leap Motion for the hardware part and Node.js + Cylon.js installed on your computer for the software part 🙂

    Let me know if you have any other question!

    Like

  2. Hey Charlie , thanks for all the information to do this project, only one question the code only works with the AR Drone 2.0? I want to buy a drone, and I would to start with the AR Drone 1.0 do you think they can control with the Leap Motion ?
    Thanks and greetings from Mx .

    Like

  3. Hi!

    I’m pretty sure the 1.0 can be controlled by the Leap Motion using the same code 🙂

    Let me know if you run into any issues!

    Like

Leave a comment