Saturday, March 28, 2015

How to compile and upload code to an APM1.4(mega1280) board under Ubuntu

The reason why I post this blog is that recently I am working on a project of catamaran in our Lab, in which we are using ArduPilot controller. However, the chip we have is pretty old, an Atmega1280, which is used probably 5 or 6 years ago. (The current version is Atmega2560 which has a double memory size). Since I don't have a newer version one, I have to google all the possible websites and try to figure out a way to make this old one work. Fortunately, I find some useful instructions and helpful resources eventually so that I could compile and upload a modified code to this obsolete chip.

Alright, Let's get started.

1. First of all, ArduPilot has its own new website here. Apparently, this website is for their latest boards. If you have a new board, follow the instruction on that website and you will have a basic idea how it works. Since I am using Ubuntu, I need some core packages to build the code under Linux. The required packages are listed on this page, simply run this line in the terminal:

$ sudo apt-get install gcc-avr avrdude avr-libc binutils-avr
 
2. The next step is to install Arduino IDE in the Ubuntu. The currently version of Arduino in the Ubuntu repository is 1.0.5. However the code of the ArduPilot is not compilable in this version. As far as I know, one reason is that in the 1.0.5 Arduino IDE, "PROGMEM" variables are supposed to be defined as const variables, but in the ardupilot code, they are not.

Anyway, we first install the arduino from the repository. Run this line in the terminal:

$ sudo apt-get install arduino

You can download this file(arduino-1.0.3-linux32.tgz). I share this file from my google drive. You can also find it online. After you download the file, unzip it using this line:

$ tar xvzf arduino-1.0.3-linux32.tgz

In this way, you will have a 1.0.3 arduino working in the ubuntu.

3. Next, get an old version code. As I mentioned at the beginning, the current code from their developer github or the firmware from their website can not be fitted into an Atmega1280 sadly:(. So we have to find their previous deprecated ardupilot-mega project website here. Go to the "Downloads" tag and choose "All downloads" in the search drop down menu. They also have their old ardurover and arducopter download websites.
I also shared a copy of ArduPlane2.40.zip from my google drive here just in case those links are broken.

4. After you download the code, unzip the file and copy the libraries folder to arduino-1.0.3 and merge with the libraries there.

5. Go to the arduino folder and run this line to open the arduino-1.0.3

$ ./arduino

Change the sketchbook location in the preference to the source code folder of the Arducopter or ArduPlane.

Open the ArduCopter.pde. Based on the instruction here, add these lines at the bottom of the APM_Config.h header file:

# define GPS_PROTOCOL GPS_PROTOCOL_MTK16
// # define TELEMETRY_UART2         DISABLED
# define CONFIG_RELAY            DISABLED
# define CAMERA                 DISABLED
# define MOUNT                  DISABLED
// # define LOGGING_ENABLED        DISABLED //for APM1 1280 logging is disabled by default
# define CLI_ENABLED            DISABLED


which can make the size of the code small enough to fit a 1280 board.


Choose Atmega1280 in the board selection and also select the correct serial port as well.
Finally, click the verify button to compile the code and then upload button to upload the code to the board.

6. We can Install the APMPlaner, which is a simulation software for ArduPilot. They have an ubuntu trusty version. I install the latest one on my laptop and it still can connect to my old mega1280 chip and show the roll, pitch and yaw data  neatly.


No comments:

Post a Comment