Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining orientation using gyroscope and accelerometer

  • I want to monitor the orientation of a device on 2 axis: very simply: which way is down.
  • It must maintain accuracy over extended time period (12 hours)
  • It will be subject to rotations and accelerations about all axes

The device will be an Android phone with standard gyroscope / accelerometer. With those two sensor types, is it possible to satisfy the above requirements?

My thoughts so far: An accelerometer alone cannot achieve this, since given any set of values for an instant in time, it is not possible to separate the gravitational and spacial acceleration components. And I can't get my head round how a gyroscope could help resolve that. Are there any clever formulas / algorithms which would manage this?

Thanks

like image 691
CL22 Avatar asked Mar 19 '13 03:03

CL22


People also ask

How do you determine the orientation of an accelerometer?

Roll is rotation on the X-axis, which means the object is rotated to the right or left: If the accelerometer is tilted right, the roll will be a positive angle (between 1° to 180°). If the accelerometer is tilted left, the roll will be a negative angle (between -1° to -180°).

Can a gyroscope measure orientation?

A gyroscope is a device that uses Earth's gravity to help determine orientation. Its design consists of a freely-rotating disk called a rotor, mounted onto a spinning axis in the center of a larger and more stable wheel.

How do you combine accelerometer and gyroscope data?

Combining 3D accelerometers and gyroscopes This can be accomplished with a sensor fusion strategy. Sensor fusion techniques combine sensory data from disparate sources and generate information that has less uncertainty, or more accuracy.

How does a gyroscope and accelerometer work?

Accelerometer Versus GyroscopeAccelerometers measure linear acceleration (specified in mV/g) along one or several axis. A gyroscope measures angular velocity (specified in mV/deg/s). If we take our accelerometer and impose a rotation to it (i.e., a roll) (Figure 8), the distances d1 and d2 will not change.


1 Answers

An easy way to combine accelerometer and gyroscope data is by the use of a complementary filter. This way, you don't have problems with drift from the gyroscope and noise from the accelerometer. It is also much easier to understand and use than a Kalman filter.

You will calculate the angle from the gyroscope using an integral. And for the accelerometer you will use a tan2 function to determine the position of the gravity vector. The complementary filter would then combine these two angles as follows:

angle = 0.98*(angle + gyroData*dt) + 0.02*accAngle

Notice how you only take a fraction of the accelerometer data (just enough to compensate for the drift). You will thus use the gyroscope data for fast changes, but on the long run, you will keep following the mean value of the accelerometer angle calculation so that you don't drift.

I hope this helps. If you need more info and a C code example, I wrote an article about it here

like image 78
Pieter-Jan Avatar answered Sep 20 '22 03:09

Pieter-Jan