Comparison of Attitude and Heading Reference Systems
using Foot Mounted MIMU Sensor Data:
Basic, Madgwick and Mahony
Simone A. Ludwiga and Kaleb D. Burnhama and Antonio R. Jiménezb and Pierre A. Toumac
a North
b Centre
Dakota State University, Fargo, ND, USA
for Automation and Robotics (CAR-CSIC/UPM), Arganda del Rey, Madrid, Spain
c Axelo Inc., Austin, TX, USA
ABSTRACT
A magnetic and inertial measurement unit (MIMU) usually measures acceleration, rotation rate, and earth’s
magnetic field in order to determine a body’s attitude. In order to find the orientation information using all
sensors a fusion algorithm is used. This paper compares two approaches used for a Attitude and Heading
Reference System (AHRS), namely Madgwick and Mahony with a basic fusion approach. Foot mounted MIMU
data is used to estimate the Euler angles as well as the position. The results show that Madgwick obtains better
heading orientation than Mahony and the basic AHRS approach in terms of the error (RMSE) of the Euler
angles when compared to the ground truth. However, the execution time of Mahony is less than Madgwick with
the basic AHRS taking the longest.
Keywords: magnetic and inertial measurement unit, fusion algorithms, foot-mounted sensor data
1. INTRODUCTION
Research around localization of objects and people has received significant attention in the past few decades
and numerous techniques have been proposed to achieve high-accuracy localization. Although GPS is the most
common technology to provide accurate location for outdoor environments, it suffers from signal blocking and
the multipath effect. These effects lead to significant low location accuracy during the localization process. Thus,
other alternative sensor measuring techniques have to be used and improved in order to cover or replace GPS
technology.
A magnetic and inertial measurement unit (MIMU) consists of a 3-axis MEMS gyroscope, accelerometer and
magnetometer. MIMUs are widely used in many applications of attitude determination such as human motion
tracking, unmanned aerial vehicle (UAV), mobile navigation, etc.1 The gyroscope measures the angular rate of a
moving object, the accelerometer measures the acceleration of a certain object, and the magnetometer measures
the magnetic field. However, low-cost sensors have inherent drawbacks,2, 3 such as nonlinearity, random walk,
temperature drift, etc. In order to obtain a reliable attitude solution, MIMU sensor measurements have to be
fused together using optimal sensor fusion algorithms.4 There are mainly two different fusion approaches. One
category includes the complementary filters and the other relates to Kalman filtering.
The sensor data obtained from the gyroscope and the magnetometer has been used to obtain the heading.5, 6
Basically, the integration of the gyroscope from a known initial orientation supplies the change in rotation.
However, the gyroscope has a long-term drift which is due to noise and bias. Thus, these errors need to be
corrected. The calibrated magnetometer is used to minimize the drift in the horizontal orientation. Similar
work has been done previously by Muñoz et al.7 Their paper describes a comparison of four different AHRS
algorithms, namely the basic AHRS, Madgwick, Mahony, and a DLR-AHRS approach. The focus of their paper,
however, was on the influence of magnetic disturbances.
This paper compares Madgwick and Mahony with the basic AHRS approach to estimate the Euler angles and
position. Foot mounted error-free MIMU data is used to evaluate the approaches. RMSE (Root Mean Square
Error) is calculated based on the ground truth and the execution time of all AHRS is measured.
Further author information: (Send correspondence to Simone A. Ludwig): E-mail: simone.ludwig@ndsu.edu
2. APPROACHES
Using a MIMU we can obtain measurements for acceleration, ambient geomagnetic field and angular velocity from
the accelerometer, magnetometer and gyroscope, respectively. In order to compute the orientation estimation,
the measurement errors of these sensors have to be considered and reduced. Using the three sensors, it is
possible to build an AHRS (Attitude and Heading Reference System) in which each sensor will compensate for
the bias introduced by the others. Therefore, the accelerometer and magnetometer data has to be merged with
angular velocity from the gyroscope to compute an estimate of the orientation angles. This estimate is provided
by orientation filters. Examples of orientation filters are the complementary filter,8 and the Kalman filter.9
Examples of general purpose Bayesian estimation filters are Mahony,10 and Madgwick.11 Either of these filters
can be used in an AHRS.
The task of an AHRS is to provide the orientation of the sensors with respect to a navigational frame. The
orientation is commonly represented by Euler angles in the form of roll, pitch and yaw. Basically, the AHRS
integrates the gyroscope reading subject to some absolute correction that results from the magnetic field and
gravity. Thus, together with the acceleration, the roll and pitch can be obtained. Furthermore, the yaw can be
obtained via the magnetometer reading.
The methods of Madgwick and Mahony differ with regards to the resolution of these biases. For example,
Mahony uses a proportional and integral controller to correct the gyroscope bias, whereas Madgwick uses only a
proportional controller. Both approaches use a quaternion representation, which is a four-dimensional complex
number representing the orientation of an object. Even though quaternions are easier to calculate and more
efficient, however, they are less intuitive and understandable than Euler angles. Euler angles on the other hand
are subject to ambiguity and gimbal lock, which are two known problems of this representation that have been
taken into account. Gimbal lock is a singularity that appears when two axes of the object have parallel orientation
and causes the loss of one degree of freedom, and therefore measurement inaccuracy. Thus, in this paper we are
comparing Madgwick and Mahony applied to foot mounted MIMU sensor data with ground truth provided in
order to observe the errors involved.
The basic AHRS approach is described in details by Muñoz et al.7 It consists of two components that are
fused together as a weighted approach. The first part estimates the orientation from the gyroscope, and the
second component provides the orientation from the accelerometer and the magnetometer. Both components
provide an independent orientation estimate, and thus, are fused together in order to benefit from each source
of information.
3. EVALUATION
The data used is foot mounted MIMU measurement data.12 It contains sensor data of a straight trajectory
of 1, 000 steps based on a human step pattern characteristics measured by a motion capture system. For our
experiments, we have only used partial data of the data set. The information from the MIMU is the acceleration,
turn rates from the gyroscope and the magnetic field. The data set includes the orientation (Euler and DCM)
ground truth values. The units are in meters, seconds and radians, a sampling frequency of 100 Hz was used,
and gravity is 9.8 sm2 . The MIMU used was the XSense MTi with the following specification:
• Accelerometer: 0.012 sm2 standard deviation random noise and a random constant with a Gaussian distribution and a standard deviation of 0.04 sm2 for the bias.
• Gyroscope: 0.0087 rad
s standard deviation random noise and a random constant with a Gaussian distribution
and a standard deviation of 0.015 rad
s for the bias.
XSense MIMU are commonly used in motion sensing applications, and are seen as the gold standard for scientific
research.13–16
Figure 1 shows the sensor data obtained by the gyroscope, accelerometer, and magnetometer. The cyclic
steps of the walking motion can be observed.
Figure 1. Sensor data of gyroscope, accelerometer, magnetometer
In Figure 2, the Euler estimation correctness obtained by the basic AHRS is shown. Furthermore, the Euler
estimation correctness obtained by Madgwick is shown in Figure 3, and the one for Mahony in Figure 4. Preliminary experiments identified the optimal user-defined gains for each filter. The gain in the Madgwick filter
represents all mean zero gyroscope measurement errors and the optimum value was identified by Madgwick.11
In both, the Mahony and our basic filter, the gains are used as weights. The Mahony filter takes into consideration the disparity between the orientation from the gyroscope and the estimation from the magnetometer and
accelerometer and weighs them according to its gains. The changes made to the gyroscope are given by:
kp ∗ em + ki ∗ ei
(1)
where kp is the proportional gain, em is the sensor error of the gyroscope, ki is the integral gain, ei is the integral
error, which is calculated by:
em ∗
1
fs
(2)
where fs is the sampling frequency.
The basic filter uses a simpler weighting process directly on the quaternions. It is given by:
γ ∗ qG + (1 − γ) ∗ qAM
(3)
where γ is the weighing coefficient, qG is the quaternion of the gyroscope, and qAM is the quaternion based on
the acceleration and magnetometer readings.
We identified the optimum values for both the Mahony and the basic filter based on preliminary experiments.
The parameters used for the experiments were:
• β = 0.03311 (Madgwick)
• kp = 0.13, ki = 0.3 (Mahony)
• γ = 0.995 (Basic AHRS)
Table 1 shows the root mean squared error (RMSE) of the euler angles for Madgwick, Mahony and the
basic AHRS. The first number represents the euler angle for the sensor data with noise and the second number
Figure 2. Euler estimation correctness of Basic AHRS
Figure 3. Euler estimation correctness of Madgwick
represents the euler angles without noise. What can be observed is that Madgwick scores best for the sensor data
with noise included outperforming both Mahony and the basic AHRS. The RMSE values for the euler angles for
Madgwick for the sensor data with noise are 0.5896, 0.3123, and 0.5787 for the roll, pitch and yaw, accordingly.
Figures 5, 6, and 7 show the position estimation of the 3 axes. Similarily to the euler angles, the position
estimation in x, y, and z direction are the smallest when Madgwick is applied to the foot mounted data. Figure
6 shows the smallest error in all directions when compared to Mahony and the basic AHRS approach.
Table 1. RMSE values of Euler angles in degrees for Basic AHRS, Madgwick and Mahony with noise / without noise
AHRS
roll (deg)
pitch (deg)
yaw (deg)
Basic
Madgwick
Mahony
4.3135 / 0.0353
0.5896 / 0.0226
0.3813 / 0.1233
2.0937 / 1.9871
0.3123 / 0.3525
0.6464 / 0.6550
4.4740 / 0.0000
0.5787 / 0.0230
0.4522 / 0.1238
Figure 4. Euler estimation correctness of Mahony
Figure 5. Position estimation of Basic AHRS
Table 2 shows the execution time or running time of the three AHRS approaches. The differences of the
execution times are relatively small. Mahony has the shortest execution time of 3.1663 seconds, followed by
Madgwick with 3.3308 seconds, and the basic AHRS takes 4.1083 seconds.
Table 2. Execution Time in seconds of Basic AHRS, Madgwick and Mahony
AHRS
Execution time (s)
Basic
Madgwick
Mahony
4.1083
3.3308
3.1663
Figure 6. Position estimation of Madgwick
Figure 7. Position estimation of Mahony
4. CONCLUSION
In order to obtain orientation information from gyroscope, accelerometer and magnetometer data a fusion algorithm has to be used. This paper compared two approaches namely Madgwick and Mahony with a basic AHRS
approach. The data used was obtained from an MIMU mounted on a foot of a person. The aim was to use
this motion data to estimate the Euler angles in order to find the orientation of the person. The Euler angles
acquired by Madgwick, Mahony and the basic approach were then compared with the ground truth. The results
show that Madgwick outperforms Mahony and the basic AHRS in terms of RMSE on the sensor data with noise
when compared to the ground truth. In terms of execution time of the three approaches, Mahony takes less time
to compute compared to the other two approaches.
Acknowledgment
This work is funded by North Dakota Department of Commerce under project number FAR0027254.
REFERENCES
[1] H. Fourati, Heterogeneous data fusion algorithm for pedestrian navigation via foot-mounted inertial measurement unit and complementary filter, IEEE Trans. Instrum. Meas., vol. 64, no. 1, pp. 221-229, Jan. 2015.
[2] N. Barbour, G. Schmidt, Inertial sensor technology trends, IEEE Sensors J., vol. 1, no. 4, pp. 332-339, Dec.
2001.
[3] J. Leclerc, MEMS for aerospace navigation, IEEE Aerosp. Electron. Syst. Mag., vol. 22, no. 10, pp. 31-36,
2007.
[4] A. Makni, H. Fourati, A. Y. Kibangou, Energy-aware adaptive attitude estimation under external acceleration
for pedestrian navigation, IEEE/ASME Trans. Mechatronics, vol. 21, no. 3, pp. 1366-1375, Jun. 2016.
[5] J. W. Kim, H. J. Jang, D.-H. Hwang, C. Park, A step, stride and heading determination for the pedestrian
navigation system, Journal of Global Positioning Systems, vol. 3, no. 1-2, pp. 273-279, 2004.
[6] P. Goyal, V. J. Riberiro, H. Saran, A. Kumar, Strap-down pedestrian dead-reckoning system, in 2011 IEEE
International Conferences on Indoor Positioning and Indoor Navigation (IPIN), 2011.
[7] E. Muñoz, A. R. Jiménez, F. de Ponte, F. Zampella, Evaluation of AHRS Algorithms for Inertial Personal
Localization in Industrial Environments, Proceedings of the 2015 IEEE International Conference on Industrial
Technology (ICIT), pp. 3412 - 3417 Seville, Spain, March 17-19, 2015.
[8] M. Euston, P. Coote, R. Mahony, J. Kim, T. Hamel, A complementary filter for attitude estimation of a
fixed-wing UAV. In Proceedings of the IEEE/RSJ International Conference on Intelligent Robots and Systems
(IROS), Nice, France, 22-26 September 2008.
[9] G. Welch, G. Bishop, An Introduction to the Kalman Filter; Technical Report 95-041; University of North
Carolina: Chapel Hill, NC, USA, 24 July 2006.
[10] S. Mahony, T. Hamel, J.-M. Pflimlin, Nonlinear complementary filters on the special orthogonal group.
Auto. Control IEEE Transac., 53, 1203-1218, 2008.
[11] S. Madgwick, An Efficient Orientation Filter for Inertial and Inertial/Magnetic Sensor Arrays; Technical
Report; Report x-io and University of Bristol: Bristol, UK, 30 April 2010.
[12] Foot Mounted IMU data sets for the evaluation of PDR algorithms, LOPSI Research group, Spain, http:
//lopsi.weebly.com/downloads.html, 2017.
[13] A. G. Cutti, A. Giovanardi, L. Rocchi, A. Davalli, R. Sacchetti, Ambulatory measurement of shoulder and
elbow kinematics through inertial and magnetic sensors. Med. Boil. Eng. Comput., 46, 169-178, 2008.
[14] W. M. Chung, S. Yeung, W. W. Chan, R. Lee, Validity of VICON Motion Analysis System for Upper Limb
Kinematic Measurement A Comparison Study with Inertial Tracking Xsens System. Hong Kong Physiother.
J. 2011.
[15] D. Hamacher, D. Bertram, C. Folsch, L. Schega, Evaluation of a visual feedback system in gait retraining:
A pilot study. Gait Posture, 36, 182-186, 2012.
[16] K. Saber-Sheikh, E. C. Bryant, C. Glazzard, A. Hamel, R. Y. Lee, Feasibility of using inertial sensors to
assess human movement. Man. Ther., 15, 122-125, 2010.