🪰 Adds angle, heading, altitude, pressure and temperature
This commit is contained in:
@@ -111,14 +111,6 @@
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets: [
|
||||
{
|
||||
label: 'IMU temperature',
|
||||
borderColor: daisyColor('--p'),
|
||||
backgroundColor: daisyColor('--p', 50),
|
||||
borderWidth: 2,
|
||||
data: $imu.imu_temp,
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
label: 'Barometer temperature',
|
||||
borderColor: daisyColor('--s'),
|
||||
@@ -257,14 +249,13 @@
|
||||
angleChart.options.scales!.y!.max = Math.max(Math.max(...$imu.x), Math.max(...$imu.y), Math.max(...$imu.z)) + 1;
|
||||
angleChart.update('none');
|
||||
|
||||
tempChart.data.labels = $imu.imu_temp;
|
||||
tempChart.data.datasets[0].data = $imu.imu_temp;
|
||||
tempChart.data.datasets[1].data = $imu.bmp_temp;
|
||||
tempChart.options.scales!.y!.min = Math.min(Math.min(...$imu.imu_temp), Math.min(...$imu.bmp_temp)) - 1;
|
||||
tempChart.options.scales!.y!.max = Math.max(Math.max(...$imu.imu_temp), Math.max(...$imu.bmp_temp)) + 1;
|
||||
tempChart.data.labels = $imu.bmp_temp;
|
||||
tempChart.data.datasets[0].data = $imu.bmp_temp;
|
||||
tempChart.options.scales!.y!.min = Math.min(...$imu.bmp_temp) - 1;
|
||||
tempChart.options.scales!.y!.max = Math.max(...$imu.bmp_temp) + 1;
|
||||
tempChart.update('none');
|
||||
|
||||
altitudeChart.data.labels = $imu.imu_temp;
|
||||
altitudeChart.data.labels = $imu.altitude;
|
||||
altitudeChart.data.datasets[0].data = $imu.altitude;
|
||||
altitudeChart.options.scales!.y!.min = Math.min(Math.min(...$imu.altitude)) - 1;
|
||||
altitudeChart.options.scales!.y!.max = Math.max(Math.max(...$imu.altitude)) + 1;
|
||||
|
||||
@@ -12,3 +12,4 @@ build_flags =
|
||||
-D FT_MAG=1
|
||||
-D FT_BMP=1
|
||||
-D FT_GPS=1
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ Adafruit_HMC5883_Unified::Adafruit_HMC5883_Unified(int32_t sensorID) {
|
||||
/**************************************************************************/
|
||||
bool Adafruit_HMC5883_Unified::begin() {
|
||||
// Enable I2C
|
||||
Wire.begin();
|
||||
// Wire.begin();
|
||||
|
||||
// Enable the magnetometer
|
||||
write8(HMC5883_ADDRESS_MAG, HMC5883_REGISTER_MAG_MR_REG_M, 0x00);
|
||||
|
||||
@@ -66,7 +66,9 @@ ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server,
|
||||
_fileExplorer(server, &_securitySettingsService),
|
||||
_motionService(_server, &_socket, &_securitySettingsService,&_taskManager),
|
||||
_deviceConfiguration(server, &ESPFS, &_securitySettingsService, &_socket),
|
||||
#if FT_ENABLED(FT_IMU) || FT_ENABLED(FT_MAG) || FT_ENABLED(FT_BMP)
|
||||
_imuService(&_socket)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@@ -208,7 +210,7 @@ void ESP32SvelteKit::startServices() {
|
||||
_cameraSettingsService.begin();
|
||||
#endif
|
||||
_deviceConfiguration.begin();
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
#if FT_ENABLED(FT_IMU) || FT_ENABLED(FT_MAG) || FT_ENABLED(FT_BMP)
|
||||
_imuService.begin();
|
||||
#endif
|
||||
}
|
||||
@@ -223,7 +225,7 @@ void IRAM_ATTR ESP32SvelteKit::_loop() {
|
||||
#if FT_ENABLED(FT_ANALYTICS)
|
||||
_analyticsService.loop();
|
||||
#endif
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
#if FT_ENABLED(FT_IMU) || FT_ENABLED(FT_MAG) || FT_ENABLED(FT_BMP)
|
||||
_imuService.loop();
|
||||
#endif
|
||||
_motionService.loop();
|
||||
|
||||
@@ -186,7 +186,7 @@ public:
|
||||
return &_deviceConfiguration;
|
||||
}
|
||||
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
#if FT_ENABLED(FT_IMU) || FT_ENABLED(FT_MAG) || FT_ENABLED(FT_BMP)
|
||||
IMUService *getIMUService()
|
||||
{
|
||||
return &_imuService;
|
||||
@@ -255,7 +255,7 @@ private:
|
||||
CameraSettingsService _cameraSettingsService;
|
||||
#endif
|
||||
DeviceConfigurationService _deviceConfiguration;
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
#if FT_ENABLED(FT_IMU) || FT_ENABLED(FT_MAG) || FT_ENABLED(FT_BMP)
|
||||
IMUService _imuService;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
#define FT_IMU 1
|
||||
#endif
|
||||
|
||||
// ESP32 magnetometer off by default
|
||||
// ESP32 magnetometer on by default
|
||||
#ifndef FT_MAG
|
||||
#define FT_MAG 0
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <MPU6050_light.h>
|
||||
#include "MPU6050_6Axis_MotionApps612.h"
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BMP085_U.h>
|
||||
#include <Adafruit_HMC5883_U.h>
|
||||
@@ -16,9 +16,6 @@ class IMUService
|
||||
public:
|
||||
IMUService(EventSocket *socket)
|
||||
:
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
_imu(Wire),
|
||||
#endif
|
||||
#if FT_ENABLED(FT_MAG)
|
||||
_mag(12345),
|
||||
#endif
|
||||
@@ -32,12 +29,16 @@ public:
|
||||
{
|
||||
_socket->registerEvent(EVENT_IMU);
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
byte status = _imu.begin();
|
||||
imu_success = status == 0;
|
||||
if(status != 0) {
|
||||
ESP_LOGE("IMUService", "MPU initialize failed: %d", status);
|
||||
_imu.initialize();
|
||||
imu_success = _imu.testConnection();
|
||||
devStatus = _imu.dmpInitialize();
|
||||
if(!imu_success) {
|
||||
ESP_LOGE("IMUService", "MPU initialize failed");
|
||||
}
|
||||
calibrate();
|
||||
_imu.setDMPEnabled(true);
|
||||
_imu.setI2CMasterModeEnabled(false);
|
||||
_imu.setI2CBypassEnabled(true);
|
||||
_imu.setSleepEnabled(false);
|
||||
#endif
|
||||
#if FT_ENABLED(FT_MAG)
|
||||
mag_success = _mag.begin();
|
||||
@@ -59,25 +60,27 @@ public:
|
||||
}
|
||||
|
||||
float getTemp() {
|
||||
return imu_success ? _imu.getTemp() : -1;
|
||||
return imu_success ? imu_temperature : -1;
|
||||
}
|
||||
|
||||
float getAngleX() {
|
||||
return imu_success ? _imu.getAngleX() : -1;
|
||||
return imu_success ? ypr[0] * 180/M_PI : -1;
|
||||
}
|
||||
|
||||
float getAngleY() {
|
||||
return imu_success ? _imu.getAngleY() : -1;
|
||||
return imu_success ? ypr[1] * 180/M_PI : -1;
|
||||
}
|
||||
|
||||
float getAngleZ() {
|
||||
return imu_success ? _imu.getGyroZ() : -1;
|
||||
return imu_success ? ypr[2] * 180/M_PI : -1;
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
if (imu_success) {
|
||||
_imu.calcOffsets(true, true);
|
||||
}
|
||||
bool readIMU() {
|
||||
bool updated = imu_success && _imu.dmpGetCurrentFIFOPacket(fifoBuffer);
|
||||
_imu.dmpGetQuaternion(&q, fifoBuffer);
|
||||
_imu.dmpGetGravity(&gravity, &q);
|
||||
_imu.dmpGetYawPitchRoll(ypr, &q, &gravity);
|
||||
return updated;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -139,26 +142,29 @@ protected:
|
||||
|
||||
void updateImu() {
|
||||
doc.clear();
|
||||
bool newData = false;
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
if (imu_success){
|
||||
_imu.update();
|
||||
newData = imu_success && readIMU();
|
||||
if (imu_success) {
|
||||
doc["x"] = round2(getAngleX());
|
||||
doc["y"] = round2(getAngleY());
|
||||
doc["z"] = round2(getAngleZ());
|
||||
doc["imu_temp"] = round2(getTemp());
|
||||
// doc["imu_temp"] = round2(getTemp());
|
||||
}
|
||||
#endif
|
||||
#if FT_ENABLED(FT_MAG)
|
||||
if (mag_success) {
|
||||
doc["heading"] = round2(getHeading());
|
||||
}
|
||||
newData = newData || mag_success;
|
||||
if (mag_success) {
|
||||
doc["heading"] = round2(getHeading());
|
||||
}
|
||||
#endif
|
||||
#if FT_ENABLED(FT_BMP)
|
||||
if (bmp_success) {
|
||||
doc["pressure"] = round2(getPressure());
|
||||
doc["altitude"] = round2(getAltitude());
|
||||
doc["bmp_temp"] = round2(getTemperature());
|
||||
}
|
||||
newData = newData || bmp_success;
|
||||
if (bmp_success) {
|
||||
doc["pressure"] = round2(getPressure());
|
||||
doc["altitude"] = round2(getAltitude());
|
||||
doc["bmp_temp"] = round2(getTemperature());
|
||||
}
|
||||
#endif
|
||||
serializeJson(doc, message);
|
||||
_socket->emit(EVENT_IMU, message);
|
||||
@@ -168,6 +174,12 @@ private:
|
||||
#if FT_ENABLED(FT_IMU)
|
||||
MPU6050 _imu;
|
||||
bool imu_success {false};
|
||||
uint8_t devStatus {false};
|
||||
Quaternion q;
|
||||
uint8_t fifoBuffer[64];
|
||||
VectorFloat gravity;
|
||||
float ypr[3];
|
||||
float imu_temperature {-1};
|
||||
#endif
|
||||
#if FT_ENABLED(FT_MAG)
|
||||
Adafruit_HMC5883_Unified _mag;
|
||||
|
||||
+1463
-1465
File diff suppressed because it is too large
Load Diff
@@ -39,15 +39,12 @@ lib_deps =
|
||||
ArduinoJson@>=7.0.0
|
||||
https://github.com/theelims/PsychicMqttClient.git#0.1.1
|
||||
teckel12/NewPing@^1.9.7
|
||||
rfetick/MPU6050_light@^1.1.0
|
||||
jrowberg/I2Cdevlib-MPU6050@^1.0.0
|
||||
adafruit/Adafruit SSD1306@^2.5.7
|
||||
adafruit/Adafruit GFX Library@^1.11.5
|
||||
adafruit/Adafruit BusIO@^1.9.3
|
||||
adafruit/Adafruit PWM Servo Driver Library@^2.4.1
|
||||
SPI
|
||||
; thomasfredericks/Bounce2@ ^2.7.0
|
||||
; adafruit/Adafruit ADS1X15@^2.4.0
|
||||
; plageoj/UrlEncode@ ^1.0.1
|
||||
extra_scripts =
|
||||
pre:scripts/pre_build.py
|
||||
pre:scripts/build_app.py
|
||||
|
||||
Reference in New Issue
Block a user