Skip to content

Commit

Permalink
add guards to some defines
Browse files Browse the repository at this point in the history
Should address SlimeVR#334 Make defines.h more powerfull
  • Loading branch information
unlogisch04 committed Nov 16, 2024
1 parent 9f20c12 commit 5bae658
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 53 deletions.
158 changes: 118 additions & 40 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,74 +25,152 @@
#include "consts.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

// Debug information

#define LOG_LEVEL LOG_LEVEL_DEBUG
#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
#define DEBUG_NETWORK
#define DEBUG_CONFIGURATION
#define DEBUG_SENSOR
#define DEBUG_NETWORK
#define DEBUG_CONFIGURATION
#endif

#define serialDebug false // Set to true to get Serial output for debugging
#define serialBaudRate 115200
#define LED_INTERVAL_STANDBY 10000
#define PRINT_STATE_EVERY_MS 60000
// 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
#define samplingRateInMillis 10
#ifndef samplingRateInMillis
#define samplingRateInMillis 10
#endif

// Sleeping options
#define POWERSAVING_MODE POWER_SAVING_LEGACY // Minimum causes sporadic data pauses
#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)
#define TARGET_LOOPTIME_MICROS (samplingRateInMillis * 1000)
#endif

// Packet bundling/aggregation
#define PACKET_BUNDLING PACKET_BUNDLING_BUFFERED
#ifndef PACKET_BUNDLING
#define PACKET_BUNDLING PACKET_BUNDLING_BUFFERED
#endif

// Extra tunable for PACKET_BUNDLING_BUFFERED (10000us = 10ms timeout, 100hz target)
#define PACKET_BUNDLING_BUFFER_SIZE_MICROS 10000
#ifndef PACKET_BUNDLING_BUFFER_SIZE_MICROS
#define PACKET_BUNDLING_BUFFER_SIZE_MICROS 10000
#endif

// Setup for the Magnetometer
#define useFullCalibrationMatrix true
#ifndef useFullCalibrationMatrix
#define useFullCalibrationMatrix true
#endif

// Battery configuration
#define batterySampleRate 10000
#define BATTERY_LOW_VOLTAGE_DEEP_SLEEP false
#define BATTERY_LOW_POWER_VOLTAGE 3.3f // Voltage to raise error
#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
#define OPTIMIZE_UPDATES true
#ifndef OPTIMIZE_UPDATES
#define OPTIMIZE_UPDATES true
#endif

#ifndef I2C_SPEED
#define I2C_SPEED 400000
#endif

#define I2C_SPEED 400000
#ifndef COMPLIANCE_MODE
#define COMPLIANCE_MODE true
#endif

#define COMPLIANCE_MODE true
#define USE_ATTENUATION COMPLIANCE_MODE&& ESP8266
#define ATTENUATION_N 10.0 / 4.0
#define ATTENUATION_G 14.0 / 4.0
#define ATTENUATION_B 40.0 / 4.0
#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
#define ENABLE_INSPECTION false
#ifndef ENABLE_INSPECTION
#define ENABLE_INSPECTION false
#endif

#define PROTOCOL_VERSION 18

Expand Down
22 changes: 21 additions & 1 deletion src/defines_bmi160.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
#endif
10 changes: 10 additions & 0 deletions src/motionprocessing/GyroTemperatureCalibrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions src/motionprocessing/RestDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Arduino.h>
#include <basicvqf.h>
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -216,7 +218,7 @@ class RestDetection {

bool getRestDetected() { return restDetected; }

#ifndef REST_DETECTION_DISABLE_LPF
#if !REST_DETECTION_DISABLE_LPF
void resetState() {
restDetected = false;

Expand Down Expand Up @@ -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);

Expand All @@ -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];
Expand All @@ -288,4 +290,4 @@ class RestDetection {
#endif
};

#endif
#endif
2 changes: 2 additions & 0 deletions src/sensors/SensorFusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5bae658

Please sign in to comment.