-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathquaternions.ino
More file actions
88 lines (65 loc) · 2.24 KB
/
Copy pathquaternions.ino
File metadata and controls
88 lines (65 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// -------------------------------------------------
// Copyright (c) 2022 HiBit <https://www.hibit.dev>
// -------------------------------------------------
#include "MPU9250.h"
#define MPU9250_IMU_ADDRESS 0x68
#define MAGNETIC_DECLINATION 1.63 // To be defined by user
#define INTERVAL_MS_PRINT 1000
MPU9250 mpu;
unsigned long lastPrintMillis = 0;
void setup()
{
Serial.begin(115200);
Wire.begin();
Serial.println("Starting...");
MPU9250Setting setting;
// Sample rate must be at least 2x DLPF rate
setting.accel_fs_sel = ACCEL_FS_SEL::A16G;
setting.gyro_fs_sel = GYRO_FS_SEL::G1000DPS;
setting.mag_output_bits = MAG_OUTPUT_BITS::M16BITS;
setting.fifo_sample_rate = FIFO_SAMPLE_RATE::SMPL_250HZ;
setting.gyro_fchoice = 0x03;
setting.gyro_dlpf_cfg = GYRO_DLPF_CFG::DLPF_20HZ;
setting.accel_fchoice = 0x01;
setting.accel_dlpf_cfg = ACCEL_DLPF_CFG::DLPF_45HZ;
mpu.setup(MPU9250_IMU_ADDRESS, setting);
mpu.setMagneticDeclination(MAGNETIC_DECLINATION);
mpu.selectFilter(QuatFilterSel::MADGWICK);
mpu.setFilterIterations(15);
Serial.println("Calibration will start in 5sec.");
Serial.println("Please leave the device still on the flat plane.");
delay(5000);
Serial.println("Calibrating...");
mpu.calibrateAccelGyro();
Serial.println("Magnetometer calibration will start in 5sec.");
Serial.println("Please Wave device in a figure eight until done.");
delay(5000);
Serial.println("Calibrating...");
mpu.calibrateMag();
Serial.println("Ready!");
}
void loop()
{
unsigned long currentMillis = millis();
if (mpu.update() && currentMillis - lastPrintMillis > INTERVAL_MS_PRINT) {
Serial.print("TEMP:\t");
Serial.print(mpu.getTemperature(), 2);
Serial.print("\xC2\xB0"); //Print degree symbol
Serial.print("C");
Serial.println();
Serial.print("Pitch:\t");
Serial.print(mpu.getPitch());
Serial.print("\xC2\xB0"); //Print degree symbol
Serial.println();
Serial.print("Roll:\t");
Serial.print(mpu.getRoll());
Serial.print("\xC2\xB0"); //Print degree symbol
Serial.println();
Serial.print("Yaw:\t");
Serial.print(mpu.getYaw());
Serial.print("\xC2\xB0"); //Print degree symbol
Serial.println();
Serial.println();
lastPrintMillis = currentMillis;
}
}