The ardupilot mega is a fairly capable complete autopilot from both the hardware and the software perspective.  But what if you projects needs all the sensors and not the full APM2 autopilot code?


The apm2-sensorhead project provides a quick, robust, and inexpensive way to add a full suite of inertial and position sensors to your larger robotics project.  This project is a replacement firmware for the ardupilot-mega hardware.  The stock arduplane firmware has been stripped down to just include the library code that interrogates the connected sensors, and also maintains the code that can read your RC transmitter stick positions through a stock RC receiver as well as drive up to 8 servo outputs.  It also includes manual override (safety pilot) code and code to communicate with a host computer.  The next upcoming feature will be onboard mixing for vtail, elevon, and flaperon aircraft configurations.  This allows you the option to fly complicated airframes (and have an autopilot fly complicated airframes) without needing a complicated transmitter or adding complicated mixing code to your autopilot application.


Speaking a bit defensively: I want to address the “why?” question.  First of all, I needed something like this for one of my own autopilot projects.  That’s really the primary motivation right there and I could just skip to the next section.  If you can answer this question for yourself, then you are my target audience!  Otherwise if your imagination is not already running off on it’s own, why should you or anyone else possibly be interested?

  • You are working in the context of a larger project and need to incorporate an IMU and GPS and possibly other sensors.  Do you design your own board?  Do you shoehorn your code onto the ardupilot?  Do you look at some of the other emerging boards (pixhawk, etc.?)  What if you could integrate the sensors you need quickly and easily?
  • The ardupilot mega is a relatively inexpensive board.  There are some APM clones available that are even less expensive.  It would be hard to put together the same collection of sensors for a lower price by any other means.
  • The ardupilot mega is proven and popular and has seen very wide scale testing.  It is hard to find any other similar device on the market that has been tested as thoroughly and under as wide a variety of applications and environments than the ardupilot.
  • The ardupilot mega code (especially the sensor I/O and RC code) is also tremendously well tested and ironed out.
  • By stripping all the extra functionality out of the firmware and concentrating simply on sensor IO and communication with a host computer, the new firmware is especially lean, mean, fast, and simple.  Where as the full arduplane code is bursting the atmega2560 cpu at the seams with no more room to add anything, compiling the amp2-sensorhead code reports: “Binary sketch size: 36,132 bytes (of a 258,048 byte maximum)”
  • Along with plenty of space for code, removing all the extraneous code allows to CPU to run fast and service all it’s required work without missing interrupts and without dropping frames.
  • There is a design philosophy the prefers splitting the hard real-time work of low level sensor interrogation from the higher level intelligence of the application.  This can lead to two simpler applications that each do their own tasks efficiently and well, versus a single monolithic conglomerations of everything which can grow to be quite complex.  With all the hard real time work taken care of by the apm2, the host computer application has far less need for a complicated and hard-to-debug thread based architecture.
  • The APM2 board can connect to a host computer trivially via a standard USB cable.  This provides power and a UART-based communication channel.  That’s really all you need to graft a full suite of sensors to your existing computer and existing application.  Some people like to solder chips onto boards, and some people don’t.  Some people like to write SPI and I2C drivers, and some people don’t.  Personally, I don’t mind if once in a while someone hands me an “easy” button. 🙂

Some Technical Details

  • The apm2-sensorhead firmware reports the internal sensor data @ 100hz over a 115,200 baud uart.
  • The apm2-sensorhead firmware can be loaded on any version of the ardupilot-mega from 2.0 to 2.5, 2.6, and even 2.7.2 from hobbyking.
  • The UART on the APM2 side is 5V TTL which you don’t have to worry about if you connect up with a USB cable.
  • This firmware has flown for extensively for 3 flying seasons at the time of this writing (2012, 2013, 2014) with no mishap attributable to a firmware problem.
  • The firmware communicates bi-directionally with a host computer using a simple binary 16-bit checksum protocol.  Sensor data is sent to the host computer and servo commands are read back from the host computer.
  • Released under the GPLv3 license (the same as the arduplane library code.)
  • Code available at the project site: https://github.com/clolsonus/apm2-sensorhead  This code requires a minor ‘fork’ of the APM2 libraries available here: https://github.com/clolsonus/libraries


I am writing this article to coincide with the public release of the apm2-sensorhead firmware under the LGPL license.  I suspect there will not be wide interest, but if you stumble upon this page and have a question or see something important I have not addressed, please leave a comment.  I continue to actively develop and refine and fly (fixed wing aircraft) with this code as part of my larger system.


Join the Conversation


Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

    1. Hi Miguel, I am first assuming you are able to compile other arduino sketches and your compiler setup is good. You will need to fetch the apm2-sensorhead project and also the “libraries” project which is in the same location on github. (https://github.com/clolsonus/libraries)

      I should point out that you need my special version of libraries to build the apm2-sensorhead code. I made a few tweaks and it is based on an older version of the apm2 firmware … it just became too much effort to track every new apm2 release and it was not necessary for a simpler system that just outputs sensor data and handles RC receivers and servos.

      So put both apm2-sensorhead and libraries inside your sketchbook folder and you should be able to compile the apm2-sensorhead sketch. The special libraries directory needs to be there, but you don’t need to compile anything in there separately.

      You should also look at the code in comms (inside apm2-sensorhead) to get an idea of the packet format the firmware sends out. The format is designed to be fairly bandwidth efficient and there will need to be a bit of code on the receiving end to extract out the values.

      For what it’s worth, I just flew 4 flights (2.5 hours of flight time) on my senior telemaster with this system in addition to about 1.5 hours the week before and so far all the latest changes have been flight worthy and rock solid.

      If you try all this and still have specific errors compiling, let me know and I can at least take a look and maybe have an idea for what to try. I am running Arduino-1.06 here which is older, but hopefully the code should compile in any version.

      1. Curt,
        Thanks for your prompt reply. I did, – as you said – put both the apm2-sensorhead code and your libraries in the same folder. I run Arduino IDE 1.0.3 and tested it with the latest ardupilot form github; both ArduPlane and Ardutracker complied (with several messages) but the .hex file was generated in each case.
        When tried apm2-sensorhead i got several errors messages and it stoped without producing an hex file.
        It will be of great help if you have time to check the error messages and point me to possible solutions. Will you prefer I post them hero or sent them via email?
        Thanks for your interest and support.

        1. Hi Miguel, I’m happy to take a look at your error messages. Hopefully it’s something simple. This isn’t the best place for detailed tech support though. I will email you separately in case you don’t already have my address. Thanks, Curt.

  1. Very interesting project.

    Do I understand this correctly? You have the same APM2 board, but this is a leaner firmware without any autopilot code. Basically, it uses all the onboard sensors, and sends their data out the UART port of a standard APM2?

    This sounds like it could be useful for one of the reasons you mentioned. The Mega is being maxed out trying to be an autopilot. A friend and I want to program the navigation on small on-board computer (BeagleBone, RasberryPi, etc), so this would work perfectly for our sensor array.

    Thanks for sharing. If/when we use this, I’ll be sure to share the results. 🙂

    1. Yes, that’s exactly it. I use a big processor + little processor model. The little processor is the arduino that handles all the low level sensor collection, does any required bit banging, times the reciever pulses (pilot inputs) and generates output PWM pulses for the servos. The big processor runs the 15 state EKF, navigation, mission/tasks, etc. If you decide to explore further down this path, feel free to ask questions.