-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDevBNO055Int.cpp
138 lines (110 loc) · 3.16 KB
/
DevBNO055Int.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* DevBNO055Int.cpp
*
* Created on: 24 ene. 2023
* Author: Carmen
*/
#include "DevBNO055Int.h"
DevBNO055Int::DevBNO055Int(void)
{
}
DevBNO055Int::~DevBNO055Int() {
// TODO Auto-generated destructor stub
}
bool DevBNO055Int::IMU_setup(long EE_address){
Wire.begin();
_imu = (RTIMUBNO055 *)RTIMU::createIMU(&_settings); // create the imu object
int errcode;
if ((errcode = _imu->IMUInit()) < 0) {
sprintf(DEBUG_buffer,"IMU %s. Error Code: %i\n",_imu->IMUName(), errcode);
DEBUG_print(DEBUG_buffer);
DEBUG_flush();
return false;
}
return true;
}
void DevBNO055Int::IBIT(void){
DEBUG_print(F("IMU int... Started\n"));
sprintf(DEBUG_buffer,"HW: %s\nSDA,SCL=%i,%i\n", IMUName(), get_PIN_SDA(),get_PIN_SCL());
DEBUG_print(F("Internal Fusion Mode\n"));
DEBUG_print(DEBUG_buffer);
DEBUG_flush();
}
float DevBNO055Int::updateHeading(void){
int loopCount = 1;
while (_imu->IMURead()) {
if (++loopCount >= 10) // this flushes remaining data in case we are falling behind
continue;
return reduce360(((RTVector3&)_imu->getFusionPose()).z() * RTMATH_RAD_TO_DEGREE);
}
}
bool DevBNO055Int::EEload_Calib(long int & eeAddress)
{
// Get and restore BNO Calibration offsets
long EE_ID, ID;
adafruit_bno055_offsets_t calibrationData;
// Look for the sensor's unique ID in EEPROM.
EEPROM.get(eeAddress, EE_ID);
// Look for unique ID reported by IMU
ID = get_IMUdeviceID();
sprintf(DEBUG_buffer,"IMU Sensor ID: %i\n",ID);
DEBUG_print(DEBUG_buffer);
if (EE_ID != ID) {
DEBUG_print(F("!WARNING: No Calibration Data for this sensor found!\n"));
sprintf(DEBUG_buffer,"ID found: %i\n",EE_ID);
DEBUG_print(DEBUG_buffer);
return false;
}
DEBUG_print(F("!Found Calibration data..."));
eeAddress += sizeof(ID);
EEPROM.get(eeAddress, calibrationData);
//displaySensorOffsets(calibrationData);
if (_imu->setSensorOffsets(calibrationData)){
DEBUG_print(F("Ok\n"));
} else {
DEBUG_print(F("Error. Not restored\n"));
}
//displaySensorOffsets();
return true;
}
bool DevBNO055Int::EEsave_Calib( long &eeAddress){
bool DataStored = false;
//DATA TO SAVE
long ID;
adafruit_bno055_offsets_t Calib;
DEBUG_print(F("!Saving Calibration..."));
//ID
ID = get_IMUdeviceID();
EEPROM.put(eeAddress, ID);
eeAddress += sizeof(ID);
//Calib
if (_imu->getSensorOffsets(Calib)) {
EEPROM.put(eeAddress, Calib);
DataStored = true;
DEBUG_print(F("Ok\n"));
} else {
DEBUG_print(F("Error. Not saved\n"));
}
return DataStored;
}
bool DevBNO055Int::IMU_startCalibration(bool completeCal) {
//IMU calibrates dynamically, no need to launch calibration process
if (completeCal == false) return false;
return false;
}
void DevBNO055Int::displaySensorOffsets(void){
DEBUG_print(F("Sensor offsets are internal.\n"));
return;
}
bool DevBNO055Int::IMU_Cal_Loop(bool completeCal){
//IMU calibration is internal
if (completeCal == false) return false;
return false;
}
bool DevBNO055Int::getCalibrationStatus(uint8_t &system, uint8_t &gyro, uint8_t &accel, uint8_t &mag){
_imu->getCalibration(&system, &gyro, &accel, &mag);
return true;
}
bool DevBNO055Int::IMU_Cal_stopRequest(void) {
return true;
}