Skip to content

Commit d4a61d7

Browse files
committed
Updated examples.
1 parent 79cb4de commit d4a61d7

File tree

3 files changed

+200
-88
lines changed

3 files changed

+200
-88
lines changed

examples/example.cpp

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,79 @@
1+
/* example.cpp
2+
* Copyright 2018 ShellAddicted <shelladdicted@gmail.com>
3+
* GitHub: https://github.com/ShellAddicted
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; If not, see <http://www.gnu.org/licenses/>.
17+
*/
118

19+
/*
20+
For more info: https://www.bosch-sensortec.com/bst/products/all_products/bno055
21+
Information in this library refers to BST_BNO055_DS000_14 (Consulted in January 2018)
22+
*/
223
#include "freertos/FreeRTOS.h"
324
#include "freertos/task.h"
425
#include "BNO055ESP32.h"
526
static const char *TAG = "BNO055ESP32Example";
627

7-
// This values are random, see exampleCalib.cpp for more details.
8-
uint8_t offsets[] = {0xED, 0xFF, 0x2E, 0x00, 0x18, 0x00, 0x5B, 0xFF, 0x2C, 0xFE, 0xAD, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0x00 ,0x00 ,0xE8 ,0x03 ,0xEC ,0x02};
9-
1028
extern "C" void app_main(){
11-
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
12-
try{
13-
bno.begin();
14-
bno.setExtCrystalUse(true);
15-
bno.setSensorOffsets(offsets);
16-
bno.setOpMode(BNO055_OPERATION_MODE_NDOF);
17-
ESP_LOGI(TAG, "Setup Done.");
18-
}
19-
catch (std::exception& ex){
20-
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
21-
return;
22-
}
29+
// This values are random, see exampleCalibration.cpp for more details.
30+
// bno055_offsets_t storedOffsets;
31+
// storedOffsets.accelOffsetX = 29;
32+
// storedOffsets.accelOffsetY = 24;
33+
// storedOffsets.accelOffsetZ = 16;
34+
// storedOffsets.magOffsetX = -243;
35+
// storedOffsets.magOffsetY = -420;
36+
// storedOffsets.magOffsetZ = -131;
37+
// storedOffsets.gyroOffsetX = 1;
38+
// storedOffsets.gyroOffsetY = -1;
39+
// storedOffsets.gyroOffsetZ = 0;
40+
// storedOffsets.accelRadius = 0;
41+
// storedOffsets.magRadius = 662;
42+
43+
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
44+
try{
45+
bno.begin(); //BNO055 is in CONFIG_MODE until it is changed
46+
bno.setExtCrystalUse(true);
47+
//bno.setSensorOffsets(storedOffsets);
48+
bno.setOpMode(BNO055_OPERATION_MODE_NDOF);
49+
ESP_LOGI(TAG, "Setup Done.");
50+
}
51+
catch (BNO055BaseException& ex){
52+
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
53+
return;
54+
}
55+
catch (std::exception& ex){
56+
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
57+
return;
58+
}
2359

24-
while (1){
25-
try{
26-
uint8_t sys, gyro, accel, mag;
27-
bno.getCalibration(&sys,&gyro,&accel,&mag);
28-
bno055_vector_t v = bno.getVectorEuler();
29-
ESP_LOGI(TAG, "Euler: (%.1f;%.1f;%.1f) <--> (%d,%d,%d,%d)", (double)v.x,(double)v.y,(double)v.z, (int)sys,(int)gyro,(int)accel,(int)mag);
30-
}
31-
catch (std::exception &ex){
32-
ESP_LOGE(TAG, "exc: %s", ex.what());
33-
}
34-
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode output rate is 100hz
35-
}
60+
int8_t temperature = bno.getTemp();
61+
ESP_LOGI(TAG, "TEMP: %d°C", temperature);
62+
63+
while (1){
64+
try{
65+
//Calibration 3 = fully calibrated, 0 = uncalibrated
66+
bno055_calibration_t cal = bno.getCalibration();
67+
bno055_vector_t v = bno.getVectorEuler();
68+
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);
69+
}
70+
catch (BNO055BaseException& ex){
71+
ESP_LOGE(TAG, "Error: %s", ex.what());
72+
return;
73+
}
74+
catch (std::exception &ex){
75+
ESP_LOGE(TAG, "Error: %s", ex.what());
76+
}
77+
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode output rate is 100hz
78+
}
3679
}

