-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmgm.cpp
More file actions
57 lines (48 loc) · 1.34 KB
/
Copy pathmgm.cpp
File metadata and controls
57 lines (48 loc) · 1.34 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
#include "mgm.hpp"
Magnetometer::Magnetometer() {
wiringPiSetup();
mpu = new MPU9250_Master_I2C(MPU9250_Master_I2C::AFS_2G,
MPU9250_Master_I2C::GFS_250DPS,
MPU9250_Master_I2C::MFS_16BITS,
MPU9250_Master_I2C::M_8Hz);
// Start the MPU9250
switch (mpu->begin()) {
case MPUIMU::ERROR_IMU_ID:
printf("Bad IMU device ID!\n");
break;
case MPUIMU::ERROR_MAG_ID:
printf("Bad magnetometer device ID!\n");
break;
case MPUIMU::ERROR_SELFTEST:
printf("Failed self test!\n");
break;
default:
printf("MPU9250 online!\n");
ok = true;
break;
}
}
Magnetometer::~Magnetometer() {
delete mpu;
}
void Magnetometer::calibrateMagnetometer() {
mpu->calibrateMagnetometer();
}
void Magnetometer::GetMagnetValues(float& mx, float& my, float& mz) {
mpu->readMagnetometer(mx, my, mz);
args[0][0] = mx;
args[0][1] = my;
args[0][2] = mz;
}
void Magnetometer::GetGyroValues(float& gx, float& gy, float& gz) {
mpu->readGyrometer(gx, gy, gz);
args[1][0] = gx;
args[1][1] = gy;
args[1][2] = gz;
}
void Magnetometer::GetAccelValues(float& ax, float& ay, float& az) {
mpu->readAccelerometer(ax, ay, az);
args[2][0] = ax;
args[2][1] = ay;
args[2][2] = az;
}