Вы находитесь на странице: 1из 11

1

Complementary Filter Design for Angle Estimation


using MEMS Accelerometer and Gyroscope
Hyung Gi Min and Eun Tae Jeung

Robotics Lab., NTREX Ltd., co., Juan-Dong 5-38, Nam-Gu, Incheon, Korea
Department of Control and Instrumentation, Changwon National University, Changwon, 641-773, Korea

Abstract: MEMS gyroscopes and accelerometers are designed to measure angular rate of rotation and
acceleration forces, respectively. In many applications, a measurement of the angle itself is needed but
gyroscopes have a drift error occurred by integrating the angular rate output and accelerometers have
errors due to translation forces. In this paper, we present a method of designing a complementary filter
to estimate the angle using both an accelerometer and a gyroscope. First, we show that the estimation
of the angle using single sensor of a gyroscope or an accelerometer has a lack of accuracy in some
experiments. And we propose a design method of the complementary filter using linear least squares to
estimate the angle. Experimental results of the proposed method are compared with the cut-off
frequency method in a practical rotary inverted pendulum system.

Keywords: gyroscope, accelerometer, filter, inverted pendulum, complementary filter, least squares.

1 Introduction

MEMS sensors have received considerable attention because of their advantages such as miniature size, low power
consumption, low cost, and mass-production. Particularly, they are very useful in applications to unmanned aerial
vehicles, automobiles, and mobile robots [1-3]. Gyroscopes are typically designed to measure the angular rate of
rotation. In order to estimate the absolute angle, the angular rate signal must be integrated with respect to time. The
integrated over time drifts due to presence of bias errors even if small [4-5]. We show this drift in section 2.2.1.
Accelerometers are designed to measure acceleration forces and can be used to measure seismic activity, machine
vibration, and inclination. The absolute angle can be determined by the measurement of the direction of the
gravitational acceleration. However, it is not easy to measure the absolute angle if translation forces are included in the
outputs of accelerometers [6-7]. We show this error in section 2.2.2.
In order to increase the accuracy of estimating the absolute angle, filter design methods have been introduced. The
Kalman filter algorithms [8-10] are used to estimate the absolute angle, but they have some drawbacks to mathematical
complexity and long computational time. There is a relatively simple filter called the complementary filter which uses
the outputs of two or multi sensors [11-18]. The basic concept of this filter is to enhance advantages of each sensor. For
example, the angular estimation using a gyroscope has a good accuracy in the sense of angular direction at high
frequencies and the angular estimation using an accelerometer has a good accuracy at low frequencies. A problem of
designing the complementary filter is to determine its coefficients such that it has the properties of low pass filter for the
accelerometer and high pass filter for the gyroscope. In general, the coefficients of the complementary filter are
determined by the cut-off frequency obtained from frequency characteristic of each sensor. However, it may be not easy
to obtain a cut-off frequency because of frequency gap between a sensor with good performance at low frequencies and
a sensor with good performance at high frequencies. That is shown in section 2.4.
In this paper, we present a systematic design method to determine the coefficients of the complementary filter using
well-known linear least squares[19-20] which minimizes the sum of the squared errors between estimating angle and
2

true angle (encoder measurement in experiment). A rotary pendulum system is experimented to illustrate the validity of
the proposed method and the results are compared with the cut-off frequency method. And the proposed filter is also
applied to a rotary inverted pendulum.

2 Some problems in experiment

We show that the angular estimation using single sensor of an accelerometer or a gyroscope has a lack of accuracy in
some experiments, and we introduce the complementary filter to detect the angle using both an accelerometer and a
gyroscope.

2.1 Test equipment


We use a rotary pendulum system as test equipment in Fig.1. The gyroscope(IDG300) of InvenSense company and
accelerometer(MMA7260QT) of Freescale company are attached between the joint of pendulum and arm, and also the
rotational encoder(E30S4-500-3-2F) of Autonics company is installed for comparison. In addition, the DC-
motor(320385) of MAXON company with a built-in encoder is mounted on the arm’s center of rotation. DSP-2812 of
TI company is used for data acquisition, filter realization, and control algorithm.

Fig.1 Rotary pendulum system.

2.2 Angle detection using single inertial sensor

2.2.1 Gyroscope
Since most of gyroscopes have bias errors, the drift errors occur from interation of the gyroscope’s outputs. Fig.2
shows this phenomenon. The solid line is the angle obtained from the encoder, the dotted line is the integration of the
angular rates obtained from gyroscope.
3

Fig.2 The result of a drift error.

2.2.2 Accelerometer
By measuring the amount of static acceleration due to the gravity, it can be found out the tilted angle of device with
respect to the direction of the gravity. When the z- component ( Z a ) and y- component ( Ya ) of accelerometer is found

out, Fig.3 shows that the angle( q c ) using accelerometer can be caculated as