examples/exampleCalib.cpp

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,83 @@
1+
/* exampleCalib.cpp
2+
* Copyright 2018 ShellAddicted <shelladdicted@gmail.com>
3+
* GitHub: https://github.com/ShellAddicted
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; If not, see <http://www.gnu.org/licenses/>.
17+
*/
118

19+
/*
20+
For more info: https://www.bosch-sensortec.com/bst/products/all_products/bno055
21+
Information in this library refers to BST_BNO055_DS000_14 (Consulted in January 2018)
22+
*/
223
#include "freertos/FreeRTOS.h"
324
#include "freertos/task.h"
425
#include "BNO055ESP32.h"
526
static const char *TAG = "BNO055ESP32Example";
627

728
extern "C" void app_main(){
8-
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
9-
try{
10-
bno.begin(); // at this point BNO055 is in CONFIG_MODE until it is changed
11-
bno.setExtCrystalUse(true);
12-
//HOW TO RESTORE OFFSETS (EXAMPLE VALUES):
13-
// bno055_offsets_t ofx;
14-
// ofx.accelOffsetX = 29;
15-
// ofx.accelOffsetY = 24;
16-
// ofx.accelOffsetZ = 16;
17-
// ofx.magOffsetX = -243;
18-
// ofx.magOffsetY = -420;
19-
// ofx.magOffsetZ = -131;
20-
// ofx.gyroOffsetX = 1;
21-
// ofx.gyroOffsetY = -1;
22-
// ofx.gyroOffsetZ = 0;
23-
// ofx.accelRadius = 0;
24-
// ofx.magRadius = 662;
25-
// bno.setSensorOffsets(ofx); //NOTE: this must be executed in CONFIG_MODE
26-
bno.setOpMode(BNO055_OPERATION_MODE_NDOF); // Change OPR_MODE
27-
ESP_LOGI(TAG, "Setup Done.");
28-
}
29-
catch (std::exception& ex){
30-
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
31-
return;
32-
}
29+
// This values are random, see exampleCalibration.cpp for more details.
30+
// bno055_offsets_t storedOffsets;
31+
// storedOffsets.accelOffsetX = 29;
32+
// storedOffsets.accelOffsetY = 24;
33+
// storedOffsets.accelOffsetZ = 16;
34+
// storedOffsets.magOffsetX = -243;
35+
// storedOffsets.magOffsetY = -420;
36+
// storedOffsets.magOffsetZ = -131;
37+
// storedOffsets.gyroOffsetX = 1;
38+
// storedOffsets.gyroOffsetY = -1;
39+
// storedOffsets.gyroOffsetZ = 0;
40+
// storedOffsets.accelRadius = 0;
41+
// storedOffsets.magRadius = 662;
42+
43+
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
44+
try{
45+
bno.begin(); //BNO055 is in CONFIG_MODE until it is changed
46+
bno.setExtCrystalUse(true);
47+
//bno.setSensorOffsets(storedOffsets);
48+
bno.setOpMode(BNO055_OPERATION_MODE_NDOF);
49+
ESP_LOGI(TAG, "Setup Done.");
50+
}
51+
catch (BNO055BaseException& ex){
52+
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
53+
return;
54+
}
55+
catch (std::exception& ex){
56+
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
57+
return;
58+
}
3359

3460
while (1){
35-
try{
36-
uint8_t sys, gyro, accel, mag;
37-
bno.getCalibration(&sys,&gyro,&accel,&mag);
38-
bno055_vector_t v = bno.getVectorEuler();
39-
ESP_LOGI(TAG, "Euler:(%.1f;%.1f;%.1f) <--> (%d,%d,%d,%d)",(double)v.x, (double)v.y, (double)v.z, (int)sys, (int)gyro, (int)accel, (int)mag);
40-
if (gyro == 3 && accel == 3 && mag == 3){
61+
try{
62+
//Calibration 3 = fully calibrated, 0 = uncalibrated
63+
bno055_calibration_t cal = bno.getCalibration();
64+
bno055_vector_t v = bno.getVectorEuler();
65+
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);
66+
if (cal.gyro == 3 && cal.accel == 3 && cal.mag == 3){
4167
ESP_LOGI(TAG, "Fully Calibrated.");
4268
bno.setOpMode(BNO055_OPERATION_MODE_CONFIG); //Change OPR_MODE
4369
bno055_offsets_t txt = bno.getSensorOffsets(); //NOTE: this must be executed in CONFIG_MODE
4470
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);
4571
break;
4672
}
4773
}
48-
catch (std::exception &ex){
49-
ESP_LOGE(TAG, "exc: %s", ex.what());
50-
}
74+
catch (BNO055BaseException& ex){
75+
ESP_LOGE(TAG, "Error: %s", ex.what());
76+
return;
77+
}
78+
catch (std::exception &ex){
79+
ESP_LOGE(TAG, "Error: %s", ex.what());
80+
}
5181
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode output rate is 100hz
5282
}
5383
}

