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 Aug 18, 2024
1 parent fef504e commit 452efcc
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 64 deletions.
126 changes: 95 additions & 31 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,70 +25,134 @@
#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 BNO_USE_MAGNETOMETER_CORRECTION false // Set to true to enable magnetometer correction for BNO08x IMUs. Only works with USE_6_AXIS set to true.
#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
#define IMU_MPU6050_RUNTIME_CALIBRATION true // Comment to revert to startup/traditional-calibration
#endif

#ifndef BNO_USE_ARVR_STABILIZATION
#define BNO_USE_ARVR_STABILIZATION true // Set to false to disable stabilization for BNO085+ IMUs
#endif

#ifndef BNO_USE_MAGNETOMETER_CORRECTION
#define BNO_USE_MAGNETOMETER_CORRECTION false // Set to true to enable magnetometer correction for BNO08x IMUs. Only works with USE_6_AXIS set to true.
#endif

#ifndef USE_6_AXIS
#define USE_6_AXIS true // uses 9 DoF (with mag) if false (only for ICM-20948 and BNO0xx currently)
#endif

#ifndef LOAD_BIAS
#define LOAD_BIAS true // Loads the bias values from NVS on start
#endif

#ifndef SAVE_BIAS
#define SAVE_BIAS true // Periodically saves bias calibration data to NVS
#endif

#ifndef BIAS_DEBUG
#define BIAS_DEBUG false // Printing BIAS Variables to serial (ICM20948 only)
#endif

#ifndef ENABLE_TAP
#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
#endif

#ifndef SEND_ACCELERATION
#define SEND_ACCELERATION true // send linear acceleration to the server
#endif
//Debug information

#define LOG_LEVEL LOG_LEVEL_DEBUG
#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
#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
#ifndef serialDebug
#define serialDebug false // Set to true to get Serial output for debugging
#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)
#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

#define I2C_SPEED 400000
#ifndef I2C_SPEED
#define I2C_SPEED 400000
#endif

#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 FIRMWARE_BUILD_NUMBER 17
#define FIRMWARE_VERSION "0.4.0"
Expand Down
34 changes: 27 additions & 7 deletions src/defines_bmi160.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,34 @@
// 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:
#define BMI160_MAG_TYPE BMI160_MAG_TYPE_HMC
#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.
#define BMI160_USE_VQF true
#ifndef BMI160_USE_VQF
#define BMI160_USE_VQF true
#endif

// Use BasicVQF instead of VQF (if BMI160_USE_VQF == true).
// Disables the features above.
#define BMI160_USE_BASIC_VQF false
#ifndef BMI160_USE_BASIC_VQF
#define BMI160_USE_BASIC_VQF false
#endif

// Use temperature calibration.
#define BMI160_USE_TEMPCAL true
#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
#define BMI160_CALIBRATION_GYRO_SECONDS 5
#ifndef BMI160_CALIBRATION_GYRO_SECONDS
#define BMI160_CALIBRATION_GYRO_SECONDS 5
#endif

// Calibration method options:
// - Skip: disable this calibration step;
Expand All @@ -53,24 +63,34 @@
// Default: ACCEL_CALIBRATION_METHOD_6POINT
// #define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_SKIP
// #define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_ROTATION
#define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_6POINT
#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
28 changes: 19 additions & 9 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
#define TEMP_CALIBRATION_MIN 15.0f
#ifndef TEMP_CALIBRATION_MIN
#define TEMP_CALIBRATION_MIN 15.0f
#endif

// Degrees C
// default: 45.0f
#define TEMP_CALIBRATION_MAX 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
#define TEMP_CALIBRATION_STEP 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
#define TEMP_CALIBRATION_MAX_DEVIATION_FROM_STEP 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
#define TEMP_CALIBRATION_SECONDS_PER_STEP 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 Expand Up @@ -121,7 +131,7 @@ struct GyroTemperatureCalibrationConfig {
minTemperatureRange(1000),
maxTemperatureRange(-1000)
{ }

bool hasData() {
return minTemperatureRange != 1000;
}
Expand Down Expand Up @@ -164,7 +174,7 @@ class GyroTemperatureCalibrator {
public:
uint8_t sensorId;
GyroTemperatureCalibrationConfig config;

// set when config is fully calibrated is saved OR on startup when loaded config is fully calibrated;
// left unset when sending saving command over serial so it can continue calibration and autosave later
bool configSaved = false;
Expand Down Expand Up @@ -200,7 +210,7 @@ class GyroTemperatureCalibrator {
GyroTemperatureCalibrationState state;
uint32_t samplesPerStep;
SlimeVR::Logging::Logger m_Logger;

float lastApproximatedTemperature = 0.0f;
float lastApproximatedOffsets[3];

Expand All @@ -216,4 +226,4 @@ class GyroTemperatureCalibrator {
void resetCurrentTemperatureState();
};

#endif
#endif
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 <vqf.h>
Expand Down Expand Up @@ -50,7 +52,7 @@ class RestDetection {
setup();
}

#ifndef REST_DETECTION_DISABLE_LPF
#if !REST_DETECTION_DISABLE_LPF
void filterInitialState(sensor_real_t x0, const double b[3], const double a[2], double out[])
{
// initial state for steady state (equivalent to scipy.signal.lfilter_zi, obtained by setting y=x=x0 in the filter
Expand Down Expand Up @@ -104,7 +106,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]) +
Expand Down Expand Up @@ -145,7 +147,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]) +
Expand Down Expand Up @@ -189,7 +191,7 @@ class RestDetection {
return restDetected;
}

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

Expand Down Expand Up @@ -220,7 +222,7 @@ class RestDetection {
#endif

void setup() {
#ifndef REST_DETECTION_DISABLE_LPF
#if !REST_DETECTION_DISABLE_LPF
assert(gyrTs > 0);
assert(accTs > 0);

Expand All @@ -241,7 +243,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 @@ -259,4 +261,4 @@ class RestDetection {
};


#endif
#endif
Loading

0 comments on commit 452efcc

Please sign in to comment.