I cant find what is wrong here in this code. I am trying to get accelerometer data, but when i try to run it on device, that is working but not a proper reading I think problem in calculation, same logic I have used for gyro and taken proper reading but accelerometer output displayed Accelx :3.56023e-09 Accely :1.76423e-42 Accelz :1.77404e-42
accelX = accelerometer->Loop_Accelx();
accelY = accelerometer->Loop_Accely();
accelZ = accelerometer->Loop_Accelz();
for(int i = 0; i<2; i++) //averaging of accelerometer data upto 3 readings
{
float accelX1 = accelerometer->Loop_Accelx(); //storing the Accelx value from DmpMPU6050_Demo class
float accelY1 = accelerometer->Loop_Accely(); //storing the Accely value from DmpMPU6050_Demo class
float accelZ1 = accelerometer->Loop_Accelz(); //storing the Accelz value from DmpMPU6050_Demo class
accelX = accelX + accelX1;
accelY = accelY + accelY1;
accelZ = accelZ + accelZ1;
delay(1);
}
accelX = accelX/3;
accelY = accelY/3;
accelZ = accelZ/3;
if(numbercount == number){
emit Accelx_Data(accelX);
emit Accely_Data(accelY);
emit Accelz_Data(accelZ);
cout<<"Accelx :"<<accelX<<" Accely :"<<accelY<<" Accelz :"<<accelZ<<endl;
dmpmpu_demo file for accel x :
float DmpMPU6050_Demo::Loop_Accelx()
{
if (!dmpReady)
{
return 1;
}
fifoCount = mpu.getFIFOCount();
if (fifoCount == 1024)
{
mpu.resetFIFO();
printf("FIFO overflow!\n");
}
else if (fifoCount >= 42 )
{
mpu.getFIFOBytes(fifoBuffer, packetSize);
#ifdef OUTPUT_READABLE_REALACCEL
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
#endif
printf("\n");
}
}
You must sense the gravitational acceleration of the earth. This means that the vertical component of the vector you get must be clearly defined, and you get a vector that is clearly the zero vector. This is wrong and indicates you are not getting correct values from the accelerometer. Check that.
Next time, it will be better to post complete code, as the global accelX
, accelY
and accelZ
declarations are not seen anywhere in your code, what can be the actual source of problems... We don't have also the definitions of accelerometer->LoopAccel...()
prototypes.
And finally, don't shake it to sense data as has been told in the comments. Accelerometers sense the gravitational attraction of the earth, and you can just change its orientation to see a change in the acceleration vector.