Hello everyone, I am a beigneer to the Arduino world.
I am trying to find the tilt angle with this code below using MPU 6050.
My problem start at when I try to multiply the cos(pitch)*cos(roll), for the assigned variable ""sqrt1""
Here is the code :
// orientation/motion vars
Quaternion q; // [w, x, y, z] quaternion container
VectorInt16 aa; // [x, y, z] accel sensor measurements
VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
VectorFloat gravity; // [x, y, z] gravity vector
float euler[3]; // [psi, theta, phi] Euler angle container
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
float CD,m,t,p,v,A_i,A,g,D,yaw,pitch,roll,t_angle,sqrt1,sqrt2,sqrt3,sqrt12;
// packet structure for InvenSense teapot demo
uint8_t teapotPacket[14] = { '
And here is the error I got :
'cos(((double)pitch))' cannot be used as a member pointer, since it is of type 'double'
[/code]
Any help would be really appreciated, 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };
// track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;
#ifdef OUTPUT_READABLE_QUATERNION
// display quaternion values in easy matrix form: w x y z
mpu.dmpGetQuaternion(&q, fifoBuffer);
Serial.print("quat\t");
Serial.print(q.w);
Serial.print("\t");
Serial.print(q.x);
Serial.print("\t");
Serial.print(q.y);
Serial.print("\t");
Serial.println(q.z);
#endif
#ifdef OUTPUT_READABLE_EULER
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetEuler(euler, &q);
Serial.print("euler\t");
Serial.print(euler[0] * 180/M_PI);
Serial.print("\t");
Serial.print(euler[1] * 180/M_PI);
Serial.print("\t");
Serial.println(euler[2] * 180/M_PI);
#endif
#ifdef OUTPUT_READABLE_YAWPITCHROLL
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
Serial.print("ypr\t");
Serial.print(ypr[0] * 180/M_PI); // x - z
Serial.print("\t");
Serial.print(ypr[1] * 180/M_PI); // y - y
Serial.print("\t");
Serial.println(ypr[2] * 180/M_PI); // z - x
CD=0.9;
p=1.225;
m=2;
g=9.81;
A_i=0.0244958;
yaw=ypr[0] ;
pitch=ypr[1];
roll=ypr[2];
sqrt1=(cos(roll).*cos(pitch));
sqrt2=(cos(roll).*sin(pitch));
sqrt3=(cos(pitch).*sin(roll));
t_angle= double 180-acos(((ypr[2]).*cos(pitch))./sqrt((pow(sqrt1,2))+(pow(sqrt2,2))+(pow(sqrt3,2))));
Serial.print("tilt angle \t");
Serial.print(t_angle * 180/M_PI);
;
//Serial.println("t angle =");
//Serial.println(v);
//D=mgtan(t);
//v=sqrt((2D)/(pA*CD));
//Serial.print("wind speed =");
//Serial.println(v);
#endif
#ifdef OUTPUT_READABLE_REALACCEL
// display real acceleration, adjusted to remove gravity
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
Serial.print("areal\t");
Serial.print(aaReal.x);
Serial.print("\t");
Serial.print(aaReal.y);
Serial.print("\t");
Serial.println(aaReal.z);
#endif
#ifdef OUTPUT_READABLE_WORLDACCEL
// display initial world-frame acceleration, adjusted to remove gravity
// and rotated based on known orientation from quaternion
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
Serial.print("aworld\t");
Serial.print(aaWorld.x);
Serial.print("\t");
Serial.print(aaWorld.y);
Serial.print("\t");
Serial.println(aaWorld.z);
#endif
#ifdef OUTPUT_TEAPOT
// display quaternion values in InvenSense Teapot demo format:
teapotPacket[2] = fifoBuffer[0];
teapotPacket[3] = fifoBuffer[1];
teapotPacket[4] = fifoBuffer[4];
teapotPacket[5] = fifoBuffer[5];
teapotPacket[6] = fifoBuffer[8];
teapotPacket[7] = fifoBuffer[9];
teapotPacket[8] = fifoBuffer[12];
teapotPacket[9] = fifoBuffer[13];
Serial.write(teapotPacket, 14);
teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
#endif
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
}
And here is the error I got :
'cos(((double)pitch))' cannot be used as a member pointer, since it is of type 'double'
[/code]
Any help would be really appreciated