Arduino Quadcopter 2: State Estimation with Kalman Filtering of GPS Data

Kalman Filter Image

Along with 3 other robotics students at Georgia Tech, I made a further development on my work on the Arduino Quadcopter GPS functions that I first introduced in this post. As shown in the introductory post, GPS data from the DJI Naza GPS receiver can be sent to Arduino via serial communications. The next step is to program Arduino to produce a location estimate based on those GPS data. Although raw (latitude,longitude) data could be used as a location estimate, problems arise when the quadrotor enters areas where the GPS signal strength is lower and (latitude, longitude) updates are received at a much lower frequency. In the outdoor tests we performed in Atlanta, the rate of GPS data retrieval varied from as high 2 Hz to as low as < 0.1 Hz. This means that if the quadrotor depends only on raw GPS data, its location estimate could be 10 seconds old or more. In addition to issues with data retrieval frequency, raw GPS data are also noisy, thus increasing the unreliability of such an unfiltered location estimation scheme.

The problems discussed above are what motivate the implementation of a Kalman Filter on board the Arduino control hardware. The Kalman Filter is a popular mathematical technique in robotics because it produces state estimates based on noisy sensor data. This great tutorial explains the Kalman Filter. You can find our online and offline Arduino implementations of the Kalman Filter on my github page. The most useful implementation is Arduino_Kalman_Online_With_Interpolation.ino because it updates the quadrotor’s state estimate in spite of a lack of GPS data from the receiver hardware.

Below is a poster we put together to succinctly describe the work. The figures show the valuable benefit of having state estimates even when GPS data are not available. Black marks show GPS data while pink marks show Kalman Filtered state estimates made by Arduino in real time. The beneficial smoothing effect and the 1.75m location estimation accuracy are also evident.

Kalman Filter Poster

Arduino Quadcopter 2: GPS Integration

The current state of my Arduino Quadcopter 2 prototype is shown above. The DJI Naza can be bought with a GPS attachment that allows the flight controller to achieve very good position control outdoors. In the resulting behavior shown above, the quadcopter hovers in place unless the user sends non-zero flight commands that are filtered and then relayed by the Arduino. The hovering behavior above is a good example of high quality position control. However, in order to achieve autonomous behaviors outdoors via Arduino, it is crucial for the Arduino to have access to the GPS data that the Naza is using to hover. One very useful application is waypoint following. My plan to achieve waypoint following is to send a GPS location to the Arduino and to program the Arduino to send the flight commands appropriate for moving the quadcopter from its current GPS location to the target GPS location. This forum post explores the possibility of tapping into the serial communications between the Naza GPS device and the Naza flight controller itself.  Because Arduino can interpret serial communications, simply plugging the GPS receiver cord into a breadboard allows one to add an additional wire that leads from the Naza GPS device’s serial TX port to one of the the Arduino Mega’s RX ports. The Naza flight controller can then be allowed to use the GPS data as usual by adding wires leading from the breadboard connections to the Naza flight controller (i.e. the Naza flight controller “feels” as though the Naza GPS device is plugged in normally). The figure below shows how this is implemented with the on-board control circuitry:

Quadcopter Electronics

With this arrangement, the Naza flight controller can use GPS to hold position given non-zero flight commands, and the Arduino can use GPS to send non-zero flight commands that direct the quadcopter to follow a GPS waypoint. The forum user pawlesky wrote an excellent tutorial and C++ library that makes it relatively easy for Arduino to interface with the Naza GPS device. My integration of pawlesky’s library into the Arduino code in the Receiver10 file is here; version 10 is still very experimental. Below is an image of the GPS data reported by the Arduino Mega that is running the new receiver code. Note how the heading estimate from the magnetometer updates much more frequently than the latitude and longitude estimates. With access to GPS data, the Arduino Quadcopter can be programmed to fully autonomously follow waypoints, which is a huge step forward.

Data Stream

Arduino Quadcopter 2: Intro

Quadcopter splash page

I’m really happy to finally show this new prototype. In the last few months, I’ve completely rebuilt my autonomous, Arduino-based quadcopter and made significant software and hardware improvements over the previous version. This new version merges the programmatic ease of Arduino with the stability and robustness of the DJI Naza flight controller. People who follow my build instructions or otherwise use my design will be able to start writing their own flight programs inside my simple Arduino script that provides access to the same controls a human pilot would manipulate: aileron, elevator, rudder, and throttle. The beauty of this design is that, although DJI Naza is a closed-source product, I’ve made an open-source Arduino interface that makes it easy to achieve autonomy. I really want to stress the word easy. To make the craft move forward, all you have to do is type the following in your program:


