Skip to content

Commit a9fea7f

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

File tree

9 files changed

+82
-40
lines changed

9 files changed

+82
-40
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: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@
66
#include <ArduinoJson.h>
77
#include <utils/math_utils.h>
88

9+
#if FT_ENABLED(USE_MPU6050)
910
#include <MPU6050_6Axis_MotionApps612.h>
11+
#endif
12+
13+
#if FT_ENABLED(USE_BNO055)
14+
#include <Adafruit_BNO055.h>
15+
#endif
1016

1117
class IMU {
1218
public:
13-
IMU() {}
19+
IMU()
20+
#if FT_ENABLED(USE_BNO055)
21+
: _imu(55, 0x29)
22+
#endif
23+
{
24+
}
1425
bool initialize() {
1526
#if FT_ENABLED(USE_MPU6050)
1627
_imu.initialize();
@@ -21,6 +32,13 @@ class IMU {
2132
_imu.setI2CMasterModeEnabled(false);
2233
_imu.setI2CBypassEnabled(true);
2334
_imu.setSleepEnabled(false);
35+
#endif
36+
#if FT_ENABLED(USE_BNO055)
37+
imu_success = _imu.begin();
38+
if (!imu_success) {
39+
return false;
40+
}
41+
_imu.setExtCrystalUse(true);
2442
#endif
2543
return true;
2644
}
@@ -32,17 +50,28 @@ class IMU {
3250
_imu.dmpGetQuaternion(&q, fifoBuffer);
3351
_imu.dmpGetGravity(&gravity, &q);
3452
_imu.dmpGetYawPitchRoll(ypr, &q, &gravity);
53+
ypr[0] *= 180 / M_PI;
54+
ypr[1] *= 180 / M_PI;
55+
ypr[2] *= 180 / M_PI;
3556
return updated;
3657
#endif
58+
#if FT_ENABLED(USE_BNO055)
59+
sensors_event_t event;
60+
_imu.getEvent(&event);
61+
ypr[0] = (float)event.orientation.x;
62+
ypr[1] = (float)event.orientation.y;
63+
ypr[2] = (float)event.orientation.z;
64+
#endif
65+
return true;
3766
}
3867

3968
float getTemperature() { return imu_success ? imu_temperature : -1; }
4069

41-
float getAngleX() { return imu_success ? ypr[0] * 180 / M_PI : 0; }
70+
float getAngleX() { return imu_success ? ypr[0] : 0; }
4271

43-
float getAngleY() { return imu_success ? ypr[1] * 180 / M_PI : 0; }
72+
float getAngleY() { return imu_success ? ypr[1] : 0; }
4473

45-
float getAngleZ() { return imu_success ? ypr[2] * 180 / M_PI : 0; }
74+
float getAngleZ() { return imu_success ? ypr[2] : 0; }
4675

4776
void readIMU(JsonObject& root) {
4877
if (!imu_success) return;
@@ -60,6 +89,9 @@ class IMU {
6089
Quaternion q;
6190
uint8_t fifoBuffer[64];
6291
VectorFloat gravity;
92+
#endif
93+
#if FT_ENABLED(USE_BNO055)
94+
Adafruit_BNO055 _imu;
6395
#endif
6496
bool imu_success {false};
6597
float ypr[3];

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

Lines changed: 12 additions & 13 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);
@@ -196,7 +196,6 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
196196

197197
void emitSonar() {
198198
#if FT_ENABLED(USE_USS)
199-
200199
char output[16];
201200
snprintf(output, sizeof(output), "[%.1f,%.1f]", _left_distance, _right_distance);
202201
socket.emit("sonar", output);
@@ -214,13 +213,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
214213

215214
JsonDocument doc;
216215
char message[MAX_ESP_IMU_SIZE];
217-
#if FT_ENABLED(USE_MPU6050)
216+
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
218217
IMU _imu;
219218
#endif
220-
#if FT_ENABLED(USE_MAG)
219+
#if FT_ENABLED(USE_HMC5883)
221220
Magnetometer _mag;
222221
#endif
223-
#if FT_ENABLED(USE_BMP)
222+
#if FT_ENABLED(USE_BMP180)
224223
Barometer _bmp;
225224
#endif
226225
#if FT_ENABLED(USE_USS)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ class ServoController : public StatefulService<ServoSettings> {
111111
float angle = servo.direction * angles[i] + servo.centerAngle;
112112
uint16_t pwm = angle * servo.conversion + servo.centerPwm;
113113
if (pwm < 125 || pwm > 600) {
114-
ESP_LOGE("ServoController", "Servo %d, Invalid PWM value %d", i, pwm);
115114
continue;
116115
}
117116
pwms[i] = pwm;

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)