2#include "tools/gyroscopeBiasEstimator.h"
5GyroscopeBiasEstimator::GyroscopeBiasEstimator()
10GyroscopeBiasEstimator::~GyroscopeBiasEstimator()
15void GyroscopeBiasEstimator::reset()
26void GyroscopeBiasEstimator::processGyroscope(
Vector3d gyro, int64_t sensorTimestampNs)
28 gyroLowPass.addSample(gyro, sensorTimestampNs);
29 Vector3d::sub(gyro, gyroLowPass.getFilteredData(), smoothedGyroDiff);
31 isGyroStatic.appendFrame(smoothedGyroDiff.length() < GYRO_DIFF_STATIC_THRESHOLD);
33 if ((isGyroStatic.isRecentlyStatic()) && (isAccelStatic.isRecentlyStatic()))
34 updateGyroBias(gyro, sensorTimestampNs);
37void GyroscopeBiasEstimator::processAccelerometer(
Vector3d accel, int64_t sensorTimestampNs)
39 accelLowPass.addSample(accel, sensorTimestampNs);
40 Vector3d::sub(accel, accelLowPass.getFilteredData(), smoothedAccelDiff);
42 isAccelStatic.appendFrame(smoothedAccelDiff.length() < ACCEL_DIFF_STATIC_THRESHOLD);
45void GyroscopeBiasEstimator::getGyroBias(
Vector3d &result)
47 if (gyroBiasLowPass.getNumSamples() < NUM_GYRO_BIAS_SAMPLES_THRESHOLD)
53 result.set(gyroBiasLowPass.getFilteredData());
54 double rampUpRatio = std::min(1.0,
double((gyroBiasLowPass.getNumSamples() - NUM_GYRO_BIAS_SAMPLES_THRESHOLD)) / NUM_GYRO_BIAS_SAMPLES_INITIAL_SMOOTHING);
55 result.scale(rampUpRatio);
59void GyroscopeBiasEstimator::updateGyroBias(
Vector3d gyro, int64_t sensorTimestampNs)
61 if (gyro.length() >= GYRO_FOR_BIAS_THRESHOLD)
66 double updateWeight = std::max(0.0, 1.0 - gyro.length() * 25.0);
67 updateWeight *= updateWeight;
68 gyroBiasLowPass.addWeightedSample(gyroLowPass.getFilteredData(), sensorTimestampNs, updateWeight);