examples/exampleQuaternion.cpp

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,75 @@
1+
/* exampleQuaternion.cpp
2+
* Copyright 2018 ShellAddicted <shelladdicted@gmail.com>
3+
* GitHub: https://github.com/ShellAddicted
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; If not, see <http://www.gnu.org/licenses/>.
17+
*/
118

19+
/*
20+
For more info: https://www.bosch-sensortec.com/bst/products/all_products/bno055
21+
Information in this library refers to BST_BNO055_DS000_14 (Consulted in January 2018)
22+
*/
223
#include "freertos/FreeRTOS.h"
324
#include "freertos/task.h"
425
#include "BNO055ESP32.h"
526
static const char *TAG = "BNO055ESP32Example";
627

7-
// This values are random, see exampleCalib.cpp for more details.
8-
uint8_t offsets[] = {0xED, 0xFF, 0x2E, 0x00, 0x18, 0x00, 0x5B, 0xFF, 0x2C, 0xFE, 0xAD, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0x00 ,0x00 ,0xE8 ,0x03 ,0xEC ,0x02};
9-
1028
extern "C" void app_main(){
11-
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
12-
try{
13-
bno.begin();
14-
bno.setExtCrystalUse(true);
15-
bno.setSensorOffsets(offsets);
16-
bno.setOpMode(BNO055_OPERATION_MODE_NDOF);
17-
ESP_LOGI(TAG, "Setup Done.");
18-
}
19-
catch (std::exception& ex){
20-
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
21-
return;
22-
}
29+
// This values are random, see exampleCalibration.cpp for more details.
30+
// bno055_offsets_t storedOffsets;
31+
// storedOffsets.accelOffsetX = 29;
32+
// storedOffsets.accelOffsetY = 24;
33+
// storedOffsets.accelOffsetZ = 16;
34+
// storedOffsets.magOffsetX = -243;
35+
// storedOffsets.magOffsetY = -420;
36+
// storedOffsets.magOffsetZ = -131;
37+
// storedOffsets.gyroOffsetX = 1;
38+
// storedOffsets.gyroOffsetY = -1;
39+
// storedOffsets.gyroOffsetZ = 0;
40+
// storedOffsets.accelRadius = 0;
41+
// storedOffsets.magRadius = 662;
42+
43+
BNO055 bno(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_16);
44+
try{
45+
bno.begin(); //BNO055 is in CONFIG_MODE until it is changed
46+
bno.setExtCrystalUse(true);
47+
//bno.setSensorOffsets(storedOffsets);
48+
bno.setOpMode(BNO055_OPERATION_MODE_NDOF);
49+
ESP_LOGI(TAG, "Setup Done.");
50+
}
51+
catch (BNO055BaseException& ex){
52+
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
53+
return;
54+
}
55+
catch (std::exception& ex){
56+
ESP_LOGE(TAG, "Setup Failed, Error: %s", ex.what());
57+
return;
58+
}
2359

24-
while (1){
25-
try{
26-
uint8_t sys, gyro, accel, mag;
27-
bno.getCalibration(&sys,&gyro,&accel,&mag);
28-
bno055_quaternion_t v = bno.getQuaternion();
29-
ESP_LOGI(TAG, "Quaternion: (%.1f;%.1f;%.1f;%.1f) <--> (%d,%d,%d,%d)", (double)v.w, (double)v.x, (double)v.y, (double)v.z, (int)sys, (int)gyro, (int)accel, (int)mag);
30-
}
31-
catch (std::exception &ex){
32-
ESP_LOGE(TAG, "exc: %s", ex.what());
33-
}
34-
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode output rate is 100hz
35-
}
60+
while (1){
61+
try{
62+
bno055_calibration_t cal = bno.getCalibration();
63+
bno055_vector_t v = bno.getQuaternion();
64+
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);
65+
}
66+
catch (BNO055BaseException& ex){
67+
ESP_LOGE(TAG, "Error: %s", ex.what());
68+
return;
69+
}
70+
catch (std::exception &ex){
71+
ESP_LOGE(TAG, "Error: %s", ex.what());
72+
}
73+
vTaskDelay(100 / portTICK_PERIOD_MS); // in fusion mode output rate is 100hz
74+
}
3675
}

0 commit comments

Comments
 (0)