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.