-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVB_MPU9250.h
101 lines (82 loc) · 2.89 KB
/
VB_MPU9250.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
++VVM created by V.Medinskiy 14/03/18
This library implements motion processing functions of Invensense's MPU-9250.
It is based on their Emedded MotionDriver 6.12 library.
https://www.invensense.com/developers/software-download
*/
#ifndef _VB_MPU9250_H_
#define _VB_MPU9250_H_
#define MPU9250
#define ARDUINO_VB
#define AK8963_SECONDARY
#define COMPASS_ENABLED
extern "C" {
#include "inv_mpu.h"
}
typedef int mpu_error_t;
#define MPU_OK 0
#define MPU_ERROR 0x20
// Define's passed to update(), to request a specific sensor (or multiple):
#define UPDATE_ACCEL (1<<1)
#define UPDATE_GYRO (1<<2)
#define UPDATE_COMPASS (1<<3)
#define UPDATE_TEMP (1<<4)
class VB_MPU9250
{
public:
int ax_raw, ay_raw, az_raw;
int gx_raw, gy_raw, gz_raw;
int mx_raw, my_raw, mz_raw;
float ax, ay, az;
float gx, gy, gz;
float mx, my, mz;
//long qw, qx, qy, qz;
long temperature;
unsigned long time;
//float pitch, roll, yaw;
//float heading;
VB_MPU9250();
void read_raw(void);
void read(void);
// begin(void) -- Verifies communication with the MPU-9250 and the AK8963,
// and initializes them to the default state:
// All sensors enabled
// Gyro FSR: +/- 2000 dps
// Accel FSR: +/- 2g
// LPF: 42 Hz
// FIFO: 50 Hz, disabled
// Output: MPU_OK (0) on success, otherwise error
mpu_error_t begin(void);
// setGyroFSR(unsigned short) -- Sets the full-scale range of the gyroscope
// Input: Gyro DPS - 250, 500, 1000, or 2000
// Output: MPU_OK (0) on success, otherwise error
mpu_error_t setGyroFSR(unsigned short fsr);
// getGyroSens -- Returns current gyroscope sensitivity. The FSR divided by
// the resolution of the sensor (signed 16-bit).
// Output: Currently set gyroscope sensitivity (e.g. 131, 65.5, 32.8, 16.4)
float getGyroSens(void);
// setAccelFSR(unsigned short) -- Sets the FSR of the accelerometer
//
// Input: Accel g range - 2, 4, 8, or 16
// Output: MPU_OK (0) on success, otherwise error
mpu_error_t setAccelFSR(unsigned char fsr);
// getAccelSens -- Returns current accelerometer sensitivity. The FSR
// divided by the resolution of the sensor (signed 16-bit).
// Output: Currently set accel sensitivity (e.g. 16384, 8192, 4096, 2048)
unsigned short getAccelSens(void);
mpu_error_t update(unsigned char sensors =
UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS);
// updateAccel, updateGyro, updateCompass, and updateTemperature are
// called by the update() public method. They read from their respective
// sensor and update the class variable (e.g. ax, ay, az)
// Output: MPU_OK (0) on success, otherwise error
mpu_error_t updateAccel(void);
mpu_error_t updateGyro(void);
mpu_error_t updateCompass(void);
mpu_error_t updateTemperature(void);
private:
unsigned short _aSense;
float _gSense, _mSense;
bool dataReady(void);
};
#endif /* #ifndef _VB_MPU9250_H_ */