0

I am working in a project using MPU6050 with my designed chip to detect object movement. Project is divided into 2 phases:

  • Phase I: visualize object orientation (DONE)
  • Phase II: visualize object position in 3D cordinates with gyroscope and accelerator.I follow instructions from this website:http://www.x-io.co.uk/oscillatory-motion-tracking-with-x-imu/. The position must be derived from this through ‘double integration’; the accelerometer is first integrated to yield a velocity and then again to yield the position.

    void COpenGLControl::Update()
    {
      double mX;
      double mY;
      double mZ;
      mX = mXCordinate*9.81;  // mXCordinate-> X accelerator
      mY = mYCordinate*9.81;  // mYCordinate-> Y accelerator
      mZ = mZCordinate*9.81;  // mZCordinate-> Z accelerator
    
      /* linear velocity*/
      curVelX = preVelX  + mX *sampleRate;
      curVelY = preVelY  + mY*sampleRate;
      curVelZ = preVelZ  + mZ*sampleRate;
      /* linear location*/
      curLoX = preLoX + curVelX*sampleRate;
      curLoY = preLoY + curVelY*sampleRate;
      curLoZ = preLoZ + curVelZ*sampleRate;
    
      preVelX = curVelX;
      preVelY = curVelY;
      preVelZ = curVelZ;
    
      preLoX = curLoX;
      preLoY = curLoY;
      preLoZ = curLoZ;
     }
    

Then curLoX, curLoY, curLoZ is used to visualize 3D object with openGL:

glPushMatrix();
glTranslatef(curLoY,curLoX,curLoZ); //-> object moving visualization
glBegin(GL_QUADS);  
........       
glPopMatrix();

My purpose is that when moving object up, down, left, right, the 3D object will have the same movement. But object just only move when I rotate my device not linear movement following in http://www.x-io.co.uk/oscillatory-motion-tracking-with-x-imu/. How can I solve this problems? enter image description here

ios198
  • 37
  • 1
  • 9

1 Answers1

1

Accelerometers don't give you the object's position, but the, well it's in their name, acceleration, i.e. the rate of change of velocity.

You have to double integrate over time the values from the accelerometer to determine the position of the object. But there's a catch: Technically doing this is only valid for bodies in free fall. Down here on Earth (and every other massive body in the universe) there's gravity. The mechanical effect of gravity is acceleration. So down here on Earth you can measure a constant acceleration of about 9.81m/s² towards the Earth's center of gravity (you already have a constant of 9.81 up there but you completely misunderstood what it means).

There is no physically correct way to compensate for that. Acceleration is acceleration and in fact we are all moved in spacetime by it (that's why time is progressing a little slower down here on Earth than in outer space) and if you plotted the movement of the IMU in 4D spacetime it'd be the actual proper movement.

What you probably want to see however is the relative movement in the local accelerated frame of reference. If you assume a constant acceleration, that you can take this acceleration vector and subtract it from the measured values. Of course with every rotation of the IMU the acceleration vector will rotate, so you have to integrate the IMU rotation and apply that on the acceleration offset vector before subtracting. Assuming that relative movements are short and have a rather high frequency you may get away with low-pass filtering the accelerometer signal to determine the gravity offset vector.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • After getting accelerator data, what should I do next ? – ios198 Jan 13 '16 at 07:30
  • @ios198: Integrate it over time. If you don't understand what "integrating" means. I can't replace a course in calculus and numerics on StackOverflow. Relevant articles on https://en.wikipedia.org/wiki/Integral https://en.wikipedia.org/wiki/Numerical_integration and for the physics behind it https://en.wikipedia.org/wiki/Equations_of_motion – datenwolf Jan 13 '16 at 08:23
  • In my post, I already did it to get the location of object overtime. What did I do wrong here? Thank you very much for your help. – ios198 Jan 14 '16 at 00:31
  • @ios198: Somewhere in your program you're probably resetting the `pre…` variables. In integration it doesn't make a lot of sense to have `pre…` and `cur…` variables; you could use those for differentiation or for a Kalman filter, but even for those cases I'd not use such and employ the fact, that acceleration is already the second order derivative. – datenwolf Jan 14 '16 at 09:04