Skip to content

Commit

Permalink
fix uninitialized calibration values and temperature coefficients cau…
Browse files Browse the repository at this point in the history
…sing all sort of issues on ESP32C3
  • Loading branch information
l0ud committed Jul 26, 2023
1 parent ed74944 commit ced549d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/configuration/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

namespace SlimeVR {
namespace Configuration {
CalibrationConfig Configuration::m_EmptyCalibration = {NONE};

void Configuration::setup() {
if (m_Loaded) {
return;
Expand Down Expand Up @@ -140,7 +138,7 @@ namespace SlimeVR {

CalibrationConfig Configuration::getCalibration(size_t sensorID) const {
if (sensorID >= m_Calibrations.size()) {
return m_EmptyCalibration;
return {};
}

return m_Calibrations.at(sensorID);
Expand All @@ -150,7 +148,7 @@ namespace SlimeVR {
size_t currentCalibrations = m_Calibrations.size();

if (sensorID >= currentCalibrations) {
m_Calibrations.resize(sensorID + 1, m_EmptyCalibration);
m_Calibrations.resize(sensorID + 1);
}

m_Calibrations[sensorID] = config;
Expand Down
2 changes: 0 additions & 2 deletions src/configuration/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ namespace SlimeVR {
std::vector<CalibrationConfig> m_Calibrations;

Logging::Logger m_Logger = Logging::Logger("Configuration");

static CalibrationConfig m_EmptyCalibration;
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/bmi160sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ class BMI160Sensor : public Sensor {
double gscaleY = BMI160_GSCALE;
double gscaleZ = BMI160_GSCALE;

double GOxyzStaticTempCompensated[3];
double GOxyzStaticTempCompensated[3] = {0.0, 0.0, 0.0};

bool isGyroCalibrated = false;
bool isAccelCalibrated = false;
bool isMagCalibrated = false;

SlimeVR::Configuration::BMI160CalibrationConfig m_Calibration;
SlimeVR::Configuration::BMI160CalibrationConfig m_Calibration = {};
};

#endif
2 changes: 1 addition & 1 deletion src/sensors/icm20948sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ICM20948Sensor : public Sensor
icm_20948_DMP_data_t dmpData{};
icm_20948_DMP_data_t dmpDataTemp{};

SlimeVR::Configuration::ICM20948CalibrationConfig m_Calibration;
SlimeVR::Configuration::ICM20948CalibrationConfig m_Calibration = {};

void saveCalibration(bool repeat);
void loadCalibration();
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/mpu6050sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MPU6050Sensor : public Sensor
uint8_t fifoBuffer[64]{}; // FIFO storage buffer

#ifndef IMU_MPU6050_RUNTIME_CALIBRATION
SlimeVR::Configuration::MPU6050CalibrationConfig m_Calibration;
SlimeVR::Configuration::MPU6050CalibrationConfig m_Calibration = {};
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/mpu9250sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MPU9250Sensor : public Sensor
// Loop timing globals
float deltat = 0; // sample time in seconds

SlimeVR::Configuration::MPU9250CalibrationConfig m_Calibration;
SlimeVR::Configuration::MPU9250CalibrationConfig m_Calibration = {};

// outputs to respective member variables
void parseAccelData(int16_t data[3]);
Expand Down

0 comments on commit ced549d

Please sign in to comment.