Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Madgwickfilter MPU6050
main.cpp
- Committer:
- shimizuta
- Date:
- 2019-07-17
- Revision:
- 5:f41d7b3be417
- Parent:
- 4:fdba5e452d36
- Child:
- 6:94c4a0e7bf48
File content as of revision 5:f41d7b3be417:
#include "mbed.h"
#include "MPU6050.h"
#include "madgwickfilter.h"
MPU6050 mpu6050(p28,p27);
Madgwickfilter filter;
const double PI = 3.14159265358979323846f;
const double kRad2Deg = 180.0/PI;
int main()
{
mpu6050.init();
while(1) {
//ジャイロから値取得
mpu6050.CalMPU6050();
double accel_x = mpu6050.GetAccelX();
double accel_y = mpu6050.GetAccelY();
double accel_z = mpu6050.GetAccelZ();
double omega_x = mpu6050.GetXRadPerSec();
double omega_y = mpu6050.GetYRadPerSec();
double omega_z = mpu6050.GetZRadPerSec();
//madgwickフィルターをかけ、yaw, pitch, rollを計算
filter.Update(accel_x, accel_y, accel_z, omega_x, omega_y, omega_z);
printf("Yaw, Pitch, Roll[deg]: %9.4f %9.4f %9.4f\r\n",
filter.getYaw()*kRad2Deg, filter.getPitch()*kRad2Deg, filter.getRoll()*kRad2Deg);
}
}