• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
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 
17 #pragma once
18 
19 #include <chrono>
20 #include <string>
21 
22 #include <Eigen/Dense>
23 
24 #include "common/libs/sensors/sensors.h"
25 
26 namespace cuttlefish {
27 namespace sensors {
28 
29 class SensorsSimulator {
30  public:
31   SensorsSimulator();
32   // Update sensor values based on new rotation status.
33   void RefreshSensors(double x, double y, double z);
34 
35   // Return a string with serialized sensors data in ascending order of
36   // sensor id. A bitmask is used to specify which sensors to include.
37   // Each bit maps to a sensor type, and a set bit indicates that the
38   // corresponding sensor should be included in the returned data. Assuming
39   // accelerometer and gyroscope are specified, the returned string would be
40   // formatted as "<acc.x>:<acc.y>:<acc.z> <gyro.x>:<gyro.y>:<gyro.z>".
41   std::string GetSensorsData(const SensorsMask mask);
42 
43  private:
44   std::mutex sensors_data_mtx_;
45   Eigen::Vector3d sensors_data_[kMaxSensorId + 1];
46   Eigen::Matrix3d prior_rotation_matrix_, current_rotation_matrix_;
47   std::chrono::time_point<std::chrono::high_resolution_clock>
48       last_event_timestamp_;
49 };
50 
51 }  // namespace sensors
52 }  // namespace cuttlefish