æ Ya ö
qc = tan -1 ç ÷. (1)
è Za ø

If there exists a translation motion, the estimated angle using accelerometer is not accurate. Fig.3 is the case of no
translation and Fig.4 is the case with a translation motion. In Fig.3 and Fig.4, the solid lines are the angles from encoder,
and the dotted lines are the angles obtained from accelerometer. We recognize that translation motion causes the
estimation error.

25
Encoder
20
Accelerometer
15

10

5
degree

-5

-10

-15

-20

-25
0 5 10 15 20
time(s)

Fig. 3 The estimated angle from accelerometer in the case without translation motion.
4

Fig.4 The estimated angle from accelerometer in the case with translation motion.

2.3 Complementary Filter


Since the angular estimation using single sensor of a gyroscope or an accelerometer has a lack of accuracy, the basic
idea of the complementary filter is to combine the outputs of gyroscope and accelerometer. The estimate of the angle is
obtained from the sum of their measurements as Fig.5. The integration of the output of a gyroscope feeds into a high
pass filter and the output of an accelerometer feeds into a low pass filter. And the sum of the high pass filter and the low
pass filter is 1, that is,

G1 ( s ) + G2 ( s ) = 1 (2)

Fig.5 The complementary filter.

Fig.6 The second order complementary filter.


5

where G1 ( s ) and G2 ( s ) are transfer functions of the low pass filter and the high pass filter, respectively. We
consider Fig.6 as a complementary filter and its equation is

1é æ K ö ù
q f = êq&g - ç K p + i ÷(q f - q c )ú (3)
së è s ø û

where q&g and q c denote the outputs of the gyroscope and the accelerometer, respectively. The filter (3) can be

rewrriten as

s2 æ1 & ö K p s + Ki
qf = 2 ç qg ÷ + 2 qc (4)
s + K p s + Ki è s ø s + K p s + Ki

and (4) satisfies the condition (2). The problem of designing a complementary filter is converted to the problem of
determining the gains K p and K i . We review the cut-off frequency method in the next section and we introduce

least squares method in the next chapter.

2.4 Determination of the filter coefficients using cut-off frequency


In order to determine the complementary filter coefficients using cut-off frequency method, we consider the test
result of Fig.7. The solid line is the angle of the pendulum and the dotted line is the angle of the arm. Fig.8 is the angle
calculated by (1) from the accelerometer output (dotted line) and the estimates from 17 seconds to 22 seconds are
different from the anlge of the encoder (solid line). This implies that the estimate using an accelerometer is not accurate
at frequencies more than about 3.7[Hz]. So the cut-off frequency of (3) is chosen 1[Hz] and the filter coefficients K p

and K i are

K p = 1.414, Ki = 1. (5)

Fig.7 The angles of the pendulum and the arm in the test.
6

Fig.8 The result of estimating the angle using accelerometer.

Fig.9 The estimated angle from complementary filter with the gains (5).

Fig.9 is the result of estimating the angle with the filter coefficients (5) and RMSE (root-mean-square error) expressed
by

1 N 2
Er = å
N k =1
éq f (k ) - q e (k ) ù
ë û (6)

is 0.0565.

3 Complementary filter using least squares

In this chapter, we present a systematic method to determine the coefficients of the complementary filter using well-
known linear least squares method[19-20] which minimizes the sum of the squared errors between the estimated angle
and the angle obtained from encoder.
7

Since we want that the filter output is very similar to the encoder output, letting the filter output q f be the encoder

output and time derivative of (3) give

æ 1 æK ö
ç qe - qc (qe - qc ) ö÷ çç p ÷÷ = q&g - q&e . (7)
è s ø è Ki ø

Let

é qe (1) ù é qc (1) ù é q&g (1) ù


ê ú
êq&g (2) ú
êq (2) ú êq (2) ú
Qe = ê e ú , Qc = ê c ú &
, Qg = ê
ê M ú ê M ú ú, (8)
ê M ú
ê ú ê ú
ëqe (k ) û ëqc (k ) û êq&g (k ) ú
ë û

then (7) can be rewritten as

é 1 éK ù
ê Qe - Qc ( Qe - Qc )ùú ê p ú = éëQ& g - Q& e ùû . (9)
ë s û ë Ki û

Since the problem of finding the gains K p and K i of (9) is a linear least square problem, the gains can be obtained

as follows:

éK p ù -1 T
T
(
ê ú = A A A B,
ë Ki û
) (10)

where

é 1
A = ê Qe - Qc ( Qe - Qc )ùú , B = éëQ& g - Q& e ùû . (11)
ë s û

Using (10), we can get the following gains of the complementary filter from the experiment in Fig.7:

é K p ù é0.1664 ù
ê ú=ê ú. (12)
ë Ki û ë0.0089 û

