-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
68 lines (62 loc) · 1.79 KB
/
main.cpp
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
#include <stdio.h>
#include <iomanip>
#include <iostream>
#include <imu/bno055.h>
#include <imu/bno085.h>
#include <mag/hmc5883l.h>
void run_bno055();
void run_bno085();
void run_hmc58883l();
int main() {
stdio_init_all();
sleep_ms(5000);
run_bno085();
//run_bno055();
//run_hmc58883l();
}
void run_bno085() {
imu::bno85 imu(16, 17);
auto rc = imu.init_i2c_hal();
if (!rc) return;
rc = imu.enableReports();
if (!rc) return;
rc = imu.enableCalibration();
if (!rc) return;
while (true) {
sleep_ms(100);
sh2_service();
if (imu.hasReset()) {
imu.enableCalibration();
imu.enableReports();
}
}
}
void run_bno055() {
imu::bno55 imu(16, 17);
while (true) {
// calibration
auto [gyro, accl, mag, sys] = imu.getCalibrationStatus();
std::cout << "{\"cal_gyro\":" << unsigned(gyro) << ", \"cal_acc\":" << unsigned(accl)
<< ", \"cal_mag\":" << unsigned(mag) << ", \"cal_sys\":" << unsigned(sys) << "}\n";
// accl
//bno055_accel_float_t accel;
//bno055_convert_float_accel_xyz_msq(&accel);
//std::cout << std::fixed << std::setprecision(2);
//std::cout << "{\"acc_x\":" << accel.x << ", \"acc_y\":" << accel.y << ", \"acc_z\":" << accel.z << "}\n";
//euler
auto [h, p, r] = imu.getEulerAngles();
std::cout << std::fixed << std::setprecision(2);
std::cout << "{\"y\":" << h << ", \"p\":" << p << ", \"r\":" << r << "}\n";
sleep_ms(100);
}
}
void run_hmc58883l() {
mag::HMC5883L compass(20, 21);
compass.setDeclination(4);
//compass.calibrate(2000);
while (true) {
auto heading = compass.getHeading();
printf("heading: %f\n", heading);
sleep_ms(700);
}
}