By Kong Wai Weng

RH2T Magazine Vol.1 (May 2009)

Measuring the tilt angle of a robot is always a challenge for any robot builder. The accuracy of the measured tilt angle is extremely important for some applications such as a two-wheeled balancing robot, a quad-rotor flying robot and an unmanned aerial vehicle (UAV).

UAV

Two-Wheeled Balancing Robot

Quad-rotor flying robot

In order to measure the tilt angle along a single axis, we will need at least a gyro and an accelerometer. But why do we need two types of sensor to measure one angle? To answer this question, we need to understand the characteristic of gyro and accelerometer.

Measuring Tilt Angle with Gyro and Accelerometer

**Accelerometer**

As named,an accelerometer is used to measure the acceleration. But what we are interested in is the tilt angle of a robot and what has it to do with the acceleration? The answer is gravity.

The earth’s gravity is a constant acceleration where the force is always pointing down to the centre of the Earth. When the accelerometer is parallel with the gravity, the measured acceleration will be 1G, when the accelerometer is perpendicular with the gravity, it will measure 0G. In short, the tilt angle can be calculated from the measured acceleration by using this equation:

θ = sin^{-1} (Measured Acceleration / Gravity Acceleration)

Unfortunately, this theory can only be applied when the robot is completely static. If the robot is moving, there will be other components of acceleration acting on the robot and causing the calculated tilt angle to be inaccurate. The solution for this problem is low-pass filter the data from the accelerometer. Typically, the acceleration components causing by the dynamic movement of the robot only happens in a short period of time, while the gravity acceleration is acting on the robot permanently. By low-pass filtering the data from the accelerometer, we can filter out the unwanted high frequency acceleration components and we are left with only the gravity acceleration which can be used to calculate the tilt angle of the robot. However, the low-pass filter will increase the latency and slow down the response time of the measurement as shown in the graph below. That’s where the gyro comes in.

Actual angle vs accelerometer output

**Gyro**

Gyro (a.k.a. rate sensor) is used to measure the angular velocity (ω). In order to get the tilt angle of a robot, we need to integrate the data from the gyro as shown in the equation below:

ω = dθ / dt

θ = ∫ ω dt

One of the problems of this integration process is, when the gyro data is integrated, the noise will also be integrated together. Furthermore, the gyro has its limitation where the output is not a constant offset when it is in static condition. In fact, this value will keep changing especially when there is temperature change. This condition is called drift. Although the drifting is very small, when we are dealing with integration, even the smallest offset will cause the integrated data to grow to infinity.

Actual angle vs Gyro output

**Gyro and Accelerometer Sensor Fusion**

After studying the characteristics of both gyro and accelerometer, we know that they have their own strengths and weakness. The calculated tilt angle from the accelerometer data has slow response time, while the integrated tilt angle from the gyro data is subjected to drift over a period of time. In other words, we can say that the accelerometer data is useful for long term while the gyro data is useful for short term.

One of the simplest ways to combine the data from the gyro and the accelerometer is by using the complementary filter. Complementary filter is designed in such a way that the strength of one sensor will be used to overcome the weaknesses of the other sensor which is complementary to each other.

In this application, the task of the complementary filter is to make use of the integrated angle from the gyro in short period, and then the low pass filtered data from the accelerometer is used to correct the drift of the angle over long period of time. The offset of the gyro sensor will also be continuously updated and corrected. This will result in a drift free and fast responding estimated tilt angle. The block diagram below shows how the gyro and accelerometer are fused together.

Block diagram of Complementary Filter

This is just a very simple filter for the sensor fusion of gyro and accelerometer. Of course, there are still other types of filter / algorithm which are more accurate such as Kalman Filter. But they are just too complicated to be discussed here.

* If you like to have faster response from author, please do post your inquiry/feedback/comment in our technical forum as we seldom check the comments section in tutorial site 🙂

hye,

can I just use idg500 gyroscope to get the angle?

I tried connect idg500 with arduino but until now can’t measure an angle,any solution for this?

or I need to add accelerometer to my project.

I have a machine which rotates 210 degree and its radias is 100 cm. if I fix a accelerometer with the arm of the machine and arrange a movable cable — then is it possible to measure the angle from the analog feedback from the accelerometer. expecting reply., thanks in advance!

regards,

Uttam Dutta

Remember, Gyro give you angular velocity, not angular/angle. You will need to integral with time to obtain angle which involve mathematical function 🙂 Do come to our technical forum to discuss.

Is possible, but is not straight forward, because accelerometer give reading in acceleration, not angle, you will need to have function or sometime we call filter to obtain the right angle. Please do come to our technical forum to discuss 🙂

Hallo,

Is it possible to do correction for robot car angle deviation from straight line using IDG500 breakout gyro. I can read angular rate. But Please tell me how to implement it for angle correction.

very good guide how to use gyro and accelerometer sensors. I add this tutorial on my article where a long list with sensors and tutorials about how to interface and programming accelerometer, gyro and IMU sensors http://www.intorobotics.com/accelerometer-gyroscope-and-imu-sensors-tutorials/

May I ask what is the best angle measurement accuracy I can get with a gyro around 100 USD?

I need something around +/- 0.01 degrees of accuracy, for a system with very low dynamic.

thanks

You need to check the datasheet. Through pricing will not give an idea.

Right here is the right blog for anyone who wishes to find out about this topic.

You know a whole lot its almost tough to argue with you (not that I actually will need to…HaHa).

You definitely put a brand new spin on a topic that’s been discussed for many years.

Great stuff, just wonderful!