• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SENSOR_ALGORITHM_H
17 #define SENSOR_ALGORITHM_H
18 
19 #include <vector>
20 
21 class SensorAlgorithm {
22 public:
23     SensorAlgorithm() = default;
24     ~SensorAlgorithm() = default;
25     int32_t CreateQuaternion(std::vector<float> rotationVector, std::vector<float> &quaternion);
26     int32_t TransformCoordinateSystem(std::vector<float> inRotationMatrix, int32_t axisX,
27                                     int32_t axisY, std::vector<float> &outRotationMatrix);
28     int32_t GetAltitude(float seaPressure, float currentPressure, float *altitude);
29     int32_t GetGeomagneticDip(std::vector<float> inclinationMatrix, float *geomagneticDip);
30     int32_t GetAngleModify(std::vector<float> currotationMatrix, std::vector<float> prerotationMatrix,
31                         std::vector<float> &angleChange);
32     int32_t GetDirection(std::vector<float> rotationMatrix, std::vector<float> &rotationAngle);
33     int32_t CreateRotationMatrix(std::vector<float> rotationVector, std::vector<float> &rotationMatrix);
34     int32_t CreateRotationAndInclination(std::vector<float> gravity, std::vector<float> geomagnetic,
35                                         std::vector<float> &rotationMatrix, std::vector<float> &inclinationMatrix);
36 
37 private:
38     int32_t TransformCoordinateSystemImpl(std::vector<float> inRotationMatrix, int32_t axisX,
39                                                            int32_t axisY, std::vector<float> &outRotationMatrix);
40     static constexpr int32_t QUATERNION_LENGTH = 4;
41     static constexpr int32_t ROTATION_VECTOR_LENGTH = 3;
42     static constexpr int32_t THREE_DIMENSIONAL_MATRIX_LENGTH = 9;
43     static constexpr int32_t FOUR_DIMENSIONAL_MATRIX_LENGTH = 16;
44     static constexpr float GRAVITATIONAL_ACCELERATION = 9.81f;
45     static constexpr float RECIPROCAL_COEFFICIENT = 5.255f;
46     static constexpr float ZERO_PRESSURE_ALTITUDE = 44330.0f;
47 };
48 #endif // SENSOR_ALGORITHM_H
49