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?