That’s it. My implementation just uses functions in the well documented Arduino servo library to control motion. Here’s a demonstration of the possibilities:

Here are Receiver8 and Transmitter8, the work-in-progress versions of the code files used to control the quadcopter. The essence of this system is that an Arduino Uno in the handheld controller accepts joystick inputs and then sends control signals via RF communications to the Arduino Mega on board the quadcopter. The Arduino Mega then sends those controls to the DJI Naza by way of Arduino Servo functions. An arming/disarming system is implemented in the handheld controller. Stay tuned for future posts with updated code, circuit diagrams, and parts lists. Below is a video I sent to my collaborators during the re-construction of the quadcopter. It demonstrates the ability to control the DJI Naza using a combination of an Arduino Uno handheld controller and on-board Arduino Mega:

Autonomous Arduino Quadcopter Part 2: Prototype Overview and Parts List

Quad Collage

The current state of my quadcopter prototype is shown in the image above. You’ll find the parts list with my comments below. Every quadcopter needs a chassis, motors, propellers, a power source, and control circuitry. In the homebrew hobbyist community, mechanical components for quadcopters are fairly standardized, but control systems are not. A Google search will reveal dozens of different combinations of components people have used to program and stabilize their homemade quadcopters. Some advanced hobbyists have built their own microcontroller boards and written their own proportional-integral-derivative (PID) control software. Others have used dedicated KK Multicopter boards that come with stabilization software pre-installed. One particularly interesting solution is the MultiWii multicopter that uses gyroscopes and accelerometers taken from a Nintendo Wii controller. Given that I plan to build an autonomous quadcopter that will guide itself, a pre-built KK Multicopter board is insufficient because it has no room for the addition of sensors or other equipment. The current prototype uses an Arduino/KK Multicopter hybrid control system. The Arduino Mega board receives sensor input and commands from a human user. It then sends guidance commands to the KK board which balances the quadcopter and executes the guidance commands. This system is somewhat redundant because both the Arduino Mega and the KK board have microcontrollers capable of handling all of the tasks I want to accomplish. A future prototype will eliminate the KK board and use only the Arduino Mega to guide and balance the quadcopter.

Aside: While researching this project, I was surprised to see that there isn’t a standard, easy-to-use, homemade, and user programmable quadcopter build. I’ve spent far too many hours troubleshooting the interactions between the different parts in this build. I’ve looked at the source code files from MultiWii and other programs; they are quite daunting to the average user and there doesn’t seem to be a standard set of parts for which these code files are known to just work. One of my side goals with this project is to create a standard set of parts and simple Arduino code that will empower normal people to make a programmable quadcopter with greater ease. 

Arduino Mega

Logic Board: Arduino Mega

I plan to write artificial intelligence algorithms for this robot in C and execute them with an on-board Arduino Mega. The Arduino Mega is an enhanced version of the Arduino Uno which I described in a previous post. The Mega can execute the same programs as the Uno, but it has several times more expansion pins as well as more RAM and EEPROM. To be safely autonomous, this quadcopter will require several sensors on each of the four arms to prevent dangerous collisions with the moving propellers. The Mega’s 65 expansion pins will make large sensor arrays possible.

KK Board

Balance Board: KK Multicopter

I don’t have the ambition to write my own self-balancing software. It makes more sense to use existing Proportional Integral Derivative (PID) control algorithms for multicopters that can be found in open source and commercially available code libraries. The Arduino Mega will accept sensor inputs, execute AI algorithms, and then send throttle, roll, yaw, and pitch movement commands to outsourced self-balancing software that will convert those commands into motor actuation signals. The first revision of this prototype uses the KK Multicopter board to store and execute the open source XXController self-balancing software. Current testing has revealed this combination to be very problematic. Our team has crashed the prototype many times in attempts to launch and stabilize it. Future revisions will be based on the DJI Naza controllers and software.

UPDATE: As you can see in more recent posts, the flight controller aboard my Arduino Quadcopter 2 is indeed the DJI NazaM Lite with GPS.


