orientation_tracker.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2019 Google Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <array>
  18. #include <memory>
  19. #include <mutex> // NOLINT
  20. #include "sensors/accelerometer_data.h"
  21. #include "sensors/gyroscope_data.h"
  22. #include "sensors/sensor_fusion_ekf.h"
  23. #include "util/rotation.h"
  24. namespace cardboard {
  25. // OrientationTracker encapsulates pose tracking by connecting sensors
  26. // to SensorFusion.
  27. // This pose tracker reports poses in display space.
  28. class OrientationTracker {
  29. public:
  30. OrientationTracker(const long sampling_period_ns);
  31. void SetCalibration(const Vector3& calibration);
  32. // Pauses tracking and sensors.
  33. void Pause();
  34. // Resumes tracking ans sensors.
  35. void Resume();
  36. // Gets the predicted pose for a given timestamp.
  37. Vector4 GetPose(int64_t timestamp_ns) const;
  38. // Function called when receiving AccelerometerData.
  39. //
  40. // @param event sensor event.
  41. void OnAccelerometerData(const AccelerometerData& event);
  42. // Function called when receiving GyroscopeData.
  43. //
  44. // @param event sensor event.
  45. Vector4 OnGyroscopeData(const GyroscopeData& event);
  46. private:
  47. long sampling_period_ns_;
  48. Vector3 calibration_;
  49. std::atomic<bool> is_tracking_;
  50. // Sensor Fusion object that stores the internal state of the filter.
  51. std::unique_ptr<SensorFusionEkf> sensor_fusion_;
  52. // Latest gyroscope data.
  53. GyroscopeData latest_gyroscope_data_;
  54. };
  55. } // namespace cardboard