I am currently trying to add a madgwick filter for MPU6050 in Mbed Studio OS6. I picked out a library to make implementation easier: https://os.mbed.com/users/hudakz/code/MPU6050/
I've tried to follow the library as best I can but the Madgwick filter setup isn't working as I had hoped. The time and temperature are showing correctly but the orientation values are listed as "0.00":
TIME, PITCH, ROLL, YAW, TEMP
00:11:59:716, 0.00, 0.00, 0.00, 25.48
Now here is the loop, what am I missing in order to get values in my output?
// Loop
while(1)
{
if (mpu6050.dataReady()) {
mpu6050.accel(); // Read 2g acceleration data
mpu6050.gyro(); // Read 250° gyroscope data
//mpu6050.setGain(float beta, float zeta); // Do I need this?
mpu6050.madgwickFilter(0.005f); // 5ms = 200Hz
// Using existing functions defined in the .cpp and .h files
float pitch = mpu6050.pitch();
float roll = mpu6050.roll();
float yaw = mpu6050.yaw();
// Read temperature - this works
float temperature = mpu6050.temp();
// Read time - this works
auto elapsed_time = t.elapsed_time();
// Print values to serial console - Now includes Time
snprintf(buffer, sizeof(buffer),
// Seperated by comma for data collection and visualiser
"%02d:%02d:%02d:%03d, %.2f, %.2f, %.2f, %.2f\n",
int (elapsed_time / 1h), int((elapsed_time % 1h) / 1min), int((elapsed_time % 1min) / 1s), int((elapsed_time % 1s) / 1ms),
pitch, roll, yaw, temperature);
// Raw values:
//"[%02d:%02d:%02d,%03d] Accel: (X: %.2f, Y: %.2f, Z: %.2f) G | Gyro: (A: %.2f, B: %.2f, C: %.2f) °/s | Temperature: %.2f°C\n\r",
//int (elapsed_time / 1h), int(elapsed_time % 1h / 1min), int(elapsed_time % 1min / 1s), int(elapsed_time % 1s / 1ms),
//ax, ay, az, gx, gy, gz, temperature);
printf("%s", buffer);
ThisThread::sleep_for(100ms); // Delay to read data
}
}