4

I am having one android smart phone containing accelerator sensor, compass sensor and gyroscope sensor . i want to calculate the distance of displacement using this sensors.

I already tried with the basic method ie.,

final velocity = initial velocity + ( acceleration * time taken)
distance = time taken * speed

But i am unable to get the correct displacement. Every time i tried for same displacement i am gettng diffrent results.

JiTHiN
  • 6,548
  • 5
  • 43
  • 69
vishnu vigneshwar
  • 109
  • 1
  • 1
  • 7

2 Answers2

5

The equation you may be looking for looking for is:

Velocity = (Gravity*Acceleration)/(2*PI*freq)

A correct use of units for this equation (metric) would be

Gravity = mm/s squared = 9806.65
Acceleration = average acceleration over 1 second
Frequency = Hz (of the acceleration waveform over 1 second)

For example, if you gathered data from all 3 axes of the accelerometer, you would do the following to get a acceleration waveform (in raw values) for a 3D space:

inputArray[i] = sqrt(X*X + Y*Y + Z*Z);

Once the data is collected, only use the amount of samples in the waveform that would have been collected (if there is a 1ms delay between values only use 1000 values).

Add the values together and divide by the amount of samples to get your average (you may need to make all values positive if the accelerometer data have minus values) you could use this algorithm to do this before finding the average.

for(i = 0; i < 1000; i++){
    if(inputArray[i] < 0){
        inputArray[i] = inputArray[i] - (inputArray[i]*2);
    }
}

Once you have the acceleration average output you need to perform the equation above.

static double PI = 3.1415926535897932384626433832795;
static double gravity = 9806.65;

double Accel2mms(double accel, double freq){
    double result = 0;
    result = (gravity*accel)/(2*PI*freq);
    return result;
}

An example could be that the average acceleration is 3 gs over 1 second in a swing:

NOTE: This calculation is based on a sinusoidal waveform, so the frequency would be representative of the physical movement of the accelerometer not the frequency of the sampling rate

Accel2mms(3, 1);

3 gs over 1 second with a frequency of 1 (1 swing in one direction) = 4682.330468 mm/s or 4.7 meters.

Hope this is something like what you're looking for.

Bear in mind this calculation is based on a sinusoidal waveform but is being adapted to calculate based on a single movement (frequency 1) so it may not be very accurate. But in theory should work.

rm-vanda
  • 3,122
  • 3
  • 23
  • 34
Sam
  • 350
  • 2
  • 9
  • If the frequency is 0.5, does the method still return mm/s? – Ajay Jul 01 '16 at 16:13
  • I am trying to make more calculations, even though it would be less accurate. – Ajay Jul 01 '16 at 16:19
  • 1
    Like said in the post the results of this calculation would theoretically be right but with a frequency of 1 the accuracy of the input data would have to be exact for the result to be accurate. This equation was originally used to analyse waveforms from an accelerometer and thus having a frequency of 0.5 as an input would produce useless results as a period of acceleration cannot be halved as the total acceleration experienced over that timeframe or distance would likely not be linear. – Sam Jul 01 '16 at 16:26
  • Awesome thanks! But, is the frequency equivalent to the time taken for the motion? – Ajay Jul 01 '16 at 16:31
  • 1
    No not at all. For your use you could technically take the freq variable out of the equation entirely and have a simple converter function far any one instance of acceleration. – Sam Jul 01 '16 at 18:07
0

As @rIHaNJiTHiN mentioned in the comments, there is no reliable way to get displacement from 2nd and 3rd order sensors (sensors that measure derivatives of displacement like velocity and acceleration).

GPS is the only way to measure absolute displacement, though its precision and accuracy are not so high at short distances and short time periods (an in certain places with a bad signal).

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137