Motor Controller: 30 Amp Electronic Speed Controller (ESC)

ESCs send the voltages required to turn the brushless motors described below. They receive and execute motor actuation signals from the KK Multicopter board. They have three blue output wires that connect to each of the three input wires of the motors. The three blue wires can be safely connected to the three motor wires in any order; exchanging the wires in any two connections merely reverses the motor’s rotation direction. ESCs receive power from the large red (+) and black (-) wires that are connected to the quadcopter’s power distribution circuit. The red and black wires must be connected only to positive and negative leads respectively, else a destructive short circuit will occur. The small white wire carries the desired speed control signal from the Arduino board to the ESC. The ESC can use power from the distribution circuit to power 5V devices such as an Arduino board via the small red wire. The black wire is connected to any ground pin.

ESCs contain microcontrollers that determine the voltages sent to each of the three blue output wires. Some readers may find it redundant that this prototype uses four microcontroller-containing ESCs when the Arduino board itself already contains a capable microcontroller that could be used for guidance, balance, and direct motor actuation. Technically, those readers would be correct: the power distribution and speed control functions of the ESCs could be totally emulated by a combination of Arduino and MOSFETS arranged in four “cascade” power relay circuits. The Arduino could be programmed to time the current flow through each MOSFET such that the input wires of each motor are energized in the right sequence to actuate motor rotation. I argue that this approach increases the complexity of the prototype thus increasing the number of points of failure. Furthermore, the near universal implementation of ESCs as motor speed controllers in quadcopters allows the use of standard code libraries and stabilization boards that would not be usable if the Arduino board were to handle motor actuation on its own. ESCs increase the robustness and ease of construction significantly.

Outrunner Motor

Motors: Mystery Brushless 1000KV

The cheapest, satisfactory motors I cold find are 1000KV outrunner motors. “KV” is a motor constant that defines the motor speed as a function of input voltage. An unloaded, 1000 KV motor will reach 1000 RPM if powered by 1V. In an outrunner motor, the entire outer shell of the motor spins along with the motor’s axle. A motor with the opposite configuration is called an “inrunner” motor. Outrunner motors have permanent magnets attached to the inner walls of the outer spinning shell. At the center of the motor, the polarity of each of three variable polarity electromagnets is determined by the polarity of the voltage sent to each of the motor’s three wires. By changing the polarity of the inner electromagnets in a cascading sequence, the outer shell of the motor is caused to spin. An example cascading polarity sequence would be (+,—,—),(—,+,—),(—,—,+). Creating this changing polarity pattern requires control circuitry connected to the three motor input wires.


Transceiver: 2.4GHz nRF24L01

Future iterations of this prototype will be autonomous, but the testing and experimentation that will lead to autonomy will require wireless control by a human operator. Although the hobbyist community prefers more advanced wireless communicators such as XBee, I’ve had great success with the very simple and very cheap nRF24L01. Each of these tiny transceivers can send and receive data in the form of integer arrays thus making Arduino communications simple to implement. In the quadcopter prototype, I connected the nRF24L01 directly to serial peripheral interface (SPI) communications pins on the Arduino Mega. This transceiver uses SPI communications protocols to transfer data to and from the Arduino board, but open source code libraries and online explanations allow hobbyists to use the transceiver without fully understanding SPI. This github code repository contains the RF24 code library for Arduino that will handle SPI communications “behind the scenes.” This Wikispaces page provides relatively simple instructions for using commands in the RF 24 Library to send and receive data via the nRF24L01 part. Some have claimed that the nRF24L01 has power problems when connected to Arduino boards, but I have had no such problems. Connecting the transceiver directly to the 3.3V pin on the Arduino Uno and Arduino Mega has produced great results in my projects. In a future post I will provide my own code and wiring diagrams that will show how to use this part specifically for the quadcopter application.


Chassis: X525

This prototype uses the X525 Chassis. After working with it, I don’t think this is a particularly good chassis, and my second quadcopter prototype will have the HJ450 frame. The X525 has metallic arms that are connected by PCB center platforms. The HJ450 has shorter polycarbonate arms that are connected by PCB center platforms. The X525 is heavier and wider than the HJ450, meaning that the X525 will require more power and will be less maneuverable than the HJ450. The X525, however, should produce more stable flights than the HJ450 because of its higher rotational inertia. I’ve noticed that most homemade quadcopters are made using the HJ450 or with a variant called the XJ MWC. The XJ MWC frame is useful because it has more room for electronics and other equipment on the center platforms.

