A few years ago, I wanted to start a professional UAV business. I did some tests with the Multiplex EasyStar II as a rather unexpensive and easy to fly R/C plane and after it went quite well (which shall be covered in another post), I started buying some more fancy equipment along with an APM2.5 from diydrones.com.
The APM is an open source autopilot board based on the AVR Atmega2560. It was supposed to do the flying, so I could have concentrated on other tasks.
As life went a different direction (but definitely not south ;o) ), the UAV thing never happened(, yet).
Just recently I found the board in my drawer and I wanted to use it in a HIL setup together with FlightGear. The firmware for the board has become quite complex since the last time I looked at it, so I wanted to use Eclipse as the IDE instead of the Arduino IDE. It took a while to find the latest and greatest firmware for the board, though, since diydrones has discontinued the AVR based APM. While their page had some not so clear infos on which software version was the most recent and final one that would still run on the Atmega, I somehow found it was V3.4.0. After downloading and importing the package into Eclipse and trying to compile the code, all I got was a bunch of error messages and none of the pages I found about the topic had a real solution…
Long story short, here is how I made it work:
- Download ArduPilot-Arduino-1.0.3, basicly a customized Arduino IDE
- Download ArduPlane-release-AVR
- Unzip 1) to a folder that has no spaces in its name. (Actually we are only interested in the WinAVR package inside (ArduPilot-Arduino-1.0.3-windows\hardware\tools\avr\), so it would be sufficient to unzip that part to a folder that has no spaces in its name and forget about the rest.) Note that the no-spaces rule does apply to the parent folders, too!
- Unpack 2) anywhere you want, preferably to your project folder.
I happened to put 1) on the desktop (it wasn’t going to stay long) and 2) inside 1)
Inside the package of 2), there is a folder named “mk”. It contains some *.mk files, which are being used by make and are referring back and forth to each other, since they try to cover all kinds of OSes and setups. You have to edit three files:
– Anywhere before line 32 (preferably right before it) enter the following:
SKETCHBOOK := ..
This will help the compiler find the libraries
– At line 107 (which was 106 before adding the line above), change the line as following:
BUILDROOT := build
This will put the compiled files into a folder named “build” inside the same folder as the firmware that you are trying to compile (ArduCopter, ArduMrover2 or ArduPlane).
– Change line 27 to
TOOLPATH := <path to the avr/bin/ of 1)>
This will help make find the right compilers
Note that the backslashes need to be normal slashes!
– Comment out lines 77 – 85 by adding a # in front of each line to avoid some unnecessary error messages
– Change lines 88 to 91 to
MCU := atmega2560
F_CPU := 16000000L
HARDWARE_CORE := arduino
UPLOAD_SPEED := 115200
– Change line 109 to
UPLOAD_PROTOCOL := wiring
Now you can import the package to Eclipse
- Create a new project
- Choose “C/C++ – Makefile Project with Existing Code”
- Choose “<none>” as Toolchain
- Create a new target called “apm2”
While building the firmware should already be working fine, the intellisense of Eclipse would still need a few infos to work correctly:
- In the project properties, C/C++ General, Paths and Symbols, add the path to the “libraries” folder inside of 2) to the GNU C and GNU C++ settings
- Same for the “avr/include” and “lib/gcc/avr/4.8.2/include” folders inside of 1)
There would still be some issues for the intellisense for the files
but the code would still compile fine.