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 an AR.Drone with 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 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!

Want to see more Leap Motion drone mashups? Check out some experimental flying videos or reach for the skies with our blog’s #drone tag.

Image courtesy of Parrot.

A software developer and consultant at ThoughtWorks, Charlie is passionate about programming, generative art, robotics, the Internet of Things and anything related to creative innovations.

Twitter LinkedIn Google+