A method for estimating the attitude angle of an Android device
By combining Euler angle rotation order and quaternion transformation relationship with complementary filtering and sensor error calibration, an attitude angle estimation method for Android devices is designed. This method solves the problem that attitude angle estimation in the prior art is easily affected by the environment and has poor accuracy, and achieves real-time, accurate and stable attitude angle estimation.
Patent Information
- Application Number
- CN202411106557.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-13
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2044-08-13
AI Technical Summary
Existing methods for estimating pose angles on Android devices are easily affected by the surrounding environment and have poor accuracy.
By adopting Euler angle rotation order and quaternion transformation relationship, combined with complementary filtering and sensor error calibration, an attitude angle estimation process is designed, and attitude angle is estimated in real time using rotation matrix and quaternion.
It improves the accuracy and stability of attitude angle estimation, enables real-time updates in dynamic environments, meets the real-time performance requirements of mobile devices, avoids the singularity problem in Euler angle representation, and ensures the accuracy of attitude angle calculation over long periods of time.
Smart Images

Figure CN119063762B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of indoor positioning technology, specifically to a method for estimating the attitude angle of an Android device. Background Technology
[0002] With the development of science and technology, location-based services (LBS) have brought numerous conveniences to people's lives. Scholars both domestically and internationally have developed many positioning methods based on technologies such as Wi-Fi, Bluetooth, Pedestrian Dead Reckoning (PDR), ultra-wideband (UWB), visible light communication, computer vision, geomagnetism, and infrared. Among these, PDR-based hybrid positioning methods have been widely used because they do not require the deployment of additional equipment. PDR positioning mainly consists of three parts: gait detection, stride length estimation, and heading estimation. Device attitude estimation is the foundation of flight path estimation, and the accuracy of heading estimation plays a crucial role in PDR positioning.
[0003] According to a recent report from market research firm Counterpoint, Android currently holds the number one market share globally with 39%. Android's underlying architecture provides a simple method for estimating attitude angles. However, this method only combines accelerometer and magnetometer data to estimate the Android device's attitude, making it susceptible to environmental influences and resulting in relatively poor accuracy. Summary of the Invention
[0004] (a) Technical problems to be solved
[0005] To address the shortcomings of existing technologies, this invention provides a method for estimating attitude angles for Android devices. This method has the advantages of determining the Euler angle rotation order, the Euler angle and quaternion transformation relationship based on the characteristics of Android devices, establishing an attitude angle estimation model based on complementary filtering, and designing an attitude angle estimation process to achieve real-time attitude angle estimation for Android devices, thus solving the problems mentioned above.
[0006] (II) Technical Solution
[0007] To achieve the above objectives, the present invention provides the following technical solution: a method for estimating the attitude angle of an Android device, comprising the following steps:
[0008] Step 1: Determine the Euler angle rotation order of the Android device and establish the mutual conversion relationship between the carrier coordinate system and the geographic coordinate system;
[0009] Step 2: Establish the conversion relationship between quaternions and Euler angles based on rotation matrices;
[0010] Step 3: Design a real-time Android device attitude angle estimation process based on sensor error calibration and complementary filtering estimation;
[0011] Step 4: According to the designed attitude angle estimation process, use an Android smartphone to collect data and update the attitude angle in real time.
[0012] Preferably, the detailed steps in step one are as follows:
[0013] S1.1 When an Android device undergoes an attitude change, from the perspective of Euler angle transformation, the Android device first undergoes γ (roll angle) transformation, θ (pitch angle) transformation, and ψ (yaw angle) transformation.
[0014] The rotation matrix from the carrier coordinate system to the geographic coordinate system Euler angles are expressed as follows:
[0015]
[0016] S1.2, Device coordinates [vx, vy, vz] after rotation matrix Transform to geographic coordinates [vx',vy',vz'];
[0017]
[0018] S1.3 The transformation from geographic coordinates [vx',vy',vz'] to device coordinates is a rotation matrix. inverse transform;
[0019]
[0020] S1.4, due to the rotation matrix It is an orthogonal matrix, and its inverse matrix is... With transpose matrix equal;
[0021] Rotation matrix from geographic coordinate system to carrier coordinate system The expression is:
[0022]
[0023] Preferably, step 2 establishes the rotation relationship between the quaternion based on the rotation matrix and the Euler angles as follows:
[0024] S2.1 On an Android device, represent the rotation matrix using quaternions [q0,q1,q2,q3]. The expression is as follows:
[0025]
[0026] S2.2, Rotation Matrix Represented by Euler angles and quaternions respectively, corresponding terms are equal.
[0027] The preferred expression for the quaternion-Euler angle transformation relationship is:
[0028] The conversion relationship from quaternions to Euler angles is expressed as follows:
[0029]
[0030] The conversion expression from Euler angles to quaternions:
[0031]
[0032] The above transformation relationship serves as the basis for real-time attitude angle estimation on Android devices.
[0033] Preferably, step three is based on real-time Android device attitude angle estimation using sensor error calibration and complementary filtering estimation.
[0034] Preferably, the attitude angle estimation step in step three is as follows:
[0035] S3.1 Android devices have built-in sensors such as accelerometer, magnetometer, and gyroscope to estimate the device's attitude angles. The aforementioned sensors are calibrated before estimation.
[0036] S3.2. Heading angle estimation model based on complementary filtering: The heading angle is estimated using a complementary filtering model, and the gyroscope is corrected using acceleration data and magnetic field strength data.
[0037] Preferably, the calibration method for the accelerometer, magnetometer, and gyroscope sensors is as follows;
[0038] S3.1.1 First, place the Android device stationary on a horizontal table. Design N different stationary postures and measure the accelerometer readings for each axis under each of the N stationary postures. i ∈R n×3 ,i∈N}, where Acc i An ellipsoidal model is constructed based on the triaxial and velocity data acquired in the i-th attitude. The center C of the ellipsoid is then solved using least squares based on the data acquired in N attitudes. a and the length S of each axis a ;
[0039] Finally, when performing device attitude estimation, the collected acceleration data needs to be processed using the following formula to obtain unbiased data for attitude estimation:
[0040]
[0041] S3.1.2 First, place the Android device in various positions around a location, such as holding the Android smartphone and circling it in the shape of an infinity symbol, then record the magnetometer readings for each axis. i ∈R n×3 ,i∈N}, where Mag i An ellipsoidal model is constructed based on the triaxial and magnetometer data acquired in the i-th attitude. The center C of the ellipsoid is then solved using least squares based on the data acquired in N attitudes. m and the length S of each axis m ;
[0042] Finally, when performing device attitude estimation, the collected acceleration data needs to be processed using the following formula to obtain unbiased data for attitude estimation:
[0043]
[0044] S3.1.3 First, keep the Android device stationary at a certain location, ensuring it does not rotate, and record the gyroscope's three-axis data {Gyr i ∈R n×3 ,i∈N}, where Gyr i The three-axis and gyroscope data collected under the i-th attitude are used to calculate the zero-bias error C by averaging the N data points across each axis. gyr ;
[0045] Finally, when performing device attitude estimation, the collected gyroscope data needs to be processed using the following formula to obtain unbiased data for attitude estimation:
[0046] {Gyr i =Gyr i -C gyr ∈R n×3 ,i∈N}.
[0047] Preferably, the correction in S3.2 includes:
[0048] Let the gyroscope data be ω g =[ω gx ω gy ω gz ] T The normalized data ω = [ω x ω y ω z ] T The deviation in the heading estimation process is denoted as e = [e x e y e z ] TThe value is obtained from acceleration and magnetic field strength data; therefore, the value after gyroscope data error compensation is:
[0049] ω=ω g +K P e+K I ∫e
[0050] Where K P =0.1,K i =0.0001;
[0051] The heading angle estimation model based on complementary filtering is as follows:
[0052] Update gyroscope data using error compensation:
[0053] ω=ω g +K P e+K I ∫e
[0054] Update quaternions using gyroscope data:
[0055]
[0056] Preferably, in step S3.2, the expression for solving the attitude angle using the conversion relationship between quaternions and attitude angles is as follows:
[0057]
[0058] Preferably, in step four, according to the designed attitude angle estimation process, data is collected using an Android smartphone to update the attitude angle in real time. The update process is as follows:
[0059] Based on the designed process, write Android code, including data acquisition from various sensors, model calculation, and real-time updates and output of device posture.
[0060] Compared with existing technologies, this invention provides a method for estimating the attitude angle of an Android device, which has the following advantages:
[0061] 1. In step one, this invention details the rotation matrix from the carrier coordinate system to the geographic coordinate system, covering the order and transformation relationship of roll angle (γ), pitch angle (θ), and yaw angle (ψ). Through the inverse transformation of the rotation matrix, the transformation relationship from the geographic coordinate system to the carrier coordinate system of the Android device is established, ensuring the correct mapping of attitude angles between different coordinate systems. Step two introduces the transformation relationship between quaternions and Euler angles based on the rotation matrix. Quaternions are used to effectively represent attitude angles, and their correspondence with the rotation matrix is clearly explained through specific mathematical formulas. Conversion formulas from quaternions to Euler angles and from Euler angles to quaternions are provided, ensuring the mathematical accuracy and stability in the attitude angle estimation process, obtaining the correct conversion results between Euler angles and quaternions, and realizing real-time updating of attitude angles.
[0062] 2. This invention establishes the rotational relationship between the carrier coordinate system and the geographic coordinate system through detailed mathematical derivation and matrix operations, ensuring the correct mapping of attitude angle transformations between different coordinate systems, thereby improving the accuracy of attitude estimation. The explicit transformation relationship between the rotation matrix and quaternions ensures the stability and mathematical accuracy of attitude angles during calculation and sensor fusion. Quaternions effectively avoid the singularity problem that may occur in Euler angle representation. In step three, obtaining accurate sensor data improves the accuracy of attitude angle estimation. In particular, the application of complementary filtering technology effectively integrates information from different sensors, making attitude angle estimation more stable and accurate, achieving the beneficial effect of more accurate attitude estimation.
[0063] 3. This invention introduces complementary filtering and sensor error calibration techniques to ensure the accuracy of data acquired from the accelerometer, magnetometer, and gyroscope. These techniques not only improve the accuracy of attitude angle estimation but also enable real-time updates in dynamic environments, meeting the real-time performance requirements of mobile devices. The stable representation using quaternions avoids common Euler angle representation problems, such as gimbal lock. The clear conversion relationship between quaternions and rotation matrices ensures the mathematical stability of attitude angle calculations, maintaining accuracy over long-term use and achieving the beneficial effect of real-time attitude angle estimation for Android devices. Attached Figure Description
[0064] Figure 1 This is a schematic diagram of the Android device attitude angle estimation method of the present invention;
[0065] Figure 2 This is a schematic diagram of the attitude angle estimation process for the Android device of the present invention;
[0066] Figure 3 This is a schematic diagram of the experimental scenario for this invention;
[0067] Figure 4 This is a schematic diagram of the heading angle of the mobile phone of the present invention. Detailed Implementation
[0068] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0069] Example 1
[0070] A method for estimating the attitude angle of an Android device is illustrated in the diagram below. Figure 1 As shown, it includes the following steps:
[0071] Step 1: Determine the Euler angle rotation order of the Android device, and calculate the rotation matrix based on Euler angles and quaternions. Based on the principle that corresponding terms in the same matrix are equal, calculate the conversion relationship between Euler angles and quaternions.
[0072] Step 2: Establish an attitude angle estimation model based on complementary filtering.
[0073] Step 3: First, calibrate the sensor error, and then use complementary filtering to estimate the Android device's attitude angle.
[0074] Step 1 determines the Euler angle rotation order of the Android device and calculates the rotation matrix based on Euler angles and quaternions. The process of calculating the conversion relationship between Euler angles and quaternions is as follows, based on the principle that corresponding terms in the same matrix are equal.
[0075] (1.1) When an Android device undergoes an attitude transformation, from the perspective of Euler angle transformation, the Android device first undergoes γ (roll angle) transformation, θ (pitch angle) transformation, and ψ (yaw angle) transformation. The rotation matrix from the carrier coordinate system to the geographic coordinate system. Euler angles are expressed as follows:
[0076]
[0077] (1.2) On an Android device, use the quaternion [q0,q1,q2,q3] to represent the rotation matrix. The expression is as follows:
[0078]
[0079] Rotation matrix These can be represented using Euler angles and quaternions respectively, and corresponding terms are equal. Therefore, the conversion relationship between quaternions and Euler angles is expressed as follows:
[0080]
[0081] Step two involves establishing the attitude angle estimation model based on complementary filtering, as follows:
[0082] (2.1) Let the gyroscope data be ω g =[ω gx ω gy ω gz ] T The normalized data ω = [ω x ω y ω z ] T The deviation in the heading estimation process is denoted as e = [e x e y e z ] T This is obtained from acceleration and magnetic field strength data. Therefore, the value after gyroscope data error compensation is , where K P =0.1,K i =0.0001:
[0083] ω=ω g +K P e+K i ∫e
[0084] (2.2) The heading angle estimation model based on complementary filtering is as follows:
[0085] Update gyroscope data using error compensation:
[0086] ω=ω g +K P e+K I ∫e
[0087] Update quaternions using gyroscope data:
[0088]
[0089] The attitude angle is solved by using the conversion relationship between quaternions and attitude angles.
[0090]
[0091] Step 3: Design a complementary filter-based estimation process for Android device attitude angle estimation based on sensor error calibration. The process is as follows:
[0092] (3.1) First, place the Android device stationary on a horizontal table. Design N stationary postures and measure the accelerometer readings for each axis under each of the N stationary postures. i ∈R n×3 ,i∈N}, where Acc i The three-axis and velocity data acquired under the i-th attitude are used to construct an ellipsoidal model. Based on the data acquired under N attitudes, the center C of the ellipsoid is solved using least squares. a and the length S of each axis a Finally, when performing device attitude estimation, the collected acceleration data needs to be processed as follows to obtain unbiased data for attitude estimation.
[0093]
[0094] (3.2) First, the Android device is placed in various positions at a certain location, such as holding the Android smartphone in a figure-eight motion, and then the magnetometer readings for each axis are recorded. i ∈R n×3 ,i∈N}, where Mag i The triaxial and magnetometer data acquired under the i-th attitude are used to construct an ellipsoidal model. The center C of the ellipsoid is solved using least squares based on the data acquired under N attitudes. m and the length S of each axis m Finally, when performing device attitude estimation, the collected acceleration data needs to be processed as follows to obtain unbiased data for attitude estimation.
[0095]
[0096] (3.3) First, keep the Android device stationary at a certain location, ensuring it does not rotate, and record the gyroscope's three-axis data {Gyr i ∈R n×3 ,i∈N}, where Gyr i This represents the three-axis and gyroscope data acquired under the i-th attitude. The zero-bias error C is calculated by averaging the N data sets across each axis. gyr Finally, when performing device attitude estimation, the collected gyroscope data needs to be processed as follows to obtain unbiased data for attitude estimation.
[0097] {Gyr i =Gyr i -C gyr ∈R n×3 ,i∈N}
[0098] (3.4) Input the calibrated data into the complementary filter model for calculation, and output the real-time attitude angle of the Android device. See Figure 2.
[0099] Example 2
[0100] Please see Figure 3
[0101] In a preferred embodiment of the present invention, Figure 3 An experiment was conducted in an indoor positioning scenario shown, which included a U-shaped corridor with a poor electromagnetic environment.
[0102] In the experimental environment of this invention, the device travels clockwise twice around a selected point, collecting data from the accelerometer, magnetometer, and gyroscope using a self-developed acquisition software on an Android P20 smartphone. Error calibration of the accelerometer, magnetometer, and gyroscope data is performed according to steps (3.2), (3.2), and (3.3). Then, according to step (3.4), a complementary filter model is input to convert the calculated quaternions to Euler angles, and the heading angle is output and displayed. A schematic diagram of the obtained heading angle is shown below. Figure 4 As shown.
[0103] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for estimating the attitude angle of an Android device, characterized in that, Includes the following steps: Step 1: Determine the Euler angle rotation order of the Android device and establish the mutual conversion relationship between the carrier coordinate system and the geographic coordinate system; Step 2: Establish the conversion relationship between quaternions and Euler angles based on rotation matrices; Step 3: Design a real-time Android device attitude angle estimation process based on sensor error calibration and complementary filtering estimation; Step 4: According to the designed attitude angle estimation process, use an Android smartphone to collect data and update the attitude angle in real time; The attitude angle estimation step in step three is as follows: S3.1 Android devices have built-in sensors such as accelerometer, magnetometer, and gyroscope to estimate the device's attitude angles. The aforementioned sensors are calibrated before estimation. S3.2, Heading angle estimation model based on complementary filtering: The heading angle is estimated using a complementary filtering model, and the gyroscope is corrected using acceleration data and magnetic field strength data. The calibration method for the accelerometer, magnetometer, and gyroscope sensors is as follows: S3.1.1 First, place the Android device stationary on a horizontal table. Design N different stationary postures and measure the accelerometer readings for each axis under each of the N stationary postures. i ∈R n×3 ,i∈N}, where Acc i An ellipsoidal model is constructed based on the triaxial and velocity data acquired in the i-th attitude. The center C of the ellipsoid is then solved using least squares based on the data acquired in N attitudes. a and the length S of each axis a ; Finally, when performing device attitude estimation, the collected acceleration data needs to be processed using the following formula to obtain unbiased data for attitude estimation: S3.1.2 First, orbit the Android device in various poses at a certain location, then record the magnetometer readings for each axis. i ∈R n×3 ,i∈N}, where Mag i An ellipsoidal model is constructed based on the triaxial and magnetometer data acquired in the i-th attitude. The center C of the ellipsoid is then solved using least squares based on the data acquired in N attitudes. m and the length S of each axis m ; Finally, when performing device attitude estimation, the collected acceleration data needs to be processed using the following formula to obtain unbiased data for attitude estimation: S3.1.3 First, keep the Android device stationary at a certain location, ensuring it does not rotate, and record the gyroscope's three-axis data {Gyr i ∈R n×3 ,i∈N}, where Gyr i The three-axis and gyroscope data collected under the i-th attitude are used to calculate the zero-bias error C by averaging the N data points across each axis. gyr ; Finally, when performing device attitude estimation, the collected gyroscope data needs to be processed using the following formula to obtain unbiased data for attitude estimation: {Gyr i =Gyr i -C gyr ∈R n×3 ,i∈N}: The correction in S3.2 includes: Let the gyroscope data be ω g =[ω gx ω gy ω gz ] T The normalized data ω = [ω x ω y ω z ] T The deviation in the heading estimation process is denoted as e = [e x e y e z ] T The value is obtained from acceleration and magnetic field strength data; therefore, the value after gyroscope data error compensation is: oh = oh g +K P e+K I ∫e Where K P =0.1,K i =0.0001; The heading angle estimation model based on complementary filtering is as follows: Update gyroscope data using error compensation: oh = oh g +K P e+K I ∫e Update quaternions using gyroscope data:
2. The pose angle estimation method for an Android device according to claim 1, characterized in that: The detailed steps in step one are as follows: S1.1 When an Android device undergoes an attitude transformation, from the perspective of Euler angle transformation, the Android device first undergoes roll angle γ transformation, pitch angle θ transformation, and yaw angle ψ transformation. The rotation matrix from the carrier coordinate system to the geographic coordinate system Euler angles are expressed as follows: S1.2, Device coordinates [vx, vy, vz] after rotation matrix Transform to geographic coordinates [vx',vy',vz']; S1.3 The transformation from geographic coordinates [vx',vy',vz'] to device coordinates is a rotation matrix. inverse transform; S1.4, due to the rotation matrix It is an orthogonal matrix, and its inverse matrix is... With transpose matrix equal; Rotation matrix from geographic coordinate system to carrier coordinate system The expression is:
3. The pose angle estimation method for an Android device according to claim 1, characterized in that: Step 2 establishes the rotation relationship between quaternions based on rotation matrices and Euler angles as follows: S2.1 On an Android device, represent the rotation matrix using quaternions [q0,q1,q2,q3]. The expression is as follows: S2.2, Rotation Matrix Represented by Euler angles and quaternions respectively, corresponding terms are equal.
4. The pose angle estimation method for an Android device according to claim 3, characterized in that: The expression for the transformation relationship between quaternions and Euler angles is as follows: The conversion relationship from quaternions to Euler angles is expressed as follows: The conversion expression from Euler angles to quaternions: The above transformation relationship serves as the basis for real-time attitude angle estimation on Android devices.
5. The pose angle estimation method for an Android device according to claim 1, characterized in that: Step three is the real-time Android device attitude angle estimation based on sensor error calibration and complementary filtering estimation.
6. The pose angle estimation method for an Android device according to claim 1, characterized in that: The attitude angle expression obtained in S3.2 using the conversion relationship between quaternions and attitude angles is as follows:
7. The pose angle estimation method for an Android device according to claim 1, characterized in that: Step four involves using an Android smartphone to collect data and update the attitude angles in real time, according to the designed attitude angle estimation process. The update process is as follows: Based on the designed process, write Android code, including data acquisition from various sensors, model calculation, and real-time updates and output of device posture.
Citation Information
Patent Citations
Attitude detection method of nine-axis motion sensor based on EKF (Extended Kalman Filter)
CN114199241A
Attitude resolving method of quaternion-based improved complementary filtering algorithm
CN117073618A