Search code examples
accelerometergyroscope

how to get linear acceleration from accelerometer data


I'm using an IMU (3 axis accelerometer, 3 axis gyro, 3 axis magnetometer), and I want to get the linear acceleration from the accelerometer data. I knew about sensor fusion and the ability to use the gyroscope data (and get orientations) to get the gravity vector, and hence removing its effect from the corresponding axes.

Am I on the right path, and could you help if you can?


after that I'll integrate the acceleration twice to get the position as in following

        CurrentAcceleration[0] = e.Accelerometer[0];
        CurrentAcceleration[1] = e.Accelerometer[1];
        CurrentAcceleration[2] = e.Accelerometer[2];

        //we need to get the linear acceleration instead of the read data !!

        CurrentVelocity[0] += (CurrentAcceleration[0] + PreviousAcceleration[0]) / 2;
        CurrentVelocity[1] += (CurrentAcceleration[1] + PreviousAcceleration[1]) / 2;
        CurrentVelocity[2] += (CurrentAcceleration[2] + PreviousAcceleration[2]) / 2;

        Position[0] += (CurrentVelocity[0] + PreviousVelocity[0]) / 2 ;
        Position[1] += (CurrentVelocity[1] + PreviousVelocity[1]) / 2 ;
        Position[2] += (CurrentVelocity[2] + PreviousVelocity[2]) / 2 ;

        PreviousAcceleration[0] = CurrentAcceleration[0];
        PreviousAcceleration[1] = CurrentAcceleration[1];
        PreviousAcceleration[2] = CurrentAcceleration[2];

        PreviousVelocity[0] = CurrentVelocity[0];
        PreviousVelocity[1] = CurrentVelocity[1];
        PreviousVelocity[2] = CurrentVelocity[2];

Solution

  • Won't work.

    You cannot get accurate location or even velocity. On the above link you find tips what you actually could do instead.

    By the way, this question pops up surprisingly often.