Skip to content

Commit 5ad061f

Browse files
committed
🎍 Updates feature flags and adds BNO055
1 parent e09ec81 commit 5ad061f

File tree

8 files changed

+71
-35
lines changed

8 files changed

+71
-35
lines changed

app/src/routes/peripherals/i2c/i2c.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
const i2cDevices = [
1010
{ address: 30, part_number: 'HMC5883', name: '3-Axis Digital Compass/Magnetometer IC' },
11+
{ address: 41, part_number: 'BNO055', name: '9-Axis Absolute Orientation Sensor' },
1112
{ address: 64, part_number: 'PCA9685', name: '16-channel PWM driver default address' },
1213
{ address: 72, part_number: 'ADS1115', name: '4-channel 16-bit ADC' },
1314
{

esp32/features.ini

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
[features]
22
build_flags =
3-
-D USE_SLEEP=0
4-
-D USE_UPLOAD_FIRMWARE=1
3+
-D USE_SLEEP=1
4+
-D USE_UPLOAD_FIRMWARE=0
55
-D USE_DOWNLOAD_FIRMWARE=0
66
-D USE_MOTION=1
77
-D USE_MDNS=1
88

99
; Hardware specific
10-
-D USE_MAG=0
11-
-D USE_BMP=0
10+
-D USE_HMC5883=0
11+
-D USE_BMP180=0
1212
-D USE_MPU6050=0
1313
-D USE_WS2812=1
14+
-D USE_BNO055=1
1415
-D USE_USS=0
15-
-D USE_SERVO=1
16+
-D USE_PCA9685=1

esp32/include/spot.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Spot {
6161
// act
6262
void updateActuators() {
6363
if (updatedMotion) _servoController.setAngles(_motionService.getAngles());
64+
updatedMotion = false;
6465

6566
_servoController.updateServoState();
6667
#if FT_ENABLED(USE_WS2812)
@@ -71,7 +72,7 @@ class Spot {
7172
// communicate
7273
void emitTelemetry() {
7374
if (updatedMotion) EXECUTE_EVERY_N_MS(100, { _motionService.emitAngles(); });
74-
EXECUTE_EVERY_N_MS(1000, { _peripherals.emitIMU(); });
75+
EXECUTE_EVERY_N_MS(250, { _peripherals.emitIMU(); });
7576
// _peripherals.emitSonar();
7677
}
7778

@@ -102,15 +103,14 @@ class Spot {
102103
bool updatedMotion = false;
103104

104105
const char *_appName = APP_NAME;
105-
const u_int16_t _numberEndpoints = 115;
106+
const u_int16_t _numberEndpoints = 116;
106107
const u_int32_t _maxFileUpload = 2300000; // 2.3 MB
107108
const uint16_t _port = 80;
108109

109110
protected:
110111
void loop();
111112
static void _loopImpl(void *_this) { static_cast<Spot *>(_this)->loop(); }
112113
void setupServer();
113-
void setupMDNS();
114114
void startServices();
115115
};
116116

esp32/lib/ESP32-sveltekit/features.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ void printFeatureConfiguration() {
1515
ESP_LOGI("Features", "USE_MOTION: %s", USE_MOTION ? "enabled" : "disabled");
1616

1717
// Sensors
18+
ESP_LOGI("Features", "USE_BNO055: %s", USE_BNO055 ? "enabled" : "disabled");
1819
ESP_LOGI("Features", "USE_MPU6050: %s", USE_MPU6050 ? "enabled" : "disabled");
19-
ESP_LOGI("Features", "USE_MAG: %s", USE_MAG ? "enabled" : "disabled");
20-
ESP_LOGI("Features", "USE_BMP: %s", USE_BMP ? "enabled" : "disabled");
20+
ESP_LOGI("Features", "USE_HMC5883: %s", USE_HMC5883 ? "enabled" : "disabled");
21+
ESP_LOGI("Features", "USE_BMP180: %s", USE_BMP180 ? "enabled" : "disabled");
2122
ESP_LOGI("Features", "USE_USS: %s", USE_USS ? "enabled" : "disabled");
2223
ESP_LOGI("Features", "USE_GPS: %s", USE_GPS ? "enabled" : "disabled");
2324

2425
// Peripherals
25-
ESP_LOGI("Features", "USE_SERVO: %s", USE_SERVO ? "enabled" : "disabled");
26+
ESP_LOGI("Features", "USE_PCA9685: %s", USE_PCA9685 ? "enabled" : "disabled");
2627
ESP_LOGI("Features", "USE_WS2812: %s", USE_WS2812 ? "enabled" : "disabled");
2728

2829
// Web services
@@ -38,12 +39,12 @@ void features(JsonObject &root) {
3839
root["download_firmware"] = USE_DOWNLOAD_FIRMWARE;
3940
root["sleep"] = USE_SLEEP;
4041
root["camera"] = USE_CAMERA;
41-
root["imu"] = USE_MPU6050;
42-
root["mag"] = USE_MAG;
43-
root["bmp"] = USE_BMP;
42+
root["imu"] = USE_MPU6050 || USE_BNO055;
43+
root["mag"] = USE_HMC5883 || USE_BNO055;
44+
root["bmp"] = USE_BMP180;
4445
root["sonar"] = USE_USS;
4546
root["motion"] = USE_MOTION;
46-
root["servo"] = USE_SERVO;
47+
root["servo"] = USE_PCA9685;
4748
root["ws2812"] = USE_WS2812;
4849
root["mdns"] = USE_MDNS;
4950
root["embed_www"] = EMBED_WWW;

esp32/lib/ESP32-sveltekit/features.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,34 @@
2929

3030
// ESP32 IMU on by default
3131
#ifndef USE_MPU6050
32-
#define USE_MPU6050 1
32+
#define USE_MPU6050 0
33+
#endif
34+
35+
// ESP32 IMU on by default
36+
#ifndef USE_BNO055
37+
#define USE_BNO055 1
3338
#endif
3439

3540
// ESP32 magnetometer on by default
36-
#ifndef USE_MAG
37-
#define USE_MAG 0
41+
#ifndef USE_HMC5883
42+
#define USE_HMC5883 0
3843
#endif
3944

4045
// ESP32 barometer off by default
41-
#ifndef USE_BMP
42-
#define USE_BMP 0
46+
#ifndef USE_BMP180
47+
#define USE_BMP180 0
4348
#endif
4449

4550
// ESP32 SONAR off by default
4651
#ifndef USE_USS
4752
#define USE_USS 0
4853
#endif
4954

55+
// PCA9685 Servo controller on by default
56+
#ifndef USE_PCA9685
57+
#define USE_PCA9685 1
58+
#endif
59+
5060
// ESP32 GPS off by default
5161
#ifndef USE_GPS
5262
#define USE_GPS 0

esp32/lib/ESP32-sveltekit/peripherals/imu.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
#include <utils/math_utils.h>
88

99
#include <MPU6050_6Axis_MotionApps612.h>
10+
#include <Adafruit_BNO055.h>
1011

1112
class IMU {
1213
public:
13-
IMU() {}
14+
IMU()
15+
#if FT_ENABLED(USE_BNO055)
16+
: _imu(55, 0x29)
17+
#endif
18+
{
19+
}
1420
bool initialize() {
1521
#if FT_ENABLED(USE_MPU6050)
1622
_imu.initialize();
@@ -21,6 +27,13 @@ class IMU {
2127
_imu.setI2CMasterModeEnabled(false);
2228
_imu.setI2CBypassEnabled(true);
2329
_imu.setSleepEnabled(false);
30+
#endif
31+
#if FT_ENABLED(USE_BNO055)
32+
imu_success = _imu.begin();
33+
if (!imu_success) {
34+
return false;
35+
}
36+
_imu.setExtCrystalUse(true);
2437
#endif
2538
return true;
2639
}
@@ -34,6 +47,14 @@ class IMU {
3447
_imu.dmpGetYawPitchRoll(ypr, &q, &gravity);
3548
return updated;
3649
#endif
50+
#if FT_ENABLED(USE_BNO055)
51+
sensors_event_t event;
52+
_imu.getEvent(&event);
53+
ypr[0] = (float)event.orientation.x;
54+
ypr[1] = (float)event.orientation.y;
55+
ypr[2] = (float)event.orientation.z;
56+
#endif
57+
return true;
3758
}
3859

3960
float getTemperature() { return imu_success ? imu_temperature : -1; }
@@ -60,6 +81,9 @@ class IMU {
6081
Quaternion q;
6182
uint8_t fifoBuffer[64];
6283
VectorFloat gravity;
84+
#endif
85+
#if FT_ENABLED(USE_BNO055)
86+
Adafruit_BNO055 _imu;
6387
#endif
6488
bool imu_success {false};
6589
float ypr[3];

esp32/lib/ESP32-sveltekit/peripherals/peripherals.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
6767

6868
updatePins();
6969

70-
#if FT_ENABLED(USE_MPU6050)
70+
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
7171
if (!_imu.initialize()) ESP_LOGE("IMUService", "IMU initialize failed");
7272
#endif
73-
#if FT_ENABLED(USE_MAG)
73+
#if FT_ENABLED(USE_HMC5883)
7474
if (!_mag.initialize()) ESP_LOGE("IMUService", "MAG initialize failed");
7575
#endif
76-
#if FT_ENABLED(USE_BMP)
76+
#if FT_ENABLED(USE_BMP180)
7777
if (!_bmp.initialize()) ESP_LOGE("IMUService", "BMP initialize failed");
7878
#endif
7979
#if FT_ENABLED(USE_USS)
@@ -137,7 +137,7 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
137137
/* IMU FUNCTIONS */
138138
bool readIMU() {
139139
bool updated = false;
140-
#if FT_ENABLED(USE_MPU6050)
140+
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
141141
beginTransaction();
142142
updated = _imu.readIMU();
143143
endTransaction();
@@ -147,7 +147,7 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
147147

148148
bool readMag() {
149149
bool updated = false;
150-
#if FT_ENABLED(USE_MAG)
150+
#if FT_ENABLED(USE_HMC5883)
151151
beginTransaction();
152152
updated = _mag.readMagnetometer();
153153
endTransaction();
@@ -157,7 +157,7 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
157157

158158
bool readBMP() {
159159
bool updated = false;
160-
#if FT_ENABLED(USE_BMP)
160+
#if FT_ENABLED(USE_BMP180)
161161
beginTransaction();
162162
updated = _bmp.readBarometer();
163163
endTransaction();
@@ -181,13 +181,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
181181
void emitIMU() {
182182
doc.clear();
183183
JsonObject root = doc.to<JsonObject>();
184-
#if FT_ENABLED(USE_MPU6050)
184+
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
185185
_imu.readIMU(root);
186186
#endif
187-
#if FT_ENABLED(USE_MAG)
187+
#if FT_ENABLED(USE_HMC5883)
188188
_mag.readMagnetometer(root);
189189
#endif
190-
#if FT_ENABLED(USE_BMP)
190+
#if FT_ENABLED(USE_BMP180)
191191
_bmp.readBarometer(root);
192192
#endif
193193
serializeJson(doc, message);
@@ -214,13 +214,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
214214

215215
JsonDocument doc;
216216
char message[MAX_ESP_IMU_SIZE];
217-
#if FT_ENABLED(USE_MPU6050)
217+
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
218218
IMU _imu;
219219
#endif
220-
#if FT_ENABLED(USE_MAG)
220+
#if FT_ENABLED(USE_HMC5883)
221221
Magnetometer _mag;
222222
#endif
223-
#if FT_ENABLED(USE_BMP)
223+
#if FT_ENABLED(USE_BMP180)
224224
Barometer _bmp;
225225
#endif
226226
#if FT_ENABLED(USE_USS)

platformio.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ data_dir = esp32/data
1414
src_dir = esp32/src
1515
include_dir = esp32/include
1616
lib_dir = esp32/lib
17+
test_dir = esp32/test
1718
extra_configs =
1819
esp32/factory_settings.ini
1920
esp32/features.ini
@@ -64,8 +65,6 @@ build_flags =
6465
${env.build_flags}
6566
-D USE_CAMERA=1
6667
-D CAMERA_MODEL_XIAO_ESP32S3=1
67-
;-D USS_LEFT_PIN=1
68-
;-D USS_RIGHT_PIN=14
6968
-D SDA_PIN=5
7069
-D SCL_PIN=6
7170

0 commit comments

Comments
 (0)