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 <functional>
21#include <mutex>
22#include <string>
23
24#include "Eigen/Dense"
25
27
28namespace cuttlefish {
29namespace sensors {
30
32 Eigen::Vector3d v;
33 float f;
34
35 SensorsData() : v(Eigen::Vector3d::Zero()), f(0.0f) {}
36};
37
39 public:
40 SensorsSimulator(bool is_auto);
41
42 using SensorsChangedCallback = std::function<void(SensorsMask)>;
43 // Registers a callback invoked whenever one or more sensors in |mask| are
44 // updated.
46 SensorsChangedCallback callback);
47
48 void SetMotion(double x, double y, double z);
49 void SetHingeAngle(float angle);
50
51 // Return a string with serialized sensors data in ascending order of
52 // sensor id. A bitmask is used to specify which sensors to include.
53 // Each bit maps to a sensor type, and a set bit indicates that the
54 // corresponding sensor should be included in the returned data. Assuming
55 // accelerometer and gyroscope are specified, the returned string would be
56 // formatted as "<acc.x>:<acc.y>:<acc.z> <gyro.x>:<gyro.y>:<gyro.z>".
57 std::string GetSensorsData(SensorsMask mask);
58
59 private:
61
66 Eigen::Matrix3d current_rotation_matrix_;
67 std::chrono::time_point<std::chrono::high_resolution_clock>
70};
71
72} // namespace sensors
73} // namespace cuttlefish
Definition: sensors_simulator.h:38
Eigen::Matrix3d current_rotation_matrix_
Definition: sensors_simulator.h:66
void SetMotion(double x, double y, double z)
Definition: sensors_simulator.cpp:123
std::mutex sensors_data_mtx_
Definition: sensors_simulator.h:62
bool is_auto_
Definition: sensors_simulator.h:69
SensorsMask sensors_changed_mask_
Definition: sensors_simulator.h:63
void SetSensorsChangedCallback(SensorsMask mask, SensorsChangedCallback callback)
Definition: sensors_simulator.cpp:110
void SetHingeAngle(float angle)
Definition: sensors_simulator.cpp:156
std::function< void(SensorsMask)> SensorsChangedCallback
Definition: sensors_simulator.h:42
std::chrono::time_point< std::chrono::high_resolution_clock > last_event_timestamp_
Definition: sensors_simulator.h:68
void NotifySensorsChanged(SensorsMask changed)
Definition: sensors_simulator.cpp:116
SensorsSimulator(bool is_auto)
Definition: sensors_simulator.cpp:95
SensorsData sensors_data_[kMaxSensorId+1]
Definition: sensors_simulator.h:65
SensorsChangedCallback sensors_changed_callback_
Definition: sensors_simulator.h:64
std::string GetSensorsData(SensorsMask mask)
Definition: sensors_simulator.cpp:167
constexpr int kMaxSensorId
Definition: sensors.h:45
int SensorsMask
Definition: sensors.h:51
Definition: alloc_driver.h:20
__u32 mask
Definition: nl80211.h:0
Definition: sensors_simulator.h:31
Eigen::Vector3d v
Definition: sensors_simulator.h:32
float f
Definition: sensors_simulator.h:33
SensorsData()
Definition: sensors_simulator.h:35