Android-cuttlefish cvd tool
sensors_simulator.h
Go to the documentation of this file.
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 <mutex>
21#include <string>
22
23#include <Eigen/Dense>
24
26
27namespace cuttlefish {
28namespace sensors {
29
31 Eigen::Vector3d v;
32 float f;
33
34 SensorsData() : v(Eigen::Vector3d::Zero()), f(0.0f) {}
35};
36
38 public:
39 SensorsSimulator(bool is_auto);
40 // Update sensor values based on new rotation status.
41 void RefreshSensors(double x, double y, double z);
42
43 // Return a string with serialized sensors data in ascending order of
44 // sensor id. A bitmask is used to specify which sensors to include.
45 // Each bit maps to a sensor type, and a set bit indicates that the
46 // corresponding sensor should be included in the returned data. Assuming
47 // accelerometer and gyroscope are specified, the returned string would be
48 // formatted as "<acc.x>:<acc.y>:<acc.z> <gyro.x>:<gyro.y>:<gyro.z>".
49 std::string GetSensorsData(const SensorsMask mask);
50
51 private:
54 Eigen::Matrix3d current_rotation_matrix_;
55 std::chrono::time_point<std::chrono::high_resolution_clock>
58};
59
60} // namespace sensors
61} // namespace cuttlefish
Definition: sensors_simulator.h:37
Eigen::Matrix3d current_rotation_matrix_
Definition: sensors_simulator.h:54
std::mutex sensors_data_mtx_
Definition: sensors_simulator.h:52
void RefreshSensors(double x, double y, double z)
Definition: sensors_simulator.cpp:111
bool is_auto_
Definition: sensors_simulator.h:57
std::string GetSensorsData(const SensorsMask mask)
Definition: sensors_simulator.cpp:137
std::chrono::time_point< std::chrono::high_resolution_clock > last_event_timestamp_
Definition: sensors_simulator.h:56
SensorsSimulator(bool is_auto)
Definition: sensors_simulator.cpp:96
SensorsData sensors_data_[kMaxSensorId+1]
Definition: sensors_simulator.h:53
constexpr int kMaxSensorId
Definition: sensors.h:44
int SensorsMask
Definition: sensors.h:50
Definition: alloc_utils.cpp:23
__u32 mask
Definition: nl80211.h:0
Definition: sensors_simulator.h:30
Eigen::Vector3d v
Definition: sensors_simulator.h:31
float f
Definition: sensors_simulator.h:32
SensorsData()
Definition: sensors_simulator.h:34