Building a Kalman Filtering Frame Work for APM2: Using Matlab for Lab testing and an Embedded Computer (Gumstix) for Field Testing

Update: 5/5/2013



1- The MATLAB frame work is complete now

2- 7-state EKF is used for attitude estimation

3- the yaw correction is done using GPS course over ground

4- C-code is generated to work on the gumstix

5- implementation on the gumstix is done


1- use magnetometer for heading estimation, instead of GPS.

2- do real flight test to evaluate the EKF performance against the standard DCM that is used on the APM2.0.


Dear all,

I am a PhD student working in the filed of UAVs. Specifically, UAV-Based Flood detection system.

Although I am not going to talk about my project in details, I prefer to jump directly to the particular task that I am currently working on, which is getting a better (if not the best) attitude estimation from an IMU board, APM2. 

As you might know, in order for people who are working on UAV control and stabilization to get the best output of their control algorithms, it's of a paramount importance to receive a highly reliable input signals, particularly, from measurement sensors.

More specifically, as many of you already know, several researchers' interests that are related to attitude estimation have been conducted in order to find an optimal method to get the best attitude estimation from MEMS-Based sensors (e.g. Tri-Axis acclerometer, Gyros, and Magnetometers ).

In summary, I am trying to apply Kalman-Based filtering (e.g. EKF, UKF) in order to get better estimates. 

The hardware I am using:

1- APM2 with telemetry

2- Laptop

3- embedded computer (Gumstix),


1- Ardupilot (open source code for APM)

2- Mission Planner for Visualization

3- MATLAB : for lab testing.

I am dividing my framework into two parts. First one is the lab testing and simulation part. The second one is the field test on our C-17 GlobeMaster UAV. 


I have already finished a big part on the first sub-task. We implemented EKF/UKF in matlab (using this reference: and interfaced the APM2 with MATLAB as well (using USB). Finally, I am visualizing the attitude estimates using the Virtual Reality tool box in MATLAB as well.

We already managed to have a full circuit auto-flights (auto takeoff, auto flight, and auto landing) using the original Ardupilot code with some PID tuning. However, we need to advance further and apply advanced filtering using Kalman filtering that will be running on an external embedded computer (Gumstix) which will communicate with the APM in order to achieve more table flights, which is the second sub-task.

I created this post because I already started this task since few months ago, and almost done with the whole framework. However, I am facing some issues that I would like to solve using your help.

For that purpose, I am ready to share my codes and files for whoever is interested to effectively help me to arrive to the end of the road and achieve the tasks successfully. If we do that, we will be able to share such framework with the public community and to provide a ready & easy environment for academic researchers and amateurs as well.

Issues i am currently facing:


The UKF is working fine on offline data from the APM. However, when I use the same MATLAB code for real-time testing, it does not work fine. I am suspecting many things.

1- Possibly, the Measurement co-variance matrix, R, for real-time data has to be re tuned!

2- I am having packet drops from the serial communication which might affect the filter performance!

3- I am not using the right coordinates with respect to the sensors i am using!

4- the magnetometer needs to be filtered out against local disturbances!

So, any one is interested to plunge in and help?!

Views: 2273

Reply to This

Replies to This Discussion

Finally, the frame work is complete now, and we have a 7-state EKF working in MATLAB. The APM is sending raw data of IMU sensors, and GPS to MATLAB and the EKF processing is done in MATLAB. Finally, the attitude is visualized as a fixed-wing UAV.

We also managed to convert the MATLAB code to C-code (using  the internal MATLAB "coder"), that is used on our embedded computer (gumstix) which we will be using in our coming flights.

I will post the videos and result once they are ready.

Its interesting.

 Have some video?

Once we are done with the flight test, I'll post the video.

how i can send the APM 2.5 sensors data on MATLAB to process ......

Reply to Discussion


© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service