diff --git a/src/debug.h b/src/debug.h index 79cc6ec5..7b6897cc 100644 --- a/src/debug.h +++ b/src/debug.h @@ -23,25 +23,62 @@ #ifndef SLIMEVR_DEBUG_H_ #define SLIMEVR_DEBUG_H_ #include "consts.h" +#include "defines.h" +#include "defines_bmi160.h" +#include "defines_sensitivity.h" #include "logging/Level.h" -#define IMU_MPU6050_RUNTIME_CALIBRATION // Comment to revert to - // startup/traditional-calibration -#define BNO_USE_ARVR_STABILIZATION \ - true // Set to false to disable stabilization for BNO085+ IMUs -#define USE_6_AXIS \ - true // uses 9 DoF (with mag) if false (only for ICM-20948 and BNO0xx currently) -#define LOAD_BIAS true // Loads the bias values from NVS on start -#define SAVE_BIAS true // Periodically saves bias calibration data to NVS -#define BIAS_DEBUG false // Printing BIAS Variables to serial (ICM20948 only) -#define ENABLE_TAP \ - false // monitor accel for (triple) tap events and send them. Uses more cpu, - // disable if problems. Server does nothing with value so disabled atm -#define SEND_ACCELERATION true // send linear acceleration to the server +#ifndef IMU_MPU6050_RUNTIME_CALIBRATION +// Set to false to revert to startup/traditional-calibration +#define IMU_MPU6050_RUNTIME_CALIBRATION true +#endif + +#ifndef BNO_USE_ARVR_STABILIZATION +// Set to false to disable stabilization for BNO085+ IMUs +#define BNO_USE_ARVR_STABILIZATION true +#endif + +#ifndef BNO_USE_MAGNETOMETER_CORRECTION +// Set to true to enable magnetometer correction for BNO08x IMUs. +// Only works with USE_6_AXIS set to true. +#define BNO_USE_MAGNETOMETER_CORRECTION false +#endif + +#ifndef USE_6_AXIS +// uses 9 DoF (with mag) if false (only for ICM-20948 and BNO0xx currently) +#define USE_6_AXIS true +#endif + +#ifndef LOAD_BIAS +// Loads the bias values from NVS on start +#define LOAD_BIAS true +#endif + +#ifndef SAVE_BIAS +// Periodically saves bias calibration data to NVS +#define SAVE_BIAS true +#endif +#ifndef BIAS_DEBUG +// Printing BIAS Variables to serial (ICM20948 only) +#define BIAS_DEBUG false +#endif + +#ifndef ENABLE_TAP +// monitor accel for (triple) tap events and send them. Uses more cpu, +// disable if problems. Server does nothing with value so disabled atm +#define ENABLE_TAP false +#endif + +#ifndef SEND_ACCELERATION +// send linear acceleration to the server +#define SEND_ACCELERATION true +#endif // Debug information +#ifndef LOG_LEVEL #define LOG_LEVEL LOG_LEVEL_DEBUG +#endif #if LOG_LEVEL == LOG_LEVEL_TRACE #define DEBUG_SENSOR @@ -49,50 +86,94 @@ #define DEBUG_CONFIGURATION #endif -#define serialDebug false // Set to true to get Serial output for debugging +// Set to true to get Serial output for debugging +#ifndef serialDebug +#define serialDebug false +#endif + +#ifndef serialBaudRate #define serialBaudRate 115200 +#endif + +#ifndef LED_INTERVAL_STANDBY #define LED_INTERVAL_STANDBY 10000 +#endif + +#ifndef PRINT_STATE_EVERY_MS #define PRINT_STATE_EVERY_MS 60000 +#endif // Determines how often we sample and send data +#ifndef samplingRateInMillis #define samplingRateInMillis 10 +#endif // Sleeping options +#ifndef POWERSAVING_MODE #define POWERSAVING_MODE POWER_SAVING_LEGACY // Minimum causes sporadic data pauses +#endif #if POWERSAVING_MODE >= POWER_SAVING_MINIMUM #define TARGET_LOOPTIME_MICROS (samplingRateInMillis * 1000) #endif // Packet bundling/aggregation +#ifndef PACKET_BUNDLING #define PACKET_BUNDLING PACKET_BUNDLING_BUFFERED +#endif + // Extra tunable for PACKET_BUNDLING_BUFFERED (10000us = 10ms timeout, 100hz target) +#ifndef PACKET_BUNDLING_BUFFER_SIZE_MICROS #define PACKET_BUNDLING_BUFFER_SIZE_MICROS 10000 +#endif // Setup for the Magnetometer +#ifndef useFullCalibrationMatrix #define useFullCalibrationMatrix true +#endif // Battery configuration +#ifndef batterySampleRate #define batterySampleRate 10000 +#endif +#ifndef BATTERY_LOW_VOLTAGE_DEEP_SLEEP #define BATTERY_LOW_VOLTAGE_DEEP_SLEEP false +#endif +#ifndef BATTERY_LOW_POWER_VOLTAGE #define BATTERY_LOW_POWER_VOLTAGE 3.3f // Voltage to raise error +#endif // Send updates over network only when changes are substantial // If "false" updates are sent at the sensor update rate (usually 100 TPS) // If "true" updates will be less frequent in the time of little motion // Experimental +#ifndef OPTIMIZE_UPDATES #define OPTIMIZE_UPDATES true +#endif +#ifndef I2C_SPEED #define I2C_SPEED 400000 +#endif +#ifndef COMPLIANCE_MODE #define COMPLIANCE_MODE true +#endif + #define USE_ATTENUATION COMPLIANCE_MODE&& ESP8266 +#ifndef ATTENUATION_N #define ATTENUATION_N 10.0 / 4.0 +#endif +#ifndef ATTENUATION_G #define ATTENUATION_G 14.0 / 4.0 +#endif +#ifndef ATTENUATION_B #define ATTENUATION_B 40.0 / 4.0 +#endif // Send inspection packets over the network to a profiler // Not recommended for production +#ifndef ENABLE_INSPECTION #define ENABLE_INSPECTION false +#endif #define PROTOCOL_VERSION 18 diff --git a/src/defines_bmi160.h b/src/defines_bmi160.h index 747656c8..10e45369 100644 --- a/src/defines_bmi160.h +++ b/src/defines_bmi160.h @@ -26,24 +26,34 @@ // BMI160 magnetometer type, applies to both main and aux trackers, mixed types are not // supported currently. If only 1 out of 2 trackers has a mag, tracker without a mag // should still function normally. NOT USED if USE_6_AXIS == true Pick one: +#ifndef BMI160_MAG_TYPE #define BMI160_MAG_TYPE BMI160_MAG_TYPE_HMC +#endif // #define BMI160_MAG_TYPE BMI160_MAG_TYPE_QMC // Use VQF instead of mahony sensor fusion. // Features: rest bias estimation, magnetic distortion rejection. +#ifndef BMI160_USE_VQF #define BMI160_USE_VQF true +#endif // Use BasicVQF instead of VQF (if BMI160_USE_VQF == true). // Disables the features above. +#ifndef BMI160_USE_BASIC_VQF #define BMI160_USE_BASIC_VQF false +#endif // Use temperature calibration. +#ifndef BMI160_USE_TEMPCAL #define BMI160_USE_TEMPCAL true +#endif // How long to run gyro calibration for. // Disables this calibration step if value is 0. // Default: 5 +#ifndef BMI160_CALIBRATION_GYRO_SECONDS #define BMI160_CALIBRATION_GYRO_SECONDS 5 +#endif // Calibration method options: // - Skip: disable this calibration step; @@ -52,22 +62,32 @@ // Default: ACCEL_CALIBRATION_METHOD_6POINT // #define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_SKIP // #define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_ROTATION +#ifndef BMI160_ACCEL_CALIBRATION_METHOD #define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_6POINT +#endif // How long to run magnetometer calibration for, if enabled and you have added a // magnetometer. Magnetometer not be used until you calibrate it. Disables this // calibration step if value is 0. NOT USED if USE_6_AXIS == true Default: 20 +#ifndef BMI160_CALIBRATION_MAG_SECONDS #define BMI160_CALIBRATION_MAG_SECONDS 20 +#endif // Send temperature to the server as AXXYY, // where XX is calibration progress from 0 to 60, and YY is temperature, // A is 1: not in calibration mode or 2: calibration in progress. +#ifndef BMI160_TEMPCAL_DEBUG #define BMI160_TEMPCAL_DEBUG false +#endif // Print debug info every second. +#ifndef BMI160_DEBUG #define BMI160_DEBUG false +#endif // Use sensitivity calibration. +#ifndef BMI160_USE_SENSCAL #define BMI160_USE_SENSCAL true +#endif -#endif \ No newline at end of file +#endif diff --git a/src/globals.h b/src/globals.h index 67eaac12..bdcc9072 100644 --- a/src/globals.h +++ b/src/globals.h @@ -25,11 +25,7 @@ #include -#include "consts.h" #include "debug.h" -#include "defines.h" -#include "defines_bmi160.h" -#include "defines_sensitivity.h" #ifndef SECOND_IMU #define SECOND_IMU IMU diff --git a/src/motionprocessing/GyroTemperatureCalibrator.h b/src/motionprocessing/GyroTemperatureCalibrator.h index 352bb0b9..0f2a78ea 100644 --- a/src/motionprocessing/GyroTemperatureCalibrator.h +++ b/src/motionprocessing/GyroTemperatureCalibrator.h @@ -34,24 +34,34 @@ // Degrees C // default: 15.0f +#ifndef TEMP_CALIBRATION_MIN #define TEMP_CALIBRATION_MIN 15.0f +#endif // Degrees C // default: 45.0f +#ifndef TEMP_CALIBRATION_MAX #define TEMP_CALIBRATION_MAX 45.0f +#endif // Snap calibration to every 1/2 of degree: 20.00, 20.50, 21.00, etc // default: 0.5f +#ifndef TEMP_CALIBRATION_STEP #define TEMP_CALIBRATION_STEP 0.5f +#endif // Record debug samples if current temperature is off by no more than this value; // if snapping point is 20.00 - samples will be recorded in range of 19.80 - 20.20 // default: 0.2f +#ifndef TEMP_CALIBRATION_MAX_DEVIATION_FROM_STEP #define TEMP_CALIBRATION_MAX_DEVIATION_FROM_STEP 0.2f +#endif // How long to average gyro samples for before saving a data point // default: 0.2f +#ifndef TEMP_CALIBRATION_SECONDS_PER_STEP #define TEMP_CALIBRATION_SECONDS_PER_STEP 0.2f +#endif #if IMU == IMU_ICM20948 // 16 bit 333 lsb/K, ~0.00508 degrees per bit @@ -91,7 +101,7 @@ struct GyroTemperatureCalibrationState { , tSum(0.0f) , xSum(0) , ySum(0) - , zSum(0){}; + , zSum(0) {} }; struct GyroTemperatureOffsetSample { diff --git a/src/motionprocessing/RestDetection.h b/src/motionprocessing/RestDetection.h index 33b98260..af8b6a18 100644 --- a/src/motionprocessing/RestDetection.h +++ b/src/motionprocessing/RestDetection.h @@ -8,7 +8,9 @@ #ifndef REST_DETECTION_H #define REST_DETECTION_H -// #define REST_DETECTION_DISABLE_LPF +#ifndef REST_DETECTION_DISABLE_LPF +#define REST_DETECTION_DISABLE_LPF false +#endif #include #include @@ -54,7 +56,7 @@ class RestDetection { setup(); } -#ifndef REST_DETECTION_DISABLE_LPF +#if !REST_DETECTION_DISABLE_LPF void filterInitialState( sensor_real_t x0, const double b[3], @@ -118,7 +120,7 @@ class RestDetection { #endif void updateGyr(const sensor_real_t gyr[3]) { -#ifdef REST_DETECTION_DISABLE_LPF +#if REST_DETECTION_DISABLE_LPF gyrLastSquaredDeviation = square(gyr[0] - lastSample.gyr[0]) + square(gyr[1] - lastSample.gyr[1]) + square(gyr[2] - lastSample.gyr[2]); @@ -168,7 +170,7 @@ class RestDetection { return; } -#ifdef REST_DETECTION_DISABLE_LPF +#if REST_DETECTION_DISABLE_LPF accLastSquaredDeviation = square(acc[0] - lastSample.acc[0]) + square(acc[1] - lastSample.acc[1]) + square(acc[2] - lastSample.acc[2]); @@ -216,7 +218,7 @@ class RestDetection { bool getRestDetected() { return restDetected; } -#ifndef REST_DETECTION_DISABLE_LPF +#if !REST_DETECTION_DISABLE_LPF void resetState() { restDetected = false; @@ -251,7 +253,7 @@ class RestDetection { #endif void setup() { -#ifndef REST_DETECTION_DISABLE_LPF +#if !REST_DETECTION_DISABLE_LPF assert(gyrTs > 0); assert(accTs > 0); @@ -271,7 +273,7 @@ class RestDetection { sensor_real_t gyrTs; sensor_real_t accTs; -#ifndef REST_DETECTION_DISABLE_LPF +#if !REST_DETECTION_DISABLE_LPF sensor_real_t restLastGyrLp[3]; double restGyrLpState[3 * 2]; double restGyrLpB[3]; @@ -288,4 +290,4 @@ class RestDetection { #endif }; -#endif \ No newline at end of file +#endif diff --git a/src/sensors/SensorFusion.h b/src/sensors/SensorFusion.h index c60b02f2..dc0a4271 100644 --- a/src/sensors/SensorFusion.h +++ b/src/sensors/SensorFusion.h @@ -6,7 +6,9 @@ #define SENSOR_DOUBLE_PRECISION 0 +#ifndef SENSOR_FUSION_TYPE #define SENSOR_FUSION_TYPE SENSOR_FUSION_VQF +#endif #define SENSOR_FUSION_MAHONY 1 #define SENSOR_FUSION_MADGWICK 2 diff --git a/src/sensors/mpu6050sensor.cpp b/src/sensors/mpu6050sensor.cpp index 4480c78d..8eb6d637 100644 --- a/src/sensors/mpu6050sensor.cpp +++ b/src/sensors/mpu6050sensor.cpp @@ -23,7 +23,7 @@ #include "globals.h" -#ifdef IMU_MPU6050_RUNTIME_CALIBRATION +#if IMU_MPU6050_RUNTIME_CALIBRATION #include "MPU6050_6Axis_MotionApps_V6_12.h" #else #include "MPU6050_6Axis_MotionApps20.h" @@ -60,7 +60,7 @@ void MPU6050Sensor::motionSetup() { addr ); -#ifndef IMU_MPU6050_RUNTIME_CALIBRATION +#if !IMU_MPU6050_RUNTIME_CALIBRATION // Initialize the configuration { SlimeVR::Configuration::SensorConfig sensorCalibration @@ -93,7 +93,7 @@ void MPU6050Sensor::motionSetup() { devStatus = imu.dmpInitialize(); if (devStatus == 0) { -#ifdef IMU_MPU6050_RUNTIME_CALIBRATION +#if IMU_MPU6050_RUNTIME_CALIBRATION // We don't have to manually calibrate if we are using the dmp's automatic // calibration #else // IMU_MPU6050_RUNTIME_CALIBRATION @@ -191,7 +191,7 @@ void MPU6050Sensor::motionLoop() { void MPU6050Sensor::startCalibration(int calibrationType) { ledManager.on(); -#ifdef IMU_MPU6050_RUNTIME_CALIBRATION +#if IMU_MPU6050_RUNTIME_CALIBRATION m_Logger.info( "MPU is using automatic runtime calibration. Place down the device and it " "should automatically calibrate after a few seconds"