linear_acceleration_fusion_algorithm_using_accelerometer.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_DEVICE_GENERIC_SENSOR_LINEAR_ACCELERATION_FUSION_ALGORITHM_USING_ACCELEROMETER_H_
  5. #define SERVICES_DEVICE_GENERIC_SENSOR_LINEAR_ACCELERATION_FUSION_ALGORITHM_USING_ACCELEROMETER_H_
  6. #include "services/device/generic_sensor/platform_sensor_fusion_algorithm.h"
  7. namespace device {
  8. // Algotithm that obtains linear acceleration values from data provided by
  9. // accelerometer sensor. Simple low-pass filter is used to isolate gravity
  10. // and subtract it from accelerometer data to get linear acceleration.
  11. class LinearAccelerationFusionAlgorithmUsingAccelerometer final
  12. : public PlatformSensorFusionAlgorithm {
  13. public:
  14. LinearAccelerationFusionAlgorithmUsingAccelerometer();
  15. LinearAccelerationFusionAlgorithmUsingAccelerometer(
  16. const LinearAccelerationFusionAlgorithmUsingAccelerometer&) = delete;
  17. LinearAccelerationFusionAlgorithmUsingAccelerometer& operator=(
  18. const LinearAccelerationFusionAlgorithmUsingAccelerometer&) = delete;
  19. ~LinearAccelerationFusionAlgorithmUsingAccelerometer() override;
  20. void SetFrequency(double frequency) override;
  21. void Reset() override;
  22. protected:
  23. bool GetFusedDataInternal(mojom::SensorType which_sensor_changed,
  24. SensorReading* fused_reading) override;
  25. private:
  26. unsigned long reading_updates_count_;
  27. // The time constant for low-pass filter.
  28. double time_constant_;
  29. double initial_timestamp_;
  30. double gravity_x_;
  31. double gravity_y_;
  32. double gravity_z_;
  33. };
  34. } // namespace device
  35. #endif // SERVICES_DEVICE_GENERIC_SENSOR_LINEAR_ACCELERATION_FUSION_ALGORITHM_USING_ACCELEROMETER_H_