Giando
Published

Control a Parrot AR Drone with Linino

Use a real joystick to control a Parrot AR Drone.

Full instructions provided8,133
Control a Parrot AR Drone with Linino

Things used in this project

Hardware components

AR.Drone
Parrot AR.Drone
×1
Arduino Yun
Arduino Yun
×1
Sparkfun Joystick Shield
×1

Story

Read more

Code

code.txt

JSON
{
  "name": "hello-world",
  "version": "0.0.1",
  "description": "Ideino example project",
  "author": {
  "name": "Ideino Team"
  }
}

code.txt

JSON
{
  "name": "Drone",
  "version": "0.0.1",
  "description": "Controlling Parrot AR.Drone with Linino on Arduino Yun and Joystick Shield",
  "author": {
    "name": "John Doe"
  },
  "dependencies": {
    "ar-drone": "*"
  }
}

code.txt

JavaScript
var btnUP = { pin: board.pin.digital.D4, value : 0 },
    btnDOWN = { pin: board.pin.digital.D5, value : 0 },
    btnCTNCLKWISE = { pin: board.pin.digital.D3, value : 0 },
    btnCLKWISE = { pin: board.pin.digital.D6, value : 0 },
    btnFLY = { pin: board.pin.digital.D2, value : 0 },
    btnLEFTRIGHT = { pin: board.pin.analog.A0, value : 0 },
    btnBACKFRONT = { pin: board.pin.analog.A1, value : 0 },
    led = { pin: board.pin.digital.D13, value : 0 };

code.txt

JavaScript
board.connect( function(){

 //Setting the pins...
 board.pinMode(btnUP.pin, board.MODES.INPUT);
 board.pinMode(btnDOWN.pin, board.MODES.INPUT);
 board.pinMode(btnCTNCLKWISE.pin, board.MODES.INPUT);
 board.pinMode(btnCLKWISE.pin, board.MODES.INPUT);
 board.pinMode(btnFLY.pin, board.MODES.INPUT);
 board.pinMode(led.pin, board.MODES.OUTPUT);

    //The following analogRead functions have callback that trigger when the joystick  is moved
    //LEFT and RIGHT
    board.analogRead(btnLEFTRIGHT.pin,function(data){
       LRValue = data.value / 1000;

       if(LRValue >= S1 && LRValue <= S2 ){
           drone.stop();
           board.digitalWrite(led.pin,board.LOW);
       }
       else{
           if(LRValue < S1 )
               drone.left( (S1 - LRValue).toFixed(2));
           else
               drone.right((LRValue - S2).toFixed(2));

            board.digitalWrite(led.pin,board.HIGH);      
       }
    });

    //BACK and FRONT
    board.analogRead(btnBACKFRONT.pin,function(data){
       BFValue = data.value / 1000;

       if(BFValue >= S1 && BFValue <= S2 ){
           drone.stop();
           board.digitalWrite(led.pin,board.LOW);
       }
       else{
           if(BFValue < S1 )
               drone.back((S1 - BFValue).toFixed(2));
           else
               drone.front((BFValue - S2).toFixed(2));

            board.digitalWrite(led.pin,board.HIGH);
       }
    });


    //The following digitalRead functions are associated with the shield Buttons switch.        
    //TAKE OFF and LANDING
    board.digitalRead(btnFLY.pin,function(data){
        try{
            if(data.value == 0 ){
                board.digitalWrite(led.pin,board.HIGH);

                //console.log('cmd');
                if(flying == false){
                    console.log("go take off");
                    drone.takeoff();

                }
                else{
                    console.log("go landing");
                    drone.stop();    
                    drone.land(); 
                }
                flying = !flying;
            }
            else
                board.digitalWrite(led.pin,board.LOW);
        }
        catch(err){
            console.log(err.message);
        }
    });

    //CLOCKWISE
    board.digitalRead(btnCLKWISE.pin,function(data){
        if(data.value == 0){
            board.digitalWrite(led.pin,board.HIGH);
            drone.clockwise(0.3);            
        }
        else{
            drone.stop();
            board.digitalWrite(led.pin,board.LOW);
        }
    });

    //COUNTER CLOCKWISE
    board.digitalRead(btnCTNCLKWISE.pin,function(data){
         if(data.value == 0){
             board.digitalWrite(led.pin,board.HIGH);
            drone.counterClockwise(0.3);
         }
        else{
            board.digitalWrite(led.pin,board.LOW);
            drone.stop();
        }         
    });

    //UP
    board.digitalRead(btnUP.pin,function(data){
        if(data.value == 0){
            board.digitalWrite(led.pin,board.HIGH);
            drone.up(0.3);
        }
        else{
            board.digitalWrite(led.pin,board.LOW);
            drone.stop();
        }        
    });

    //DOWN
    board.digitalRead(btnDOWN.pin,function(data){
         if(data.value == 0){
             board.digitalWrite(led.pin,board.HIGH);
            drone.down(0.3);
         }
        else{
            board.digitalWrite(led.pin,board.LOW);
            drone.stop();
        }         
    });

});

Github

https://github.com/felixge/node-ar-drone

Credits

Giando

Giando

15 projects • 13 followers

Comments