Fig.10 is the estimate of the angle using the complementary filter with the gains (12) and its RMSE is 0.0389 which is
smaller than the result (RMSE: 0.0565) of the cut-off frequency method. In the cut-off frequency method, the RMSE
can be reduced according to choosing the cut-off frequency through many tests. But the proposed method is clearly
simple and systematic.
To verify the performance, apart from the test in Fig.7, the experiment of Fig.11 is carried out and its result is shown
in Table 1. In Fig.11, the solid line is the angle from encoder and the dotted line is the angle obtained from acclerometer.
In Table 1, (a) is the experiment of Fig.7, and (b) is of Fig.11. Er in Table 1 is the RMSE expressed by (6), and L.S. is
the proposed method using least squares. Table 1 shows that the proposed method is better than the others.
8

Fig.10 The estimated angle of the complementary filter using least squares.

Fig.11 The other experiment to verify performance of the proposed method.

Table 1 The RMSEs comparison with the cut-off frequency method.

Cut-off frequency
L.S.
0.01 0.1 1 3
Kp 0.0141 0.1414 1.4140 4.2420 1.664
Ki 0.0001 0.0100 1.0000 9.0000 0.0089
(a) 0.0735 0.0449 0.0565 0.0744 0.0389
Er
(b) 0.1392 0.0488 0.0732 0.0780 0.0425

4 An application to inverted pendulum control

In this chapter, we apply the complenetary filter to the stabilizing problem of a rotary inverted pendulum. The rotary
inverted pendulum[21-22] is inherently unstable, so it is important to esimate the angle of the pendulum for stabilization.
The linear dynamics of the rotary inverted pendulum[21] is given by
9


q&& = m p l p gq - f pq& ( J a + m p r 2 ) - m p l p r K g K t (V - K b K g a& ) Ra - f aa& ù
( ) ( ) (13)
Dë û


a&& = - m p l p r m p l p gq - f pq& + K g K t (V - K b K g a& ) Ra - f aa&
( ) ( )( J + m p l p2 ) ù , (14)
Dë û
p

where

( )( )
D = J a + ma r 2 J p + m p l 2 - (m p l p r )
2
(15)

and q is the angle of the pendulum, and a is the angle of the arm. The parameters are shown in Table 2 and we
design a stabilizing controller using LQR[23] method.

Table 2 Parameters of the rotary inverted pendulum.

Symbol Parameter Value

g Gravity 9.8 éë m s 2 ùû

mp Mass of pendulum 0.126 [ kg ]

r Length of arm 0.42 [ m ]

lp Distance between pendulum’s center l p = 0.24 [ m ]


of mass and center of rotation axis
fa Friction coefficient of arm 0.0362

fp Friction coefficient of pendulum 0.003

fm Friction coefficient of motor 0.001

Ja Inertia of arm 0.045 éë kgm 2 ùû

Jp Inertia of pendulum 0.003 éë kgm 2 ùû

Kg Gear ratio 12

Kb Back EMF constant K b = 0.0031

Kt Torque constant 0.0169

Ra Registance of motor 0.316 [ W ]

La Inductance of motor La = 0.00008 [ H ]

The angle of the arm is measured by built-in encoder in DC-motor. And the angle is detected by the proposed
complementary filter using a gyroscope and an accelerometer. The angular velocity of the arm is obtained from
differentiation its angle, and the angular velocity of the pendulum is obtained from the gyroscope. Fig.12 is a snap-shot
of the actual stabilization of the rotary inverted pendulum. And Fig.13 is a part of results to estimate the angle using the
proposed filter, in which the solid line is the angle of the pendulum obtained by the proposed complementary filter and
the dotted line is the angle from the encoder for comparison. It can be verified that the proposed method has good
performance enough to stabilize the inverted pendulum.
10

Fig.12 A snap-shot of the actual stabilization of the rotary inverted pendulum.

Fig.13 The estimated angle and the encoder angle of the inverted pendulum.

5 Conclusions

We have proposed a design method of the complementary filter with a gyroscope and an accelerometer using least
squares. The complementary filter has both a low pass filter for the output of an accelerometer and a high pass filter for
the output of a gyroscope. The least square method is used to estimate the angle and the proposed mothod is systematic,
simple, and accurate in comparison with the cut-off frequency method. And we show that the proposed filter has good
performance through the application to the stabilization of the rotary inverted pendulum.

References
[1] Sung Kyung Hong, “Fuzzy logic based closed-loop strapdown attitude system for unmanned aerial vehicle (UAV),”
Sensors and Actuators, A. 107, pp. 109-118, 2003.
[2] Yorihisa Yamamoto, “NXTway-GS Model –Based Design – Control of self-balancing two-wheeled robot built
with LEGO Mindstorms NXT,” http://www.mathworks.com/matlabcentral/fileexchange/19147.
[3] Pedro Castillo, Alejandro Dzul, and Rogelio Lozano, “Real-Time Stabilization and Tracking of a Four-Rotor Mini
Rotorcraft,” IEEE Transactions on Control Systems Technology, vol. 12, no. 4, pp. 510-516, July 2004.
11

