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 int32_t CreateQuaternion(std::vector<float> rotationVector, std::vector<float> &quaternion); 27 int32_t TransformCoordinateSystem(std::vector<float> inRotationMatrix, int32_t axisX, 28 int32_t axisY, std::vector<float> &outRotationMatrix); 29 int32_t GetAltitude(float seaPressure, float currentPressure, float *altitude); 30 int32_t GetGeomagneticDip(std::vector<float> inclinationMatrix, float *geomagneticDip); 31 int32_t GetAngleModify(std::vector<float> currotationMatrix, std::vector<float> prerotationMatrix, 32 std::vector<float> &angleChange); 33 int32_t GetDirection(std::vector<float> rotationMatrix, std::vector<float> &rotationAngle); 34 int32_t CreateRotationMatrix(std::vector<float> rotationVector, std::vector<float> &rotationMatrix); 35 int32_t CreateRotationAndInclination(std::vector<float> gravity, std::vector<float> geomagnetic, 36 std::vector<float> &rotationMatrix, std::vector<float> &inclinationMatrix); 37 38 private: 39 int32_t TransformCoordinateSystemImpl(std::vector<float> inRotationMatrix, int32_t axisX, 40 int32_t axisY, std::vector<float> &outRotationMatrix); 41 static constexpr int32_t QUATERNION_LENGTH = 4; 42 static constexpr int32_t ROTATION_VECTOR_LENGTH = 3; 43 static constexpr int32_t THREE_DIMENSIONAL_MATRIX_LENGTH = 9; 44 static constexpr int32_t FOUR_DIMENSIONAL_MATRIX_LENGTH = 16; 45 static constexpr float GRAVITATIONAL_ACCELERATION = 9.81f; 46 static constexpr float RECIPROCAL_COEFFICIENT = 5.255f; 47 static constexpr float ZERO_PRESSURE_ALTITUDE = 44330.0f; 48 }; 49 #endif // SENSOR_ALGORITHM_H 50