|
|
@@ -27,7 +27,7 @@ enum Codes {
|
|
27
|
27
|
};
|
|
28
|
28
|
|
|
29
|
29
|
IMU::IMU()
|
|
30
|
|
- : mpu_(MPU6050_ADDRESS_AD0_HIGH) {
|
|
|
30
|
+ : mpu_(MPU6050_ADDRESS_AD0_HIGH), good_(false) {
|
|
31
|
31
|
}
|
|
32
|
32
|
|
|
33
|
33
|
void IMU::init() {
|
|
|
@@ -50,6 +50,7 @@ uint8_t IMU::wait() {
|
|
50
|
50
|
|
|
51
|
51
|
bool IMU::read(Protocol::IMU* pinto) {
|
|
52
|
52
|
if (!mpu_.testConnection()) {
|
|
|
53
|
+ good_ = false;
|
|
53
|
54
|
return false;
|
|
54
|
55
|
}
|
|
55
|
56
|
|
|
|
@@ -59,9 +60,16 @@ bool IMU::read(Protocol::IMU* pinto) {
|
|
59
|
60
|
pinto->gyros + 0,
|
|
60
|
61
|
pinto->gyros + 1,
|
|
61
|
62
|
pinto->gyros + 2);
|
|
|
63
|
+ good_ = true;
|
|
62
|
64
|
return true;
|
|
63
|
65
|
}
|
|
64
|
66
|
|
|
|
67
|
+void IMU::check() {
|
|
|
68
|
+ if (!good_) {
|
|
|
69
|
+ init();
|
|
|
70
|
+ }
|
|
|
71
|
+}
|
|
|
72
|
+
|
|
65
|
73
|
#define ERRORX(x) { dbg("err " #x "\r\n"); return -x; }
|
|
66
|
74
|
#define ERROR(x) { return -x; }
|
|
67
|
75
|
#define DBG(x)
|