Want to intuitively fly your Parrot AR.Drone 2.0 with gestures and arm movement using your Myo armband? All you need is a Windows PC, AutoFlight, and this connector. Welcome to this week's #MyoCraft.

The script is a bit long, so you can grab the code this post is based on here, in case the Myo Market version gets updated in the future.

While we're waiting for our official Parrot AR.Drone 2.0 iOS app to be published, I thought I'd whip something together to let you control your drone via your PC. I found a Windows application called AutoFlight that seemed to work well enough, and set about writing a Myo Script that took advantage of the built-in keyboard shortcuts.

Autoflight

This script is basically an expanded and more generic version of the Race The Sun connector we built in our Orientation and Gestures Myo Script tutorial. The key is the new fly function that replaces the three flyLeft, flyRight and flyNeutral commands:

  
 




 function fly(lowKey, highKey, delta, deadZone, currentDirection)  
        oldDirection = currentDirection;
        if (delta < -deadZone) then
            currentDirection = LOW_DIRECTION
        elseif (delta > deadZone) then
            currentDirection = HIGH_DIRECTION
        else
            currentDirection = NEUTRAL_DIRECTION
        end

        if (oldDirection ~= currentDirection) then
            if (currentDirection == HIGH_DIRECTION) then
                myo.keyboard(highKey, "down")
                myo.debug(highKey)
            elseif (currentDirection == LOW_DIRECTION) then
                myo.keyboard(lowKey, "down")
                myo.debug(lowKey)
            end

            if (oldDirection > NEUTRAL_DIRECTION) then
                myo.keyboard(highKey, "up")
            elseif (oldDirection < NEUTRAL_DIRECTION) then
                myo.keyboard(lowKey, "up")
            end
        end

        return currentDirection;
    end 

It gives you a single function that will let you fly up or down along an axis, given the hotkeys for that axis, the current value of the Myo axis you want to control it with, and the deadzone in which no controls should be send. To ensure buttons are released at the right time, it also takes (and returns) the current direction.

We've used this to let us have the same code control the forward/backward motion, the left/right motion, and the rotation of the drone.

  
 



 
function onPeriodic()  
        if (centreYaw == 0) then
            return
        end

        local currentYaw = myo.getYaw()
        local currentPitch = myo.getPitch()
        local currentRoll = myo.getRoll()

        local deltaYaw = calculateDeltaRadians(currentYaw, centreYaw)
        local deltaPitch = calculateDeltaRadians(currentPitch, centrePitch);
        deltaRoll = calculateDeltaRadians(currentRoll, centreRoll);

        forwardBackwardDirection = fly(ForwardBackward.lowKey, ForwardBackward.highKey, deltaPitch, PITCH_DEADZONE, forwardBackwardDirection)

        leftRightDirection = fly(LeftRight.lowKey, LeftRight.highKey, deltaYaw, YAW_DEADZONE, leftRightDirection)
        if rotating then
            rotateDirection = fly(Rotate.lowKey, Rotate.highKey, deltaRoll, ROLL_DEADZONE, rotateDirection)
        end
    end

In my testing it was too difficult to yaw your arm without accidentally rolling it a bit as well in the midst of flight, so you can only rotate while holding fist. Perhaps a better pilot could manage, however.

Drone Double tap does takeoff and landing, and fingers spread stops all motion and lets you hover. For now, I've left out flip and the emergency button. I think we could probably come up with a good motion gesture for both, but we'll leave that for another time.

Enjoy your drone flying! If you come up with a better control scheme, or use this scheme to control something else (like another kind of drone perhaps?) let met know on Twitter (@thalmicdev) or at MyoCraft@thalmic.com.

Otherwise, see you next week!

Newsletter

Enter your email address and get all latest content delivered to your inbox every now and then.