Controlling the Parrot AR Drone with the Myo armband in Node.js

myo-drone-nodjs-tutorial

Following the last tutorial I wrote on how to control the Sphero with the Myo armband, here is another one on how to control the Parrot AR Drone with the Myo using Node.js.

If you want to follow along, you can find the repo on my github.

To begin with, we need to setup the server configuration. After requiring the necessary modules, here is what we need to write:

var env = process.env.NODE_ENV || 'development';
if('development' == env){
  app.set('port', process.env.PORT || 3000);
  app.use(express.static(__dirname + '/public'));
  app.use("/node_modules", express.static(path.join(__dirname, 'node_modules')))
}

server = require('http').createServer(app);

var bayeux = new faye.NodeAdapter({
    mount: '/faye',
    timeout: 50
  });

  bayeux.attach(server);

  client = new faye.Client("http://localhost:" + (app.get("port")) + "/faye", {});

  client.subscribe("/drone/move", function (d) {
    console.log(d);
    console.log("drone move?")
    return drone[d.action](d.speed);
  });

  client.subscribe("/drone/drone", function (d) {
    console.log(d);
    console.log("drone stuff")
      return drone[d.action]();
  });

  server.listen(app.get('port'), function () {
    console.log("Express server listening on port " + app.get("port"));
  })

We use express to set up the server and Faye & Bayeux for the communications between the Drone and your app.

We also use the module ‘dronestream’ to be able to stream video from the drone to the browser that is listening on port 3001.

The rest of the code deals with the commands sent from the Myo to the drone. First of all, we need to create an instance of the Myo and then define some commands.

myo = Myo.create();

myo.unlock();

myo.on('fingers_spread', function(){
    takeoff();
});

myo.on('wave_in', function(){
    goLeft();
})

var takeoff = function () {
    flying = true;
    return faye.publish("/drone/drone", {
      action: 'takeoff'
    });
};

var goLeft = function(){
    stopped = false;
    setTimeout(function (){
      return faye.publish("/drone/move", {
        action: 'left'
        // speed: adjustXspeed
      })
    }, timeout);
  };

Once the instance of the Myo is created, it can detect certain types of movements and run functions accordingly.

The ‘myo.unlock()’ command should allow the Myo to be unlocked while you use the app. However, I noticed I still needed to execute the unlock gesture ‘double tap’ between each command… Then the ‘faye.publish’ allows to send the commands and make the drone move. You can adjust the action and speed as you like.

This is just a snippet so once again, if you wanna have a look at the rest of the code or if you want to play around with it, everything is available on my Github šŸ™‚

Hope it helps and enjoy!

Video: Teenage NASA Employee Creates Mind-Control Bionic Arm

This is just amazing… Definitely worth watching!

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!

Wireless Brain-Computer Interface

BCI

I am fascinated about brain-computer interfaces and all the research around using computers to try to recreate some brain functionalities.

In the United States, a team at the Brown University and BlackRock Microsystems Ā have been working on a new interface that would work wirelessly and created a device that could fit in the palm of your hand…

This device could help paralyzed people take control of devices using their own thoughts without using long wires to connect their brain to signal processors.

You can learn more about this by reading the article by the MIT Technology Review here.

Controlling the Sphero using the Leap Motion in Cylon.js

cylonjs-sphero-leap-motion

In my personal time, I love to play around with hardware and robots.

IĀ started inĀ Node.js but recently I discovered Cylon.js and after a quick play around with it, I found it pretty awesome and decided to rewrite my projects using this framework.

As a starting point, I decided to rewrite the project to control the Sphero with the Leap Motion.

You can find the original repo here, but here are a few code snippets:

Screen Shot 2015-01-10 at 3.02.47 pm

Screen Shot 2015-01-10 at 3.04.09 pm

The way it works is pretty straight forward. The Sphero connects via bluetooth and the Leap Motion needs to be plugged in your computer. Once the Sphero is detected, the hand is tracked by the Leap Motion and the direction will be applied to the Sphero.

Feel free to have a better look at the code on Github.

Now, let’s move on to Cylon.js. The first thing I noticed about this framework is the short amount of code necessary to get to the same result. I managed to do pretty much the exact same thing in 68 lines of code!

I guess what makes it easier is that Cylon already has some modules you can install to program for certain devices, like the ones below:

cylon-devices

To start using Cylon, you need to require it and specify which devices you are working with.

```
var Cylon = require('cylon');

Cylon.robot({
  connections: {
    leapmotion: {adaptor: 'leapmotion'},
    sphero: {adaptor: 'sphero', port: '/dev/rfcomm0'}
  },

  devices: {
    leapmotion: {driver: 'leapmotion', connection: 'leapmotion'},
    sphero: {driver: 'sphero', connection: 'sphero'}
  },

  work: function(f){
  }
}).start();
 ``` 

At the moment, this code is not really doing anything but you can see how to specify which devices you are going to use.

You have to specify a port for the Sphero because it connects to your computer via Bluetooth. To find the port for your own Sphero, run ‘ls /dev/tty.Sphero*’ in your console and replace the port in this code with the result you get.

The rest of the code goes inside the ‘work’ function as below:

```
work: function(my){
  my.leapmotion.on('frame', function(frame){
   if(frame.valid && frame.gestures.length > 0{
     my.sphero.roll(70,0,1);
   }
  }
}

 ``` 

The code above makes the Sphero go forward if the Leap Motion detects any kind of gesture.

For the full code, have a look atĀ my github repo.

I’ll probably write another tutorial soon once I have a chance to rewrite another project but in the meantime let me know if you have any question!

‘Snake Monster’: A Spiderlike Robot Responding To Stimuli In Its Environment

snakebot

I found spiderlike robots fascinating. So fascinating that I am considering building my own. The way they mimic real movements is really impressive and complex to execute.

The way each ‘leg’ moves has to be done considering the position of the other ones. The balance has to be calculated so the robot can actually walk.

Besides this, more and more robots are able to adapt to their environment and any obstacle that may come in front of them.

One example is the ‘Snake Monster’, a robot developed by the Biorobotics Lab at the Carnegie Mellon University, using 6 snakelike legs.

This robot funded by DARPA, is able to respond to different obstacles like being kicked, or having to walk over a bunch of objects placed on the floor.

Watch the video below to see the robot in action:

At the moment, this kind of robots are more experimental or at a prototype stage but I can’t wait to see them being developed to help rescue victims of earthquakes for instance.

A tradition of failing live demos

wwcsyd_charliegerard

Last night I presented at the Women Who Code meetup in Sydney one of the project I have been working on on my personal time involving a Sphero robotic ball, a Parrot AR Drone and the Myo armband.

As this wasn’t my first talk, I learnt to double check that everything was working before even going to the meetup. I was pretty confident this time because I knew all my code was still working. After talking quickly about how I managed to connect all the devices together and control the Sphero and Drone using the Myo armband, I moved on to the live demo, and.. of course… it failed.

I wanted to start by showing the Sphero and for some reason, this one did not want to connect to my computer. It sometimes takes a few seconds because it connects via bluetooth, but this time, it just didn’t seem to be working fast enough. As I had just 5min to do my presentation, I just gave up and moved on to showing the drone. This one worked really well and I was able to show how I applied some specific gestures to some drone commands. I had to disable the actual directions because we were indoors and I did not want any accident to happen but it was still taking off when I was executing the “fingers spread” movement, and landing when I was doing the “fist”.

I still need to work on the code to make sure the directions are working fine and maybe make it do some more fancy stuff but for now I’m pretty happy it’s working.

I will demo this project again in January at the SydJS meetup and hopefully the demo gods will be fully with me this time.