Intro: Fly a Mini-drone With Your Computer!
A few months ago, I watched a TED Talk where they setup an indoor arena and did some amazing things with drones. It got me thinking, and it inspired me to build something like that for myself – but on a much smaller and cheaper scale. In the TED Talk video they use an expensive real-time infrared motion tracking system made by companies like Vicon or Optitrack to measure the position of the drones, and then used a computer to calculate and send control signals to coordinate the drones.
At a high level, my setup works in a similar way, using a USB camera to track the position of a $15 toy drone, and then using the computer to send radio control signals through an Arduino and a wireless card. Excluding the computer, all the equipment cost about $85.
Watch the video above to see my computer flying the drone! The photo above shows my first setup. Read this Instructable to learn how to do it yourself!
Also check out MakeHardware.com for more details and links.
Step 1: Get the Components
To get this working, you're going to need a reasonably fast PC and the following items:
The Addicore wireless card is used to send the same radio signals that the drone would receive from the joystick.
Step 2: Setup the Drone
To help the camera recognize the drone, place four paper circles on the drone. Cut out circles from colored card stock. You'll want to choose a contrasting color from the color of your drone. Then, install the propeller guards on the Cheerson CX-10 drone, and use some double-sided tape to affix three circles to the propeller guard and one to the center of the drone. Arrange the three propeller guard circles as shown in the photo, with one circle to the front, one to the left, and one to the right. The side with the power switch should have no circle.
Step 3: Setup Your Arduino and the Wireless Card
Connect the nRF24L01+ card and the adapter board, and then wire them to the Arduino Uno according to the table below:
|Arduino Uno||NRF24L01+ Socket Adapter Board||Wire Color (in photo)|
|D5 (Digital 5)||CE||Yellow|
|A1 (Analog 1)||CSN||Green|
|D4 (Digital 4)||SCK||Blue|
|D3 (Digital 3)||MO (MOSI)||Purple|
|A0 (Analog 0)||MI (MISO)||Gray|
Step 4: Setup the USB Camera
The camera needs to be mounted so that it is aimed downward at a white surface from a height of about 2 feet. I used two sheets of poster board as the white background on the table. In my first setup (shown in the top picture), I used a folding table with a piece particle board to hold the camera above the table.
The second picture shows my upgraded setup built with Plexiglas sides and the camera mounted on wooden crossbars. In the second setup, the camera is mounted in the middle, and two LED lights are mounted next to it to make the lighting conditions more consistent.
Step 5: Setup Your Computer
As you might expect there is a fair amount of programming required to get this working.
You'll need to install the following software:
- Python 2.7 - I recommend using the Spyder development environment from the Python(x,y) distribution.
- PySerial package
Check out my guide to installing Python and OpenCV for more details.
Now download the code from the pc-drone repository. It is currently only setup to work on Windows right now, but you should be able to work on Linux or MacOS with some minor changes.
The main program to run is fly_drone.py, run it from the command line with python ./fly_drone.py
You'll need to have the USB camera and Arduino connected to run this code, as specified above. Most likely it will not work the first time - you'll need to edit the code so that it sees the right video camera, and also communicates to the right COM port for your Arduino. Also, you may need to tweak your code for your specific circle colors and also your lighting conditions. This post describes the process of how the computer recognizes the circles and how to modify the color recognition thresholds.
Step 6: Make It Fly!
If everything is running properly with the fly_drone.py script, then it is time to turn on your drone. You should see one of the lights on the Arduino Uno stop flashing and stay lit. This indicates the Arduino and drone are paired and now the computer can send signals to the drone.
Press 'w' on the keyboard to let the drone take off and hover. To make it land, press 's'. There are other sequences available as well to rotate or move the drone through a pattern. You can find the keyboard commands in the fly_drone.py code.
The above video shows the USB camera images that the computer uses to fly the drone. The small blue square in the video indicates the target location that the computer is trying to fly the drone to. The colored circles drawn around the purple circles on the drone indicate that the computer identified the position of each circle.
I hope you enjoyed my project. Please vote for this Instructable in the Make It Fly contest!