[4] A. D. King, “Inertial Navigation – Forty Years of Evolution,” GEC REVIEW, vol. 13, no. 3, pp. 140-149, 1998.
[5] D. Piyabongkarn, R. Rajamani, and M. Greminger, “The development of a MEMS gyroscope for absolute angle
measurement,” IEEE Transactions on Control Systems Technology, vol. 13, no. 2, pp. 185-195, March 2005.
[6] V. Krishnan, “Measurement of Angular Velocity and Linear Acceleration Using Linear Accelerometers,” Journal
of the Franklin Institute, vol. 280, no. 4, pp. 307-315, 1965.
[7] A beginner’s guide to accelerometers. http://www.dimenstionengineering.com/accelerometers.htm
[8] M. S. Grewal, V. D. Henderson, and R. S. Miyasako, “Application of Kalman filtering to the calibration and
alignment of inertial navigation systems,” Institute of Electrical and Electronics Engineer, New York, pp. 65-72,
1986.
[9] David E. Gaylor, and E. Glenn Lightsey, “GPS/INS Kalman Filter Design for Spacecraft Operating in the
Proximity of the International Space Station,” American Institute of Aeronautics and Astronautics Guidance,
Navigation and Control Conference and Exhibit, Austin, TX, August 2003.
[10] H. J. Luinge, and P. H. Veltink, “Measuring orientation of human body segments using miniature gyroscope and
accelerometer,” Medical and Biological Engineering and Computing, vol. 43, no. 2, pp. 273-282, April 2005.
[11] Albert-Jan Baerveldt, and Robert Klang, “A Low-cost and Low-weight Attitude Estimation System for an
Autonomous Helicopter,” IEEE international conference on intelligent engineering systems, proceedings,
Budapest Hungary pp. 391-395, 1997.
[12] Lauro Ojeda, and Johann Borenstein, “Experomental Result with the KVH C-100 Fluxgate Compass in Mobile
Robots,” Proc.of the IASTED International Conference Robotics and Applications, Honolulu, Hawaii, August,
2000.
[13] A. Pascoal, I. Kaminer, and P. Oliveira, “Navigation System Design Using Time-Varying Complementary Filters,”
IEEE Transactions on Aerospace and Electronic Systems, vol. 36, no. 4, pp. 1099-1114, October, 2000.
[14] Anthony Gallaher, Yoky Matsuoka, and Wei-Tech Ang, “An Efficient Real-Time Human Posture Tracking
Algorithm Using Low-Cost Inertial and Magnetic Sensors,” Proc.of IEEE/RSJ International Conference on
Intelligent Robots and Systems, Sendai, Japan, September, 2004.
[15] Robert Mahony, Tarek Hamel, and Jean-Michel Pflimlin, “Complementary filter design on the special orthogonal
group,” Proc.of 4th IEEE Conference on Decision and Control, and the European Control Conference, Seville,
Spain, December, 2005.
[16] Woon-Tahk Sung, Sangkyung Sung, June-Young Lee, and Taesam Kang, “Development of a lateral velocity-
controlled MEMS vibratory gyroscope and its performance test,” Journal of the Micromechanics and
Microengineering, vol. 18, 055028.
[17] Cao Dong, Qu Qiang, and Li Chuntao, “Research of Attitude Estimation of UAV Based on Informantion Fusion of
Complementary Filter,” Fourth International Conference on Computer sciences and Convergence Information
Technology, Seoul, 2009.
[18] Armando Alves Neto, Douglas Guimaraes Macharet, Victor Costa da Silva Campos, and Mario Fernando Campos,
“Adaptive complementary filtering algorithm for mobile robot localization,” ” Journal of the Brazilian Computer
Society, vol. 15, no. 3, Campinas, September, 2009.
[19] Dennis G. Zill, Warren S. Wright, Advanced Engineering Mathematics Fourth Edition, Jones and Bartlett
Publishes, 2009.
[20] Wikipedia’s Article of Least Squares, http://en.wikipedia.org/wiki/Least_Squares.
[21] Myung-Gong Sohn, Cheon Don Son, Hyung Gi Min, Sung-Ha Kwon, and Eun Tae Jeung, “Design of a Stabilizing
Controller using T-S Fuzzy model for a rotary inverted pendulum,” AISM2006, Hong Kong, 2006.
[22] Wikipedia’s Article of Inverted Pendulum, http://en.wikipedia.org/wiki/Inverted_pendulum.
[23] Richard C. Dorf, and Robert H. Bishop, Modern Control System 10th Edition, Person Education, 2005.

Вам также может понравиться