Sunday, June 16, 2013

Getting to know the Parrot AR Drone 2.0

This summer, I am doing my final independent study project at RIT.  The project is to design a control mechanism for a quadcopter that can find a fire and track its movement.  This would be of use in a forest fire situation, where the quadcopter could track the fire as it moves, allowing the authorities to easily follow its progress via GPS.  I am using the Parrot AR Drone 2.0 as my vehicle because of its simplicity, great price, and awesome features.

The AR Drone includes:
- 2 HD Cameras that can be streamed back to a home computer
- Onboard 1 GHz Linux board
- Altitude sensors
- Full IMU (Inertial Measurement Unit)
- Protective foam padding (for when I inevitably crash it into something)

The drone comes ready to fly with IOS and Android apps that are available.  Right off the bat, I was able to record some video directly from the drone:


The other reason I got this drone was for the Node.js implementation.  Node.js is a javascript platform for building network applications that is getting really popular because of its simplicity.  There are events called Nodecopter events that program these quadcopters using using the simple Node framework.  I am using this framework for my project, along with OpenCV (the definitive computer vision library).  So, I made a quick video of a script I wrote in Node.js to control the drone with the arrow keys on my computer.  Here is the video and the code below.


This code simply allows me to drive the Parrot AR Drone
var keypress = require('keypress');
var stdin = process.stdin;
var arDrone = require('ar-drone');
var client  = arDrone.createClient();
var inair = false;
client.config('general:navdata_demo', 'TRUE');
client.disableEmergency();
keypress(stdin);
stdin.on('keypress', function (ch, key){
    console.log('Got keypress:',key.name);
    if (key && key.ctrl && key.name == "c" || key.name == "q"){
        process.exit();
    }
    else if (key && key.name == "space" && inair == false){
        stdin.pause();
        console.log('Takeoff');
        client.takeoff();
        inair = true;
        stdin.resume();
    }
    else if (key && key.name == "space" && inair == true){
        stdin.pause();
        console.log('Landing...');
        client.stop();
        client.land();
        inair = false;
        stdin.resume();
    }
    else if (inair == true){
        if (key && key.name == "up"){
            stdin.pause();
            client.front(0.25);
            client.after(10,function(){
                client.stop();
                stdin.resume();
            });
        }
        else if (key && key.name == "down"){
            stdin.pause();
            client.back(0.25);
            client.after(10,function(){
                client.stop();
                stdin.resume();
            });
        }
        else if (key && key.name == "left"){
            stdin.pause();
            client.counterClockwise(0.35);
            client.after(10,function(){
                client.stop();
                stdin.resume();
            });
        }
        else if(key && key.name == "right"){
            stdin.pause();
            client.clockwise(0.35);
            client.after(10,function(){
                client.stop();
                stdin.resume();
            });
        }
        else if(key && key.name == "s"){
            stdin.pause();
            client.stop();
            client.after(50, function(){
                stdin.resume();
            });
        }
    }
});
process.on('exit', function(){
    console.log('Exiting...');
})
stdin.setRawMode(true);
stdin.resume();

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Working with Google's Cartographer SLAM Package

At my current position, at Canvas Construction, I have worked with a number of SLAM and localization packages. In the past few years, my wor...