Skip to content

Commit 8e8424a

Browse files
committed
examples update
1 parent bb876e8 commit 8e8424a

File tree

4 files changed

+113
-30
lines changed

4 files changed

+113
-30
lines changed

examples/example.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
static const char *TAG = "BNO055ESP32Example";
3131

3232
extern "C" void app_main(){
33-
// This values are random, see exampleCalibration.cpp for more details.
33+
// see exampleCalibration.cpp for more details.
3434
// bno055_offsets_t storedOffsets;
3535
// storedOffsets.accelOffsetX = 29;
3636
// storedOffsets.accelOffsetY = 24;
@@ -53,7 +53,7 @@ extern "C" void app_main(){
5353
bno.setOprModeNdof();
5454
ESP_LOGI(TAG, "Setup Done.");
5555
}
56-
catch (BNO055BaseException& ex){
56+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
5757
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
5858
return;
5959
}
@@ -62,15 +62,25 @@ extern "C" void app_main(){
6262
return;
6363
}
6464

65-
int8_t temperature = bno.getTemp();
66-
ESP_LOGI(TAG, "TEMP: %d°C", temperature);
65+
try{
66+
int8_t temperature = bno.getTemp();
67+
ESP_LOGI(TAG, "TEMP: %d°C", temperature);
6768

68-
int16_t sw = bno.getSWRevision();
69-
uint8_t bl_rev = bno.getBootloaderRevision();
70-
ESP_LOGI(TAG, "SW rev: %d, bootloader rev: %u", sw, bl_rev);
69+
int16_t sw = bno.getSWRevision();
70+
uint8_t bl_rev = bno.getBootloaderRevision();
71+
ESP_LOGI(TAG, "SW rev: %d, bootloader rev: %u", sw, bl_rev);
7172

72-
bno055_self_test_result_t res = bno.getSelfTestResult();
73-
ESP_LOGI(TAG, "Self-Test Results: MCU: %u, GYR:%u, MAG:%u, ACC: %u",res.mcuState,res.gyrState,res.magState,res.accState);
73+
bno055_self_test_result_t res = bno.getSelfTestResult();
74+
ESP_LOGI(TAG, "Self-Test Results: MCU: %u, GYR:%u, MAG:%u, ACC: %u",res.mcuState,res.gyrState,res.magState,res.accState);
75+
}
76+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
77+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
78+
return;
79+
}
80+
catch (std::exception& ex){
81+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
82+
return;
83+
}
7484

