🎍 Updates feature flags and adds BNO055
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
const i2cDevices = [
|
const i2cDevices = [
|
||||||
{ address: 30, part_number: 'HMC5883', name: '3-Axis Digital Compass/Magnetometer IC' },
|
{ address: 30, part_number: 'HMC5883', name: '3-Axis Digital Compass/Magnetometer IC' },
|
||||||
|
{ address: 41, part_number: 'BNO055', name: '9-Axis Absolute Orientation Sensor' },
|
||||||
{ address: 64, part_number: 'PCA9685', name: '16-channel PWM driver default address' },
|
{ address: 64, part_number: 'PCA9685', name: '16-channel PWM driver default address' },
|
||||||
{ address: 72, part_number: 'ADS1115', name: '4-channel 16-bit ADC' },
|
{ address: 72, part_number: 'ADS1115', name: '4-channel 16-bit ADC' },
|
||||||
{
|
{
|
||||||
|
|||||||
+6
-5
@@ -1,15 +1,16 @@
|
|||||||
[features]
|
[features]
|
||||||
build_flags =
|
build_flags =
|
||||||
-D USE_SLEEP=0
|
-D USE_SLEEP=1
|
||||||
-D USE_UPLOAD_FIRMWARE=1
|
-D USE_UPLOAD_FIRMWARE=0
|
||||||
-D USE_DOWNLOAD_FIRMWARE=0
|
-D USE_DOWNLOAD_FIRMWARE=0
|
||||||
-D USE_MOTION=1
|
-D USE_MOTION=1
|
||||||
-D USE_MDNS=1
|
-D USE_MDNS=1
|
||||||
|
|
||||||
; Hardware specific
|
; Hardware specific
|
||||||
-D USE_MAG=0
|
-D USE_HMC5883=0
|
||||||
-D USE_BMP=0
|
-D USE_BMP180=0
|
||||||
-D USE_MPU6050=0
|
-D USE_MPU6050=0
|
||||||
-D USE_WS2812=1
|
-D USE_WS2812=1
|
||||||
|
-D USE_BNO055=1
|
||||||
-D USE_USS=0
|
-D USE_USS=0
|
||||||
-D USE_SERVO=1
|
-D USE_PCA9685=1
|
||||||
@@ -61,6 +61,7 @@ class Spot {
|
|||||||
// act
|
// act
|
||||||
void updateActuators() {
|
void updateActuators() {
|
||||||
if (updatedMotion) _servoController.setAngles(_motionService.getAngles());
|
if (updatedMotion) _servoController.setAngles(_motionService.getAngles());
|
||||||
|
updatedMotion = false;
|
||||||
|
|
||||||
_servoController.updateServoState();
|
_servoController.updateServoState();
|
||||||
#if FT_ENABLED(USE_WS2812)
|
#if FT_ENABLED(USE_WS2812)
|
||||||
@@ -71,7 +72,7 @@ class Spot {
|
|||||||
// communicate
|
// communicate
|
||||||
void emitTelemetry() {
|
void emitTelemetry() {
|
||||||
if (updatedMotion) EXECUTE_EVERY_N_MS(100, { _motionService.emitAngles(); });
|
if (updatedMotion) EXECUTE_EVERY_N_MS(100, { _motionService.emitAngles(); });
|
||||||
EXECUTE_EVERY_N_MS(1000, { _peripherals.emitIMU(); });
|
EXECUTE_EVERY_N_MS(250, { _peripherals.emitIMU(); });
|
||||||
// _peripherals.emitSonar();
|
// _peripherals.emitSonar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ class Spot {
|
|||||||
bool updatedMotion = false;
|
bool updatedMotion = false;
|
||||||
|
|
||||||
const char *_appName = APP_NAME;
|
const char *_appName = APP_NAME;
|
||||||
const u_int16_t _numberEndpoints = 115;
|
const u_int16_t _numberEndpoints = 116;
|
||||||
const u_int32_t _maxFileUpload = 2300000; // 2.3 MB
|
const u_int32_t _maxFileUpload = 2300000; // 2.3 MB
|
||||||
const uint16_t _port = 80;
|
const uint16_t _port = 80;
|
||||||
|
|
||||||
@@ -110,7 +111,6 @@ class Spot {
|
|||||||
void loop();
|
void loop();
|
||||||
static void _loopImpl(void *_this) { static_cast<Spot *>(_this)->loop(); }
|
static void _loopImpl(void *_this) { static_cast<Spot *>(_this)->loop(); }
|
||||||
void setupServer();
|
void setupServer();
|
||||||
void setupMDNS();
|
|
||||||
void startServices();
|
void startServices();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,15 @@ void printFeatureConfiguration() {
|
|||||||
ESP_LOGI("Features", "USE_MOTION: %s", USE_MOTION ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_MOTION: %s", USE_MOTION ? "enabled" : "disabled");
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
|
ESP_LOGI("Features", "USE_BNO055: %s", USE_BNO055 ? "enabled" : "disabled");
|
||||||
ESP_LOGI("Features", "USE_MPU6050: %s", USE_MPU6050 ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_MPU6050: %s", USE_MPU6050 ? "enabled" : "disabled");
|
||||||
ESP_LOGI("Features", "USE_MAG: %s", USE_MAG ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_HMC5883: %s", USE_HMC5883 ? "enabled" : "disabled");
|
||||||
ESP_LOGI("Features", "USE_BMP: %s", USE_BMP ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_BMP180: %s", USE_BMP180 ? "enabled" : "disabled");
|
||||||
ESP_LOGI("Features", "USE_USS: %s", USE_USS ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_USS: %s", USE_USS ? "enabled" : "disabled");
|
||||||
ESP_LOGI("Features", "USE_GPS: %s", USE_GPS ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_GPS: %s", USE_GPS ? "enabled" : "disabled");
|
||||||
|
|
||||||
// Peripherals
|
// Peripherals
|
||||||
ESP_LOGI("Features", "USE_SERVO: %s", USE_SERVO ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_PCA9685: %s", USE_PCA9685 ? "enabled" : "disabled");
|
||||||
ESP_LOGI("Features", "USE_WS2812: %s", USE_WS2812 ? "enabled" : "disabled");
|
ESP_LOGI("Features", "USE_WS2812: %s", USE_WS2812 ? "enabled" : "disabled");
|
||||||
|
|
||||||
// Web services
|
// Web services
|
||||||
@@ -38,12 +39,12 @@ void features(JsonObject &root) {
|
|||||||
root["download_firmware"] = USE_DOWNLOAD_FIRMWARE;
|
root["download_firmware"] = USE_DOWNLOAD_FIRMWARE;
|
||||||
root["sleep"] = USE_SLEEP;
|
root["sleep"] = USE_SLEEP;
|
||||||
root["camera"] = USE_CAMERA;
|
root["camera"] = USE_CAMERA;
|
||||||
root["imu"] = USE_MPU6050;
|
root["imu"] = USE_MPU6050 || USE_BNO055;
|
||||||
root["mag"] = USE_MAG;
|
root["mag"] = USE_HMC5883 || USE_BNO055;
|
||||||
root["bmp"] = USE_BMP;
|
root["bmp"] = USE_BMP180;
|
||||||
root["sonar"] = USE_USS;
|
root["sonar"] = USE_USS;
|
||||||
root["motion"] = USE_MOTION;
|
root["motion"] = USE_MOTION;
|
||||||
root["servo"] = USE_SERVO;
|
root["servo"] = USE_PCA9685;
|
||||||
root["ws2812"] = USE_WS2812;
|
root["ws2812"] = USE_WS2812;
|
||||||
root["mdns"] = USE_MDNS;
|
root["mdns"] = USE_MDNS;
|
||||||
root["embed_www"] = EMBED_WWW;
|
root["embed_www"] = EMBED_WWW;
|
||||||
|
|||||||
@@ -29,17 +29,22 @@
|
|||||||
|
|
||||||
// ESP32 IMU on by default
|
// ESP32 IMU on by default
|
||||||
#ifndef USE_MPU6050
|
#ifndef USE_MPU6050
|
||||||
#define USE_MPU6050 1
|
#define USE_MPU6050 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ESP32 IMU on by default
|
||||||
|
#ifndef USE_BNO055
|
||||||
|
#define USE_BNO055 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ESP32 magnetometer on by default
|
// ESP32 magnetometer on by default
|
||||||
#ifndef USE_MAG
|
#ifndef USE_HMC5883
|
||||||
#define USE_MAG 0
|
#define USE_HMC5883 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ESP32 barometer off by default
|
// ESP32 barometer off by default
|
||||||
#ifndef USE_BMP
|
#ifndef USE_BMP180
|
||||||
#define USE_BMP 0
|
#define USE_BMP180 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ESP32 SONAR off by default
|
// ESP32 SONAR off by default
|
||||||
@@ -47,6 +52,11 @@
|
|||||||
#define USE_USS 0
|
#define USE_USS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// PCA9685 Servo controller on by default
|
||||||
|
#ifndef USE_PCA9685
|
||||||
|
#define USE_PCA9685 1
|
||||||
|
#endif
|
||||||
|
|
||||||
// ESP32 GPS off by default
|
// ESP32 GPS off by default
|
||||||
#ifndef USE_GPS
|
#ifndef USE_GPS
|
||||||
#define USE_GPS 0
|
#define USE_GPS 0
|
||||||
|
|||||||
@@ -6,11 +6,22 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <utils/math_utils.h>
|
#include <utils/math_utils.h>
|
||||||
|
|
||||||
|
#if FT_ENABLED(USE_MPU6050)
|
||||||
#include <MPU6050_6Axis_MotionApps612.h>
|
#include <MPU6050_6Axis_MotionApps612.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FT_ENABLED(USE_BNO055)
|
||||||
|
#include <Adafruit_BNO055.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class IMU {
|
class IMU {
|
||||||
public:
|
public:
|
||||||
IMU() {}
|
IMU()
|
||||||
|
#if FT_ENABLED(USE_BNO055)
|
||||||
|
: _imu(55, 0x29)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
}
|
||||||
bool initialize() {
|
bool initialize() {
|
||||||
#if FT_ENABLED(USE_MPU6050)
|
#if FT_ENABLED(USE_MPU6050)
|
||||||
_imu.initialize();
|
_imu.initialize();
|
||||||
@@ -21,6 +32,13 @@ class IMU {
|
|||||||
_imu.setI2CMasterModeEnabled(false);
|
_imu.setI2CMasterModeEnabled(false);
|
||||||
_imu.setI2CBypassEnabled(true);
|
_imu.setI2CBypassEnabled(true);
|
||||||
_imu.setSleepEnabled(false);
|
_imu.setSleepEnabled(false);
|
||||||
|
#endif
|
||||||
|
#if FT_ENABLED(USE_BNO055)
|
||||||
|
imu_success = _imu.begin();
|
||||||
|
if (!imu_success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_imu.setExtCrystalUse(true);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -32,17 +50,28 @@ class IMU {
|
|||||||
_imu.dmpGetQuaternion(&q, fifoBuffer);
|
_imu.dmpGetQuaternion(&q, fifoBuffer);
|
||||||
_imu.dmpGetGravity(&gravity, &q);
|
_imu.dmpGetGravity(&gravity, &q);
|
||||||
_imu.dmpGetYawPitchRoll(ypr, &q, &gravity);
|
_imu.dmpGetYawPitchRoll(ypr, &q, &gravity);
|
||||||
|
ypr[0] *= 180 / M_PI;
|
||||||
|
ypr[1] *= 180 / M_PI;
|
||||||
|
ypr[2] *= 180 / M_PI;
|
||||||
return updated;
|
return updated;
|
||||||
#endif
|
#endif
|
||||||
|
#if FT_ENABLED(USE_BNO055)
|
||||||
|
sensors_event_t event;
|
||||||
|
_imu.getEvent(&event);
|
||||||
|
ypr[0] = (float)event.orientation.x;
|
||||||
|
ypr[1] = (float)event.orientation.y;
|
||||||
|
ypr[2] = (float)event.orientation.z;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getTemperature() { return imu_success ? imu_temperature : -1; }
|
float getTemperature() { return imu_success ? imu_temperature : -1; }
|
||||||
|
|
||||||
float getAngleX() { return imu_success ? ypr[0] * 180 / M_PI : 0; }
|
float getAngleX() { return imu_success ? ypr[0] : 0; }
|
||||||
|
|
||||||
float getAngleY() { return imu_success ? ypr[1] * 180 / M_PI : 0; }
|
float getAngleY() { return imu_success ? ypr[1] : 0; }
|
||||||
|
|
||||||
float getAngleZ() { return imu_success ? ypr[2] * 180 / M_PI : 0; }
|
float getAngleZ() { return imu_success ? ypr[2] : 0; }
|
||||||
|
|
||||||
void readIMU(JsonObject& root) {
|
void readIMU(JsonObject& root) {
|
||||||
if (!imu_success) return;
|
if (!imu_success) return;
|
||||||
@@ -60,6 +89,9 @@ class IMU {
|
|||||||
Quaternion q;
|
Quaternion q;
|
||||||
uint8_t fifoBuffer[64];
|
uint8_t fifoBuffer[64];
|
||||||
VectorFloat gravity;
|
VectorFloat gravity;
|
||||||
|
#endif
|
||||||
|
#if FT_ENABLED(USE_BNO055)
|
||||||
|
Adafruit_BNO055 _imu;
|
||||||
#endif
|
#endif
|
||||||
bool imu_success {false};
|
bool imu_success {false};
|
||||||
float ypr[3];
|
float ypr[3];
|
||||||
|
|||||||
@@ -67,13 +67,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
|||||||
|
|
||||||
updatePins();
|
updatePins();
|
||||||
|
|
||||||
#if FT_ENABLED(USE_MPU6050)
|
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
|
||||||
if (!_imu.initialize()) ESP_LOGE("IMUService", "IMU initialize failed");
|
if (!_imu.initialize()) ESP_LOGE("IMUService", "IMU initialize failed");
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_MAG)
|
#if FT_ENABLED(USE_HMC5883)
|
||||||
if (!_mag.initialize()) ESP_LOGE("IMUService", "MAG initialize failed");
|
if (!_mag.initialize()) ESP_LOGE("IMUService", "MAG initialize failed");
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_BMP)
|
#if FT_ENABLED(USE_BMP180)
|
||||||
if (!_bmp.initialize()) ESP_LOGE("IMUService", "BMP initialize failed");
|
if (!_bmp.initialize()) ESP_LOGE("IMUService", "BMP initialize failed");
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_USS)
|
#if FT_ENABLED(USE_USS)
|
||||||
@@ -137,7 +137,7 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
|||||||
/* IMU FUNCTIONS */
|
/* IMU FUNCTIONS */
|
||||||
bool readIMU() {
|
bool readIMU() {
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
#if FT_ENABLED(USE_MPU6050)
|
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
updated = _imu.readIMU();
|
updated = _imu.readIMU();
|
||||||
endTransaction();
|
endTransaction();
|
||||||
@@ -147,7 +147,7 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
|||||||
|
|
||||||
bool readMag() {
|
bool readMag() {
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
#if FT_ENABLED(USE_MAG)
|
#if FT_ENABLED(USE_HMC5883)
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
updated = _mag.readMagnetometer();
|
updated = _mag.readMagnetometer();
|
||||||
endTransaction();
|
endTransaction();
|
||||||
@@ -157,7 +157,7 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
|||||||
|
|
||||||
bool readBMP() {
|
bool readBMP() {
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
#if FT_ENABLED(USE_BMP)
|
#if FT_ENABLED(USE_BMP180)
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
updated = _bmp.readBarometer();
|
updated = _bmp.readBarometer();
|
||||||
endTransaction();
|
endTransaction();
|
||||||
@@ -181,13 +181,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
|||||||
void emitIMU() {
|
void emitIMU() {
|
||||||
doc.clear();
|
doc.clear();
|
||||||
JsonObject root = doc.to<JsonObject>();
|
JsonObject root = doc.to<JsonObject>();
|
||||||
#if FT_ENABLED(USE_MPU6050)
|
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
|
||||||
_imu.readIMU(root);
|
_imu.readIMU(root);
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_MAG)
|
#if FT_ENABLED(USE_HMC5883)
|
||||||
_mag.readMagnetometer(root);
|
_mag.readMagnetometer(root);
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_BMP)
|
#if FT_ENABLED(USE_BMP180)
|
||||||
_bmp.readBarometer(root);
|
_bmp.readBarometer(root);
|
||||||
#endif
|
#endif
|
||||||
serializeJson(doc, message);
|
serializeJson(doc, message);
|
||||||
@@ -196,7 +196,6 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
|||||||
|
|
||||||
void emitSonar() {
|
void emitSonar() {
|
||||||
#if FT_ENABLED(USE_USS)
|
#if FT_ENABLED(USE_USS)
|
||||||
|
|
||||||
char output[16];
|
char output[16];
|
||||||
snprintf(output, sizeof(output), "[%.1f,%.1f]", _left_distance, _right_distance);
|
snprintf(output, sizeof(output), "[%.1f,%.1f]", _left_distance, _right_distance);
|
||||||
socket.emit("sonar", output);
|
socket.emit("sonar", output);
|
||||||
@@ -214,13 +213,13 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
|
|||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
char message[MAX_ESP_IMU_SIZE];
|
char message[MAX_ESP_IMU_SIZE];
|
||||||
#if FT_ENABLED(USE_MPU6050)
|
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
|
||||||
IMU _imu;
|
IMU _imu;
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_MAG)
|
#if FT_ENABLED(USE_HMC5883)
|
||||||
Magnetometer _mag;
|
Magnetometer _mag;
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_BMP)
|
#if FT_ENABLED(USE_BMP180)
|
||||||
Barometer _bmp;
|
Barometer _bmp;
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_USS)
|
#if FT_ENABLED(USE_USS)
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ class ServoController : public StatefulService<ServoSettings> {
|
|||||||
float angle = servo.direction * angles[i] + servo.centerAngle;
|
float angle = servo.direction * angles[i] + servo.centerAngle;
|
||||||
uint16_t pwm = angle * servo.conversion + servo.centerPwm;
|
uint16_t pwm = angle * servo.conversion + servo.centerPwm;
|
||||||
if (pwm < 125 || pwm > 600) {
|
if (pwm < 125 || pwm > 600) {
|
||||||
ESP_LOGE("ServoController", "Servo %d, Invalid PWM value %d", i, pwm);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pwms[i] = pwm;
|
pwms[i] = pwm;
|
||||||
|
|||||||
+1
-2
@@ -14,6 +14,7 @@ data_dir = esp32/data
|
|||||||
src_dir = esp32/src
|
src_dir = esp32/src
|
||||||
include_dir = esp32/include
|
include_dir = esp32/include
|
||||||
lib_dir = esp32/lib
|
lib_dir = esp32/lib
|
||||||
|
test_dir = esp32/test
|
||||||
extra_configs =
|
extra_configs =
|
||||||
esp32/factory_settings.ini
|
esp32/factory_settings.ini
|
||||||
esp32/features.ini
|
esp32/features.ini
|
||||||
@@ -64,8 +65,6 @@ build_flags =
|
|||||||
${env.build_flags}
|
${env.build_flags}
|
||||||
-D USE_CAMERA=1
|
-D USE_CAMERA=1
|
||||||
-D CAMERA_MODEL_XIAO_ESP32S3=1
|
-D CAMERA_MODEL_XIAO_ESP32S3=1
|
||||||
;-D USS_LEFT_PIN=1
|
|
||||||
;-D USS_RIGHT_PIN=14
|
|
||||||
-D SDA_PIN=5
|
-D SDA_PIN=5
|
||||||
-D SCL_PIN=6
|
-D SCL_PIN=6
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user