The form of the chassis determines the mode of quadcopter flight. A + (plus) configuration quadcopter moves by turning one motor faster than the other three. An x configuration quadcopter moves by turning two motors faster than the other two. This page provides definitions of the different multicopter configurations and flight modes. The X525 and HJ540 frames are compatible with + and x configurations while the XJ MWC is compatible only with the x configuration because the XJ MWC is not symmetric about its motor arms. X configured quadcopters are more popular than + configured quadcopters in the hobbyist and commercial quadcopter communities. I’m still experimenting with + and x configurations.


Propellers: APC 10 x 4.7

I recommend 10 x 4.7 SF and 10 x 4.7 SFP propellers because they come quite well balanced from the factory. In order to balance the moments exerted by the motors on the quadcopter, two propellers must spin counterclowise and two propellers must spin clockwise. The “P” designation in “SFP” indicates a “pusher” propeller whose design is the reverse of a standard propeller. I use two SF and two SFP propellers. 

Distribution Board

Power Distribution Board

A power distribution board connects to the positive and negative battery leads. It allows 4 to 8 ESCs to be connected in parallel to the same battery, thus providing the same battery voltage to each battery.


Battery: 2200 mAh 3 cell Lithium Polymer Battery

Lithium polymer (LiPo) batteries have the best power/weight ratios on the market at present. They are the best batteries for drone/UAV applications. The disadvantage of LiPo batteries is that they are a fire hazard if charged or discharged improperly. Specialized battery chargers are required for LiPo batteries. I used this LiPo charger for this project. LiPo batteries are equipped with voltage leads for each individual cell so that the voltage of each cell can be monitored. Large differences in cell voltage lead to failure. Commercial LiPo batteries have various kinds of connectors attached to their leads. Before purchasing, make sure that the battery connectors are compatible with the other connectors in your project else you will have to remove the existing connector and solder your own connector. 

Autonomous Arduino Quadcopter Part 1: Introduction


Quadcopters are helicopters with four motors and four propellers. Quadcopters can be very agile, but they can also be very unstable. Unlike airplanes that can glide because of the aerodynamic lift force acting on their wings, quadcopters have no passive lift mechanism; a single motor failure or motor speed mismatch will lead to a violent crash. As a result, it’s extremely difficult for a human to fly a quadcopter by directly controlling each motor because this “classic” piloting method requires extreme reaction speed and attention. Modern quadcopter pilots rely on on-board sensors and microcontrollers that detect the machine’s dynamics and adjust motor speeds many times per second to self-stabilize. With dynamic stabilization handled by the machine itself, pilots are free to adjust a quadcopter’s throttle, pitch, roll, and yaw to semi-manually guide the quadcopter in a manner similar to a traditional aircraft. Our goal is to eventually build an autonomous quadcopter, one that not only balances itself but also guides itself. The self-balancing system described above makes flying quadcopters easier for pilots, but our goal is to replace pilots with artificial intelligence software.

I started working on an autonomous quadcopter because I got inspired by the Amazon’s Prime Air delivery system and by this incredible TED talk by Dr. Rafaello D’Andrea from ETH Zurich. My goal for the project is to build a quadcopter that can deliver a light package from one point to another. My plan is to construct a quadcopter using readily available hobby parts, configure those parts to interface with an Arduino board, and program the quadcopter to guide itself autonomously. To challenge myself, I want the start and end points to be hundreds of yards apart in order to reasonably simulate a local delivery. I live in Atlanta, and so the start and end points will be further separated by difficult obstacles such as tall buildings, trees, vehicles, etc.

I’m doing this project because I want to learn more about autonomous robotics and because I’m collaborating with Vergilis, a brilliant team at Atlanta Tech Village that has greater ambitions for my project. Vergilis is an Atlanta technology startup that plans to use autonomous drone technology to enable efficient local deliveries of fast food and other small items. Needless to say, this project has a long way to go before it achieves our ambition. One note I would like to make is that, unlike my previous rover project, this project is very much a work in progress. The code and assemblies I will post will be in very early stages of development and will likely contain many bugs; this is important to keep in mind especially due to the dangers of working with quadcopters. With that said, I hope these posts become an interesting and useful record of our progress.