7585
while (1){
7686
try{
@@ -80,11 +90,11 @@ extern "C" void app_main(){
8090
ESP_LOGI(TAG, "Euler: X: %.1f Y: %.1f Z: %.1f || Calibration SYS: %u GYRO: %u ACC:%u MAG:%u", v.x, v.y, v.z, cal.sys, cal.gyro, cal.accel, cal.mag);
8191
}
8292
catch (BNO055BaseException& ex){
83-
ESP_LOGE(TAG, "Error: %s", ex.what());
93+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
8494
return;
8595
}
8696
catch (std::exception &ex){
87-
ESP_LOGE(TAG, "Error: %s", ex.what());
97+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
8898
}
8999
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode max output rate is 100hz (actual rate: 100ms (10hz))
90100
}

examples/exampleCalib.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,30 @@
3030
static const char *TAG = "BNO055ESP32Example";
3131

3232
extern "C" void app_main(){
33+
// see exampleCalibration.cpp for more details.
34+
// bno055_offsets_t storedOffsets;
35+
// storedOffsets.accelOffsetX = 29;
36+
// storedOffsets.accelOffsetY = 24;
37+
// storedOffsets.accelOffsetZ = 16;
38+
// storedOffsets.magOffsetX = -243;
39+
// storedOffsets.magOffsetY = -420;
40+
// storedOffsets.magOffsetZ = -131;
41+
// storedOffsets.gyroOffsetX = 1;
42+
// storedOffsets.gyroOffsetY = -1;
43+
// storedOffsets.gyroOffsetZ = 0;
44+
// storedOffsets.accelRadius = 0;
45+
// storedOffsets.magRadius = 662;
46+
3347
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
3448
try{
3549
bno.begin(); //BNO055 is in CONFIG_MODE until it is changed
3650
bno.enableExternalCrystal();
51+
//bno.setSensorOffsets(storedOffsets);
3752
//bno.setAxisRemap(BNO055_REMAP_CONFIG_P1, BNO055_REMAP_SIGN_P1); // see datasheet, section 3.4
3853
bno.setOprModeNdof();
3954
ESP_LOGI(TAG, "Setup Done.");
4055
}
41-
catch (BNO055BaseException& ex){
56+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
4257
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
4358
return;
4459
}
@@ -47,6 +62,26 @@ extern "C" void app_main(){
4762
return;
4863
}
4964

65+
try{
66+
int8_t temperature = bno.getTemp();
67+
ESP_LOGI(TAG, "TEMP: %d°C", temperature);
68+
69+
int16_t sw = bno.getSWRevision();
70+
uint8_t bl_rev = bno.getBootloaderRevision();
71+
ESP_LOGI(TAG, "SW rev: %d, bootloader rev: %u", sw, bl_rev);
72+
73+
bno055_self_test_result_t res = bno.getSelfTestResult();
74+
ESP_LOGI(TAG, "Self-Test Results: MCU: %u, GYR:%u, MAG:%u, ACC: %u",res.mcuState,res.gyrState,res.magState,res.accState);
75+
}
76+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
77+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
78+
return;
79+
}
80+
catch (std::exception& ex){
81+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
82+
return;
83+
}
84+
5085
while (1){
5186
try{
5287
//Calibration 3 = fully calibrated, 0 = uncalibrated
@@ -55,20 +90,20 @@ extern "C" void app_main(){
5590
ESP_LOGI(TAG, "Euler: X: %.1f Y: %.1f Z: %.1f || Calibration SYS: %u GYRO: %u ACC:%u MAG:%u", v.x, v.y, v.z, cal.sys, cal.gyro, cal.accel, cal.mag);
5691
if (cal.gyro == 3 && cal.accel == 3 && cal.mag == 3){
5792
ESP_LOGI(TAG, "Fully Calibrated.");
58-
bno.setOprModeConfig(); //Change OPR_MODE
93+
bno.setOprModeConfig(); //Change to OPR_MODE
5994
bno055_offsets_t txt = bno.getSensorOffsets(); //NOTE: this must be executed in CONFIG_MODE
6095
ESP_LOGI(TAG, "\nOffsets:\nAccel: X:%d, Y:%d, Z:%d;\nMag: X:%d, Y:%d, Z:%d;\nGyro: X:%d, Y:%d, Z:%d;\nAccelRadius: %d;\nMagRadius: %d;\n", txt.accelOffsetX, txt.accelOffsetY, txt.accelOffsetZ, txt.magOffsetX, txt.magOffsetY, txt.magOffsetZ, txt.gyroOffsetX, txt.gyroOffsetY, txt.gyroOffsetZ, txt.accelRadius, txt.magRadius);
61-
ESP_LOGI(TAG,"Store this values, place them using setSensorOffsets() after every reset of the BNO055 to avoid the calibration process, unluckily MAG requires to be calibrated after every reset, for more information consult datasheet.");
96+
ESP_LOGI(TAG,"Store this values, place them using setSensorOffsets() after every reset of the BNO055 to avoid the calibration process, unluckily MAG requires to be calibrated after every reset, for more information check datasheet.");
6297
break;
6398
}
6499
}
65100
catch (BNO055BaseException& ex){
66-
ESP_LOGE(TAG, "Error: %s", ex.what());
101+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
67102
return;
68103
}
69104
catch (std::exception &ex){
70-
ESP_LOGE(TAG, "Error: %s", ex.what());
105+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
71106
}
72-
vTaskDelay(100 / portTICK_PERIOD_MS); //in fusion mode max output rate is 100hz (actual rate: 100ms (10hz))
107+
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode max output rate is 100hz (actual rate: 100ms (10hz))
73108
}
74109
}

examples/exampleInterrupts.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
static const char *TAG = "BNO055ESP32Example";
3131

3232
extern "C" void app_main(){
33-
// This values are random, see exampleCalibration.cpp for more details.
33+
// see exampleCalibration.cpp for more details.
3434
// bno055_offsets_t storedOffsets;
3535
// storedOffsets.accelOffsetX = 29;
3636
// storedOffsets.accelOffsetY = 24;
@@ -44,7 +44,7 @@ extern "C" void app_main(){
4444
// storedOffsets.accelRadius = 0;
4545
// storedOffsets.magRadius = 662;
4646

47-
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16, GPIO_NUM_MAX, GPIO_NUM_23); // GPIO_NUM_MAX means unset
47+
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
4848
try{
4949
bno.begin(); //BNO055 is in CONFIG_MODE until it is changed
5050
bno.enableExternalCrystal();
@@ -57,7 +57,7 @@ extern "C" void app_main(){
5757
bno.setOprModeNdof();
5858
ESP_LOGI(TAG, "Setup Done.");
5959
}
60-
catch (BNO055BaseException& ex){
60+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
6161
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
6262
return;
6363
}
@@ -66,14 +66,31 @@ extern "C" void app_main(){
6666
return;
6767
}
6868

69-
int8_t temperature = bno.getTemp();
70-
ESP_LOGI(TAG, "TEMP: %d°C", temperature);
69+
try{
70+
int8_t temperature = bno.getTemp();
71+
ESP_LOGI(TAG, "TEMP: %d°C", temperature);
72+
73+
int16_t sw = bno.getSWRevision();
74+
uint8_t bl_rev = bno.getBootloaderRevision();
75+
ESP_LOGI(TAG, "SW rev: %d, bootloader rev: %u", sw, bl_rev);
76+
77+
bno055_self_test_result_t res = bno.getSelfTestResult();
78+
ESP_LOGI(TAG, "Self-Test Results: MCU: %u, GYR:%u, MAG:%u, ACC: %u",res.mcuState,res.gyrState,res.magState,res.accState);
79+
}
80+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
81+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
82+
return;
83+
}
84+
catch (std::exception& ex){
85+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
86+
return;
87+
}
7188

7289
while (1){
7390
if (bno.interruptFlag == true){
7491
//See bno055_interrupts_status_t for more details.
7592
bno055_interrupts_status_t ist = bno.getInterruptsStatus();
76-
// remmeber that multiple interrupts can be triggered at the same time. so you shouldn't use 'else if'
93+
// remember that multiple interrupts can be triggered at the same time. so you shouldn't use 'else if'
7794
if (ist.accelAnyMotion == 1){
7895
ESP_LOGI(TAG, "AccelAnyMotion Interrupt received.");
7996
}
@@ -89,11 +106,11 @@ extern "C" void app_main(){
89106
ESP_LOGI(TAG, "Euler: X: %.1f Y: %.1f Z: %.1f || Calibration SYS: %u GYRO: %u ACC:%u MAG:%u", v.x, v.y, v.z, cal.sys, cal.gyro, cal.accel, cal.mag);
90107
}
91108
catch (BNO055BaseException& ex){
92-
ESP_LOGE(TAG, "Error: %s", ex.what());
109+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
93110
return;
94111
}
95112
catch (std::exception &ex){
96-
ESP_LOGE(TAG, "Error: %s", ex.what());
113+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
97114
}
98115
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode max output rate is 100hz (actual rate: 100ms (10hz))
99116
}

examples/exampleQuaternion.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
static const char *TAG = "BNO055ESP32Example";
3131

3232
extern "C" void app_main(){
33-
// This values are random, see exampleCalibration.cpp for more details.
33+
// see exampleCalibration.cpp for more details.
3434
// bno055_offsets_t storedOffsets;
3535
// storedOffsets.accelOffsetX = 29;
3636
// storedOffsets.accelOffsetY = 24;
@@ -53,7 +53,7 @@ extern "C" void app_main(){
5353
bno.setOprModeNdof();
5454
ESP_LOGI(TAG, "Setup Done.");
5555
}
56-
catch (BNO055BaseException& ex){
56+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
5757
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
5858
return;
5959
}
@@ -62,19 +62,40 @@ extern "C" void app_main(){
6262
return;
6363
}
6464

65+
try{
66+
int8_t temperature = bno.getTemp();
67+
ESP_LOGI(TAG, "TEMP: %d°C", temperature);
68+
69+
int16_t sw = bno.getSWRevision();
70+
uint8_t bl_rev = bno.getBootloaderRevision();
71+
ESP_LOGI(TAG, "SW rev: %d, bootloader rev: %u", sw, bl_rev);
72+
73+
bno055_self_test_result_t res = bno.getSelfTestResult();
74+
ESP_LOGI(TAG, "Self-Test Results: MCU: %u, GYR:%u, MAG:%u, ACC: %u",res.mcuState,res.gyrState,res.magState,res.accState);
75+
}
76+
catch (BNO055BaseException& ex){ //see BNO055ESP32.h for more details about exceptions
77+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
78+
return;
79+
}
80+
catch (std::exception& ex){
81+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
82+
return;
83+
}
84+
6585
while (1){
6686
try{
87+
//Calibration 3 = fully calibrated, 0 = uncalibrated
6788
bno055_calibration_t cal = bno.getCalibration();
6889
bno055_quaternion_t v = bno.getQuaternion();
6990
ESP_LOGI(TAG, "Quaternion: W: %1.f X: %.1f Y: %.1f Z: %.1f || Calibration SYS: %u GYRO: %u ACC:%u MAG:%u", v.w,v.x, v.y, v.z, cal.sys, cal.gyro, cal.accel, cal.mag);
7091
}
7192
catch (BNO055BaseException& ex){
72-
ESP_LOGE(TAG, "Error: %s", ex.what());
93+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
7394
return;
7495
}
7596
catch (std::exception &ex){
76-
ESP_LOGE(TAG, "Error: %s", ex.what());
97+
ESP_LOGE(TAG, "Something bad happened: %s", ex.what());
7798
}
7899
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode max output rate is 100hz (actual rate: 100ms (10hz))
79100
}
80-
}
101+
}

0 commit comments

Comments
 (0)