• 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 <cstdint>
20 #include <vector>
21 
22 class SensorAlgorithm {
23 public:
24     SensorAlgorithm() = default;
25     ~SensorAlgorithm() = default;
26 
27     int32_t createQuaternion(std::vector<float> rotationVector, std::vector<float> &quaternion);
28 
29     int32_t transformCoordinateSystem(std::vector<float> inRotationMatrix, int32_t axisX,
30                                     int32_t axisY, std::vector<float> &outRotationMatrix);
31 
32     int32_t getAltitude(float seaPressure, float currentPressure, float *altitude);
33 
34     int32_t getGeomagneticDip(std::vector<float> inclinationMatrix, float *geomagneticDip);
35 
36     int32_t getAngleModify(std::vector<float> currotationMatrix, std::vector<float> prerotationMatrix,
37                         std::vector<float> &angleChange);
38 
39     int32_t getDirection(std::vector<float> rotationMatrix, std::vector<float> &rotationAngle);
40 
41     int32_t createRotationMatrix(std::vector<float> rotationVector, std::vector<float> &rotationMatrix);
42 
43     int32_t createRotationAndInclination(std::vector<float> gravity, std::vector<float> geomagnetic,
44                                         std::vector<float> &rotationMatrix, std::vector<float> &inclinationMatrix);
45 private:
46     int32_t transformCoordinateSystemImpl(std::vector<float> inRotationMatrix, int32_t axisX,
47                                                            int32_t axisY, std::vector<float> &outRotationMatrix);
48     static constexpr int32_t QUATERNION_LENGTH = 4;
49     static constexpr int32_t ROTATION_VECTOR_LENGTH = 3;
50     static constexpr int32_t THREE_DIMENSIONAL_MATRIX_LENGTH = 9;
51     static constexpr int32_t FOUR_DIMENSIONAL_MATRIX_LENGTH = 16;
52     static constexpr float GRAVITATIONAL_ACCELERATION = 9.81f;
53     static constexpr float RECIPROCAL_COEFFICIENT = 5.255f;
54     static constexpr float ZERO_PRESSURE_ALTITUDE = 44330.0f;
55 };
56 #endif // SENSOR_ALGORITHM_H
57