Magnetic calibration method and device, electronic equipment and storage medium

By applying a magnetic deviation prediction algorithm in electronic devices for real-time magnetic calibration, the problem of deviation between the magnetometer measured value and the real value is solved, and more accurate magnetic field orientation and higher equipment reliability are achieved.

CN119439000APending Publication Date: 2025-02-14GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310967792.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-02
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

In actual use of magnetometers in electronic devices, the measured values ​​are biased from the real values, resulting in inaccurate orientation or orientation information provided.

Method used

The magnetic calibration method based on the magnetic deviation prediction algorithm is adopted, and real-time calibration is performed by obtaining the real-time value of the magnetic deviation parameters of the magnetometer to reduce the measurement deviation.

Benefits of technology

Accurate calibration of magnetometer data is achieved, and the orientation accuracy and reliability of electronic devices in magnetic field environments are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119439000A_ABST
    Figure CN119439000A_ABST
Patent Text Reader

Abstract

The invention discloses a magnetic calibration method and device, electronic equipment and a storage medium, and relates to the technical field of conventional navigation. The method comprises the steps of obtaining a first parameter value of a magnetic bias parameter of a magnetometer at a current moment based on a magnetic bias prediction algorithm; obtaining a change value of the first parameter value relative to a historical parameter value as a magnetic bias variation, the historical parameter value being a parameter value of the magnetic bias parameter at a target moment before the current moment; if the magnetic bias variation is greater than a first threshold value, performing iterative optimization on target parameters in a magnetic bias prediction algorithm until the magnetic bias prediction algorithm converges, and obtaining an optimized magnetic bias prediction algorithm; based on the optimized magnetic bias prediction algorithm, real-time magnetic bias parameter values of the magnetic bias parameters are obtained, and the real-time parameter values are used for calibrating real-time magnetic data collected by the magnetometer. In this way, real-time magnetic calibration is better achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of conventional navigation technology, and in particular to a magnetic calibration method, device, electronic device and storage medium. Background Art

[0002] Electronic devices often use magnetometers to help determine the orientation or direction of the electronic device. A magnetometer is used to measure the strength and direction of the magnetic field to determine the direction of the electronic device relative to the earth's magnetic field. However, in actual use, the measured value of the magnetometer often deviates from the true value, which results in providing the wrong orientation or direction for the electronic device. Summary of the invention

[0003] The present application proposes a magnetic calibration method, device, electronic device and storage medium to achieve real-time magnetic calibration.

[0004] In a first aspect, an embodiment of the present application provides a magnetic calibration method, which is applied to an electronic device, wherein the electronic device includes a magnetometer, and the method includes: based on a magnetic deviation prediction algorithm, obtaining a first parameter value of a magnetic deviation parameter of the magnetometer at a current moment; obtaining a change value of the first parameter value relative to a historical parameter value as a magnetic deviation change amount, wherein the historical parameter value is a parameter value of the magnetic deviation parameter at a target moment before the current moment; if the magnetic deviation change amount is greater than a first threshold, iteratively optimizing the target parameter in the magnetic deviation prediction algorithm until the magnetic deviation prediction algorithm converges to obtain an optimized magnetic deviation prediction algorithm; based on the optimized magnetic deviation prediction algorithm, obtaining a real-time magnetic deviation parameter value of the magnetic deviation parameter, wherein the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer.

[0005] In a second aspect, an embodiment of the present application provides a magnetic calibration device, which is applied to an electronic device, wherein the electronic device includes a magnetometer, and the device includes: a magnetic deviation parameter value acquisition module, which is used to obtain a first parameter value of the magnetic deviation parameter of the magnetometer at a current moment based on a magnetic deviation prediction algorithm; a magnetic deviation change acquisition module, which is used to obtain a change value of the first parameter value relative to a historical parameter value as a magnetic deviation change, wherein the historical parameter value is the parameter value of the magnetic deviation parameter at a target moment before the current moment; a parameter optimization module, which is used to iteratively optimize the target parameter in the magnetic deviation prediction algorithm if the magnetic deviation change is greater than a first threshold value until the magnetic deviation prediction algorithm converges to obtain the optimized magnetic deviation prediction algorithm; a real-time magnetic deviation acquisition module, which is used to obtain a real-time magnetic deviation parameter value of the magnetic deviation parameter based on the optimized magnetic deviation prediction algorithm, and the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer.

[0006] In a third aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors; a memory; one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the above-mentioned method.

[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored. The program code can be called by a processor to execute the above method.

[0008] In the scheme provided by the present application, based on the magnetic bias prediction algorithm, the first parameter value of the magnetic bias parameter of the magnetometer at the current moment is obtained; the change value of the first parameter value relative to the historical parameter value is obtained as the magnetic bias change amount, and the historical parameter value is the parameter value of the magnetic bias parameter at the target moment before the current moment; if the magnetic bias change amount is greater than the first threshold, the target parameter in the magnetic bias prediction algorithm is iteratively optimized until the magnetic bias prediction algorithm converges to obtain the optimized magnetic bias prediction algorithm; based on the optimized magnetic bias prediction algorithm, the real-time magnetic bias parameter value of the magnetic bias parameter is obtained, and the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer. In this way, when it is detected that the magnetic bias parameter at the current moment has a sudden change compared with the parameter value of the magnetic bias parameter at the historical target moment, the target parameter in the magnetic bias prediction algorithm is optimized so that the optimized magnetic bias prediction algorithm can more accurately predict the real-time value of the magnetic bias parameter of the magnetometer. That is, the real-time calibration of the magnetic bias parameter is realized, and then the real-time magnetic data collected by the magnetometer is calibrated using the accurate real-time magnetic bias parameter value, so as to better realize the real-time magnetic calibration. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0010] Figure 1 A schematic flow chart of a magnetic calibration method provided in an embodiment of the present application is shown.

[0011] Figure 2 A schematic flow chart of a magnetic calibration method provided in another embodiment of the present application is shown.

[0012] Figure 3 It is a block diagram of a magnetic calibration device provided according to an embodiment of the present application.

[0013] Figure 44 is a block diagram of an electronic device for executing a magnetic calibration method according to an embodiment of the present application.

[0014] Figure 5 It is a storage unit of an embodiment of the present application for storing or carrying a program code for implementing the magnetic calibration method according to an embodiment of the present application. DETAILED DESCRIPTION

[0015] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0016] It should be noted that in some processes described in the specification, claims and the above-mentioned drawings of the present application, multiple operations that appear in a specific order are included, and these operations may not be executed or executed in parallel in the order in which they appear in this article. The sequence numbers of operations such as S110, S120, etc. are only used to distinguish different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or less operations, and these operations may be executed in sequence or in parallel. And, the terms "first", "second", etc. in the specification, claims and the above-mentioned drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or server that includes a series of steps or sub-modules is not necessarily limited to those steps or sub-modules explicitly listed, but may include other steps or sub-modules that are not explicitly listed or that are inherent to these processes, methods, products, or devices.

[0017] In related technologies, when manufacturers produce magnetometers, due to process and technology reasons, the measured values ​​of the magnetometers in actual applications have certain deviations from the real data. Based on this, the magnetic deviation parameters of the magnetometer are generally calculated before use, and the magnetic deviation parameters are used to compensate for the deviation caused by the measurement.

[0018] However, in actual applications, there are usually magnetic materials around the magnetometer, or materials that can affect the local magnetic field strength. These magnetic materials or materials that affect the local magnetic field strength will interfere with the magnetic field, resulting in deviations in the magnetometer data. In other words, as the environment around the magnetometer changes, the interference to the magnetic field will also change, and the deviation in the magnetometer data will also change accordingly.

[0019] The inventor proposes a magnetic calibration method, device, electronic device and storage medium. When the parameter value of the magnetic deviation parameter suddenly changes, the algorithm parameters in the magnetic deviation prediction algorithm are optimized, and the optimized magnetic deviation prediction algorithm is used to accurately estimate the real-time parameter value of the magnetic deviation parameter. The magnetic calibration method provided in the embodiment of the present application is described in detail below.

[0020] Please refer to Figure 1 , Figure 1 A flowchart of a magnetic calibration method provided in an embodiment of the present application is shown below. Figure 1 The magnetic calibration method provided in the embodiment of the present application is described in detail. The magnetic calibration method may include the following steps:

[0021] Step S110: Based on the magnetic deflection prediction algorithm, a first parameter value of the magnetic deflection parameter of the magnetometer at the current moment is obtained.

[0022] In this embodiment, the magnetic deviation prediction algorithm can be an extended Kalman filtering (Extend Kalman filtering, EKF) algorithm, an unscented Kalman Filter (Unscented Kalman Filter, UKF) algorithm or a cubic Kalman Filter (Cubature Kalman Filter, CKF) algorithm. Among them, the EKF algorithm has a simple structure, is suitable for scenarios with low nonlinearity, and has a small amount of calculation; the UKF algorithm can handle nonlinear systems, and does not need to linearize the system, and can more accurately estimate hidden state variables; the CKF algorithm is suitable for high-dimensional systems, with high filtering accuracy and good convergence, but the amount of calculation is large. Therefore, the specific algorithm used as the magnetic deviation prediction algorithm in this embodiment can be selected according to the actual application requirements; of course, any algorithm in the relevant technology that can be used to estimate the magnetic deviation parameters is within the protection scope of this application, and will not be repeated here one by one.

[0023] It can be understood that the magnetometer detects magnetic induction along its own X-axis, Y-axis and Z-axis. Obviously, the first self-parameter value of the magnetic deflection parameter of the magnetometer estimated based on the magnetic deflection prediction algorithm at the current moment includes the magnetic deflection parameter value bx of the magnetic induction intensity detected along the X-axis, the magnetic deflection parameter value by of the magnetic induction intensity detected along the Y-axis and the magnetic deflection parameter value bz of the magnetic induction intensity detected along the Z-axis at the current moment.

[0024] Step S120: Obtain a change value of the first parameter value relative to a historical parameter value as a magnetic deviation change amount, wherein the historical parameter value is a parameter value of the magnetic deviation parameter at a target moment before the current moment.

[0025] Step S130: If the magnetic deviation change is greater than a first threshold, iteratively optimize the target parameters in the magnetic deviation prediction algorithm until the magnetic deviation prediction algorithm converges to obtain an optimized magnetic deviation prediction algorithm.

[0026] Among them, the target moment before the current moment is the moment before the current moment, which can also be understood as the moment when the magnetometer was last sampled. The length of the time interval between the target moment and the current moment is determined by the sampling frequency of the magnetometer. Without considering external environmental factors, the magnetic deflection parameter of the magnetometer should be a fixed value; however, in practical applications, changes in the external environment will cause the parameter value of the magnetic deflection parameter to change greatly. In other words, when the magnetometer is in different positions in the same environment, the parameter value of the magnetic deflection parameter will only fluctuate slightly; if the magnetometer switches from one environment to another, for example, from a computer room to an open square, the parameter value of the magnetic deflection parameter will fluctuate greatly.

[0027] Therefore, the magnetic deviation change of the first parameter value relative to the historical parameter value can be obtained, and the magnetic deviation change can be compared with the first threshold value. Based on the comparison result, it is measured whether the environment in which the magnetometer is located has changed. The change in the environment may be that the magnetometer moves from the current environment to another environment, or that the magnetic material in the current environment moves or changes, etc.

[0028] Optionally, if the change in magnetic deviation is greater than a first threshold, it indicates that the environment in which the magnetometer is currently located has changed. It is understandable that, when the environment changes, the relevant target parameters in the magnetic deviation prediction algorithm used to predict the magnetic deviation parameters of the magnetometer in the current environment also need to be adjusted accordingly to ensure the accuracy of the parameter value prediction of the magnetic deviation parameters. Among them, the target parameters in the magnetic deviation prediction algorithm are iteratively optimized until the magnetic deviation prediction algorithm converges, and a magnetic deviation prediction algorithm that converges in the current environment is obtained as the above-mentioned optimized magnetic deviation prediction algorithm. It is understandable that after multiple iterations of the magnetic deviation prediction algorithm, the value predicted by the magnetic deviation prediction algorithm tends to a certain value. In layman's terms, the converged magnetic deviation prediction algorithm can more accurately predict the parameter value of the magnetic deviation parameters of the magnetometer in the environment.

[0029] Optionally, if the aforementioned magnetic deviation change is less than or equal to the first threshold, it indicates that the current environment of the magnetometer has not changed, and it can be determined that the first parameter value predicted based on the magnetic deviation prediction algorithm is more accurate. Therefore, the magnetic data collected by the magnetometer at the current moment can be calibrated directly based on the first parameter value.

[0030] Step S140: Based on the optimized magnetic deviation prediction algorithm, a real-time magnetic deviation parameter value of the magnetic deviation parameter is obtained, and the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer.

[0031] Furthermore, the optimized magnetic deflection prediction algorithm is used to more accurately detect the real-time magnetic deflection parameter value of the magnetic deflection parameter, and the real-time magnetic data collected by the magnetometer is calibrated using the real-time magnetic deflection parameter value. The real-time magnetic data is the real-time magnetic induction intensity.

[0032] In some embodiments, the electronic device further includes an accelerometer and a gyroscope, and the accelerometer, the gyroscope and the magnetometer together constitute an inertial measurement unit (IMU). Based on this, the acceleration data measured by the accelerometer and the gyroscope data measured by the gyroscope are obtained; the real-time attitude information of the electronic device is determined according to the acceleration data, the gyroscope data and the calibrated real-time magnetic data. In this way, while ensuring the accuracy of the real-time magnetic data, the accuracy of the determined real-time attitude information of the electronic device is also guaranteed.

[0033] In other implementations, the magnetometer may also independently provide real-time magnetic data to the electronic device, so that applications such as compass applications in the electronic device only need to use the real-time magnetic data to accurately implement corresponding application functions.

[0034] In this embodiment, when it is detected that the magnetic deflection parameter at the current moment has a sudden change compared to the parameter value of the magnetic deflection parameter at the historical target moment, it indicates that the external magnetic interference caused by the external environment has changed, that is, the external environment where the magnetometer is currently located has changed. Therefore, the target parameters in the magnetic deflection prediction algorithm are optimized so that the optimized magnetic deflection prediction algorithm is more compatible with the external environment at the current moment, that is, the real-time value of the magnetic deflection parameter of the magnetometer in the current external environment can be predicted more accurately. That is, the real-time calibration of the magnetic deflection parameter is realized, and then the real-time magnetic data collected by the magnetometer is calibrated using the accurate real-time magnetic deflection parameter value, so as to better realize the real-time magnetic calibration.

[0035] Please refer to Figure 2 , Figure 2 A flowchart of a magnetic calibration method provided in another embodiment of the present application is shown below. Figure 2The magnetic calibration method provided in the embodiment of the present application is described in detail. The magnetic calibration method may include the following steps:

[0036] Step S210: Acquire a plurality of historical magnetometer data collected by the magnetometer.

[0037] The multiple historical magnetometer data are magnetometer data collected by the magnetometer in multiple postures. That is, without manual parameters, the electronic device can automatically obtain the multiple historical magnetometer data collected by the magnetometer, thereby realizing real-time magnetic calibration without manual participation throughout the process.

[0038] Optionally, after detecting that the electronic device stores historically collected magnetometer data exceeding a target number, magnetometer data in multiple postures may be automatically screened out from the historically collected magnetometer data as the multiple historical magnetometer data.

[0039] Step S220: according to the historical position at which the magnetometer collected each of the historical magnetometer data, determine the standard magnetometer data corresponding to the historical position as the standard magnetometer data corresponding to each of the historical magnetometer data, and obtain a plurality of the standard magnetometer data.

[0040] In this embodiment, the historical position may be the latitude and longitude information of the magnetometer when collecting each historical magnetometer data, and the standard magnetometer data corresponding to the latitude and longitude information may be queried by looking up a table. In this way, the standard magnetometer data corresponding to each historical position may be obtained.

[0041] Step S230: Calibrate each of the historical magnetometer data according to the magnetic calibration algorithm, the initial parameter value of the magnetic deviation parameter and the initial parameter value of the second calibration parameter to obtain multiple historical calibration data, and the multiple historical calibration data correspond one-to-one to the multiple standard magnetometer data.

[0042] In this embodiment, the magnetic calibration algorithm can be expressed by the following magnetic calibration formula:

[0043]

[0044] Among them, z b represents the calibrated magnetometer data, that is, the actual magnetic induction intensity after calibration, b represents the magnetic deviation parameter, and the second calibration parameter includes the above formula and K m , K m represents the diagonal matrix of scaling factors, Characterize the non-orthogonal compensation matrix of the device installation, z mIt represents the magnetic induction intensity measured by the magnetometer, and v represents the measurement noise distribution. The measurement noise distribution is recorded in the parameter table provided by the magnetometer manufacturer and is a known value.

[0045] Non-orthogonal compensation matrix K m It can be completely defined as the following matrix:

[0046]

[0047] In the above formula, i b j b k b represents the orthogonal system, i m j m k m It represents a non-orthogonal system, that is, it is used to characterize that the matrix composed of β1~β9 is a non-orthogonal matrix.

[0048] The scale factor diagonal matrix can be completely defined as the following matrix:

[0049]

[0050] Based on this, the above magnetic calibration formula can be used, and based on b, and K m The initial value of is used to calibrate each historical magnetometer data to obtain multiple historical calibration data.

[0051] Step S240: Based on the degree of difference between each of the historical calibration data and the standard magnetometer data corresponding to each of the historical calibration data, and using the optimal estimation algorithm, the initial parameter value of the second calibration parameter is iteratively optimized until the degree of difference is less than the target difference threshold or the degree of difference no longer changes, thereby obtaining the parameter value of the second calibration parameter.

[0052] It can be understood that for the above magnetic calibration formula, the magnetic deviation parameter b, the scale factor diagonal matrix K m And the non-orthogonal compensation matrix are all parameters to be estimated. For the convenience of subsequent description, all parameters Θ to be estimated can be expressed as:

[0053] Θ=[k x k y k z β1…β9b x b y b z ]

[0054] Based on this, a loss function Θ* can be constructed to calculate the degree of difference between each historical calibration data and the standard magnetometer data corresponding to each historical calibration data. The loss function Θ* can be specifically expressed by the following formula:

[0055]

[0056] Where k represents the kth round of optimization of the initial parameter values, Used to characterize the historical calibration data calculated for each historical magnetometer data in the kth round of optimization, z s Characterizes the standard magnetometer data corresponding to each historical magnetometer data. Correspondingly, the above function F(Θ) characterizes the degree of difference between each historical calibration data and the standard magnetometer data corresponding to each historical calibration data.

[0057] Based on this, the parameter to be estimated can be iteratively optimized based on the above loss function and using the optimal estimation algorithm, until the difference is less than the target difference threshold or the difference no longer changes, and the parameter value of the second calibration parameter is obtained. Among them, the optimal estimation algorithm can be the Levenberg-Marquardt method (Levenberg-Marquardt, LM) algorithm, of course, it can also be a Gauss-Newton algorithm, the steepest descent method and other similar optimal estimation algorithms, and the specific optimization algorithm to be used can be selected according to actual needs, and this embodiment does not limit this. Optionally, it can also be based on the above loss function and use the optimal estimation algorithm to iteratively optimize the parameter to be estimated, until the number of iterations reaches the iteration number threshold, and the parameter value of the second calibration parameter is obtained.

[0058] Exemplarily, the above step S340 is explained by taking the target optimization algorithm as the LM algorithm as an example.

[0059] First, we can initialize the parameters, k = 0, v = 2, Θ = Θ0, A = J T J, g = J T F. Where v represents the iteration speed, J is the Jacobian matrix of the loss function, and F is the aforementioned loss function.

[0060] Then, h is calculated according to the iterative formula (A+μI)h=-g, where μ is the damping factor, I is the identity matrix, and h represents the iteration step.

[0061] If h<ε2(||Θ||+ε2), it can be determined that the iteration step is very small, and the parameter optimization loop can be ended to obtain the parameter value of the second calibration parameter at the end of the loop, where ε2 is a preset iteration termination threshold.

[0062] The parameter value Θ of the K+1th round of optimization k+1 , which can be expressed as Θ k+1=Θ k +h, where θ k is the parameter value optimized in the Kth round. Based on this, the scaling factor can be expressed as Where L is the second-order approximation of F.

[0063] Furthermore, if ρ>0, then A=J T J, g = J T F, Continue iterative optimization of parameter values;

[0064] If g<ε1, the parameter optimization cycle ends, where ε1 is the preset iteration termination threshold.

[0065] If ρ≤0, then based on the two formulas of μ=μv and v=2v, the damping factor and iteration speed are increased, and the aforementioned iteration formula is continued to be used to optimize the parameters of Θ until any of the aforementioned conditions for ending the optimization cycle of the parameters is met, and the optimization cycle is ended.

[0066] In this embodiment, since the scale factor diagonal matrix K m And the non-orthogonal compensation matrix It can be regarded as a non-time-varying parameter, and the magnetic deflection parameter b can be regarded as a time-varying parameter. Among them, the time-varying parameter is greatly affected by the environment. Therefore, it is necessary to estimate the time-varying parameter in real time to avoid the occurrence of problems such as unsuccessful correction of real-time magnetic data caused by large changes in the magnetic deflection parameter due to environmental changes. The non-time-varying parameter is almost unaffected by the environment. Therefore, the non-time-varying parameter can be estimated in advance by the LM algorithm. After estimating the non-time-varying parameter, the time-varying parameter is estimated using steps S350 to S380. In this way, the number of parameters that need to be estimated in real time is reduced, thereby reducing the algorithm dimension (from 21 dimensions to 9 dimensions), that is, simplifying the algorithm and improving the algorithm performance.

[0067] That is to say, in the above-mentioned estimation process for the time-invariant parameters, the time-varying parameters will actually be estimated at the same time, but because the time-invariant parameters are very little affected by environmental factors, therefore, after meeting the aforementioned second target condition, the parameter value of the second calibration parameter is saved, and the parameter value of the time-invariant parameter is stored. In each subsequent magnetic calibration, the parameter value of the time-invariant parameter can be directly called. Since the time-varying parameters are greatly affected by environmental factors, there is no need to store the time-varying parameters estimated at this time. That is, steps S210 to S240 are not executed every time the real-time magnetic data is calibrated. Generally, they only need to be executed once. The electronic device can save the parameter value of the second calibration parameter estimated in the first execution for each subsequent magnetic calibration process. In this way, the amount of calculation is reduced and the efficiency of magnetic calibration is also improved.

[0068] Furthermore, since the present application does not use ellipse fitting to estimate parameters, it does not rely on the user's 8-shaped operation. If the user does not operate properly, such as not rotating a certain axis of the magnetometer to 360 degrees, the magnetometer does not collect enough data and the calibration fails. That is, in the present application, the multiple historical magnetic data collected in time do not contain data rotated 360 degrees, and the parameter estimation can still be achieved.

[0069] In some embodiments, in an ideal case, the scale factor diagonal matrix K m And the non-orthogonal compensation matrix (i.e., the parameter value of the second calibration parameter) is generally not affected by environmental factors; however, in actual application scenarios, it has been verified that when magnetic data is collected in two different and distant areas and non-time-varying parameters are estimated, the non-time-varying parameters finally obtained will still be somewhat different. Based on this, in order to further improve the accuracy of the magnetic calibration for the magnetometer, the aforementioned step S310 may include determining the target area where the magnetometer is currently located; and obtaining a plurality of historical magnetometer data collected by the magnetometer in the target area. Among them, the target area can be based on a district, city or province. For example, Chengdu can be regarded as a target area, and Guangzhou can be regarded as another target area. This embodiment does not limit this.

[0070] In other embodiments, multiple target parameter values ​​may be pre-stored, based on which the target area where the magnetometer is currently located may be determined; if there is a target parameter value matching the target area among the stored multiple target parameter values, the target parameter value matching the target area is determined as the parameter value of the second calibration parameter. Among them, multiple target parameter values ​​correspond one-to-one to multiple different areas. In this way, the parameter values ​​of the time-invariant parameters of different areas are pre-calculated and stored, and the corresponding parameter values ​​can be directly called when the parameter values ​​need to be obtained, without the need for temporary calculations, thereby improving the efficiency of magnetic calibration.

[0071] Optionally, if there is no target parameter value matching the target area among the stored multiple target parameter values, the electronic device can filter out multiple target historical magnetic data collected in the target area from the historical magnetic data. Estimate the parameter value of the second calibration parameter corresponding to the target area based on the multiple target historical magnetic data. And, after calculating the parameter value of the second calibration parameter corresponding to the target area, store the parameter value of the second calibration parameter corresponding to the target area.

[0072] In some embodiments, since the electronic device will store the parameter values ​​calculated in different areas of the second calibration parameter, in order to avoid occupying too much memory, when the memory value occupied by the parameter values ​​of the second calibration parameter in different areas exceeds the first memory threshold, the parameter value with a call frequency lower than the first frequency threshold among multiple parameter values ​​can be obtained as the target parameter value, and the target parameter value is deleted. In this way, it can be avoided that the storage of the parameter values ​​of the second calibration parameter in a large number of different areas causes excessive memory to be occupied, affecting the operating efficiency of the electronic device, and the like; at the same time, since the deleted parameter value with a too low call frequency indicates that the parameter value is less likely to be called, it will not interfere with the real-time magnetic calibration.

[0073] In this way, when the memory value occupied by the parameter values ​​of the second calibration parameter in different areas exceeds the first memory threshold, the target area where the electronic device is currently located can be determined; the area distance corresponding to each stored parameter value compared to the target area is obtained to obtain the area distance corresponding to each parameter value; the area whose area distance is greater than the first distance threshold is obtained as the designated area, and the parameter value corresponding to the designated area is deleted. In this way, when the parameter values ​​of the second calibration parameter in a large number of different areas are stored, on the one hand, it is avoided that the parameter value occupies too much memory resources of the electronic device. On the other hand, since the parameter values ​​corresponding to the designated area far from the target area where the electronic device is currently located are deleted first, it indicates that the electronic device will not use the parameter values ​​corresponding to the designated area in a short time. Therefore, the parameter values ​​that will not be called in the near future are deleted first, which will not affect the real-time magnetic calibration in the near future.

[0074] Step S250: Based on the magnetic deflection prediction algorithm, a first parameter value of the magnetic deflection parameter of the magnetometer at the current moment is obtained.

[0075] In some embodiments, the magnetic deviation prediction algorithm may be an EKF algorithm. The EKF algorithm linearizes the nonlinear function by expanding the nonlinear function in a Taylor series manner, retaining the first-order terms, replacing the state transfer matrix in the Kalman filter equation with the Jacobian matrix, and then using the Kalman filter algorithm as a framework to calculate the state estimate and variance of the system.

[0076] In this embodiment, the state equation and observation equation required by the EKF algorithm are first established, the state equation is used to calculate the state variable, and the observation equation is used to calculate the observation variable. Among them, the state equation can be a general formula summarized from daily life experience, but the real value is often different from the one predicted by the state equation because there is process noise that affects the state variable; therefore, it is necessary to introduce a measurement tool for the observed variable actually measured, for example, for detecting the parameter value of the magnetic deflection parameter of the magnetometer, an actual magnetometer can be introduced to measure the observed variable. However, the measurement tool (such as a magnetometer) itself also has errors, resulting in a certain error between the measured value and the real value. The general idea of ​​the extended Kalman filter algorithm is to fuse the state variable with the observation variable to obtain data close to the real data, and then use it as the state variable of the next process, and then fuse it with the observation variable of the next process, and so on, and the final data will be very close to the real data, that is, the parameter value of the magnetic deflection parameter closest to the real value can be estimated by the EKF algorithm.

[0077] Specifically, in addition to the magnetometer, the electronic device also includes a gyroscope, which is used to detect the rotational angular velocity of the electronic device. Among them, the angular velocity can be understood as the physical quantity of the angle at which an object rotates around a certain axis per unit time; and in three-dimensional space, the rotation of an object can also be described by quaternions, and there is no singularity in expressing the rotation of three-dimensional space by quaternions. Therefore, the state equation can be established by combining the gyroscope model and the kinematic equation based on quaternions:

[0078] The gyro model can be expressed by the following formula:

[0079]

[0080]

[0081] Among them, w b is the true value of the carrier angular velocity; b g is the gyro bias; v A and v R Both are uncorrelated Gaussian white noises, and their standard deviations correspond to the angle random walk and angular velocity random walk, respectively.

[0082] The inverse equation of the quaternion kinematics equation with respect to time can be expressed as:

[0083]

[0084] According to the above gyro model formula and the inverse equation of the quaternion kinematics square length to time, the kinematic equation of the error quaternion can be derived:

[0085]

[0086] Among them, △q v is the vector part of the error quaternion △q; is the gyro bias estimate; × represents an antisymmetric matrix, where all elements on the main diagonal of the antisymmetric matrix are zero, while the elements symmetrical on both sides of the main diagonal have opposite signs.

[0087] Combined with the ideal zero bias state of the magnetometer, the inverse equation of the magnetic bias parameter compared to time can be expressed by the following formula:

[0088]

[0089] Furthermore, the state equation can be expressed as the following matrix:

[0090]

[0091] in, Characterizes the estimate of the gyro bias, Characterizes the estimate of the magnetic bias parameters of the magnetometer.

[0092] At the same time, when only the magnetometer is used as the measurement tool, the following observation equation can be established:

[0093]

[0094] Wherein, △z represents the parameter value of the magnetic deflection parameter detected by the magnetometer;

[0095] H k is the observation matrix, and its specific matrix form can be defined as Represents the cosine transformation matrix from the navigation system to the local system; The representation of the magnetic vector of the current area in the navigation system can be obtained by looking up a table or calculating the IGRF theoretical geomagnetic field.

[0096] Furthermore, after the state equation and observation equation are established, they can be updated using the following formula:

[0097] P k|k-1 =ΦP k-1 Φ T +Q k-1

[0098] K k =P k|k-1 H k T (H k P k|k-1 H k T +R k ) -1

[0099] P k =(IK k H k ) k|k-1 (IK k H k ) T +K k H k K k T

[0100] Among them, Φ is the state transfer matrix, H k is the observation matrix, R k is the measurement noise matrix of the kth round, R k It is used to characterize the difference between the measured value and the true value. Generally, the sensor manufacturer will provide it. If the manufacturer does not provide it, it can also be obtained through testing and debugging; Q k-1 That is, the state noise matrix of the k-1th round. Specifically, Φ, H k , R k and Q k-1 It can be specifically expressed in the following matrix form:

[0101]

[0102]

[0103]

[0104]

[0105] Among them, P k|k-1 Characterize the error covariance of the estimation of the magnetic deflection parameters based on the k-1th round, and calculate the error covariance of the estimation of the magnetic deflection parameters in the current kth round. The kth round can be understood as the estimation round of the magnetic deflection parameters corresponding to the current moment, and the k-1th round can be understood as the estimation round of the magnetic deflection parameters at the target moment before the current moment. That is to say, firstly, according to the error covariance of the magnetic deflection parameters at the target moment, the state noise at the target moment, and the state transfer matrix at the target moment, determine the prior error covariance P at the current moment k|k-1 .

[0106] Furthermore, based on the conversion matrix H between the current state quantity and the observation quantity k , the prior error covariance P k|k-1 , and the observation noise R for the magnetic deflection parameter at the current moment k , determine the Kalman gain coefficient K at the current moment k Then based on the Kalman gain coefficient K at the current momentk , the transformation matrix H k And the prior error covariance P k|k-1 , determine the error covariance P at the current moment k Among them, the error covariance P k The smaller the more precise.

[0107] Based on this, the state quantity of the state equation and the observation quantity of the observation equation can be updated based on the prior error covariance, Kalman gain coefficient and error covariance to obtain the updated state quantity, that is, the change in the parameter value of the updated magnetic deflection parameter. The optimal estimation result of each round of EKF can be obtained, and the optimal estimation result can be characterized as:

[0108]

[0109] in, K m It can be regarded as a time-invariant parameter and can be estimated in advance by an optimal estimation algorithm such as the Levenberg-Marquardt (LM) algorithm, the Gauss-Newton algorithm or the steepest descent method when the magnetometer is initially calibrated for the first time. It can be understood as the change in the optimal magnetic deflection parameter estimated for the kth round.

[0110] Furthermore, based on the updated state quantity estimated in the optimal estimation result, the first parameter value of the magnetic deviation parameter is predicted, that is, the real-time parameter value of the magnetic deviation parameter can be calculated by the following formula:

[0111]

[0112] If k is 1, Then take the initial value of the magnetic deflection parameter, Characterizes the parameter value of the magnetic deflection parameter of the kth round predicted based on the parameter value of the magnetic deflection parameter of the k-1th round.

[0113] Step S260: Obtain a change value of the first parameter value relative to a historical parameter value as a magnetic deviation change amount, wherein the historical parameter value is a parameter value of the magnetic deviation parameter at a target moment before the current moment.

[0114] In this embodiment, the step S220 may refer to the contents in the above-mentioned embodiments, which will not be described in detail here.

[0115] Step S270: If the magnetic deviation change is greater than the first threshold, increase the parameter value of the error covariance in the magnetic deviation prediction algorithm at the target time.

[0116] In this embodiment, the magnetic deviation prediction algorithm is initialized first, that is, the magnetic deviation prediction algorithm is converged before the magnetic deviation prediction algorithm is used to predict the magnetic deviation parameters. However, since the environment in which the magnetometer is located may change, and the parameters in the magnetic deviation prediction algorithm after the first initialization are not applicable to all environments, it is necessary to determine whether the magnetic deviation prediction algorithm needs to be reinitialized according to the change value of the magnetic deviation parameters, that is, to make the magnetic deviation prediction algorithm converge again in the changed environment.

[0117] Taking the parameter value estimation of the k-th round magnetic deflection parameter as an example, if If it is greater than the first threshold, it indicates that the magnetic deflection parameter has changed suddenly, that is, the current environment of the magnetometer has changed. By resetting the error covariance calculated in the previous round of estimation, that is, resetting P k-1 It can be understood that when the data is multidimensional, the smaller the error covariance, the more accurate it is, that is, the smaller the trace of the error covariance matrix, the more accurate it is. In the convergence process of the magnetic deviation prediction algorithm, P k-1 will gradually converge to a smaller value, and the current magnetic deflection prediction algorithm is based on the environment before it changes. If the P k-1 The converged value is larger than its original value. If P is not k-1 If the error covariance is reset, the convergence speed of the magnetic deflection prediction algorithm will be slow, and it will take a long time to converge, that is, it will take a long time to adjust the parameters in the magnetic deflection prediction algorithm to the real-time parameter values ​​that can accurately predict the magnetic deflection parameters in the current environment. Therefore, when the magnetic deflection change suddenly occurs, the way to reset the error covariance is generally to increase the parameter value of the error covariance at the target time, that is, to increase P k-1 .

[0118] Step S280: Time-update the algorithm parameters in the magnetic deviation prediction algorithm after increasing the error covariance until the parameter value of the magnetic deviation parameter predicted by the updated magnetic deviation prediction algorithm is less than a second threshold value relative to the parameter value of the magnetic deviation parameter predicted last time, thereby obtaining the optimized magnetic deviation prediction algorithm, wherein the second threshold value is less than the first threshold value.

[0119] Further, when increasing the parameter value P of the error covariance at the target time k-1 After that, the sampling data of the magnetometer in a short time after the current moment can be used to update the algorithm parameters in the magnetic deflection prediction algorithm until the parameter value of the magnetic deflection parameter predicted by the updated magnetic deflection prediction algorithm is less than the second threshold value relative to the parameter value of the magnetic deflection parameter predicted last time, thereby obtaining an optimized magnetic deflection prediction algorithm. In each process of updating the algorithm parameters, the estimation of the magnetic deflection parameters can be performed according to the process of optimal estimation based on the EKF algorithm described above, which will not be repeated here.

[0120] Among them, the second threshold is generally smaller than the first threshold, so that the accuracy of the convergence of the magnetic deviation prediction algorithm can be guaranteed. At the same time, the first threshold used to determine whether the magnetic deviation prediction algorithm needs to be reinitialized is larger, which increases the fault tolerance space, that is, the parameter change value of the magnetic deviation parameter fluctuates in a small range, which is in line with practical applications.

[0121] Step S290: Based on the optimized magnetic deviation prediction algorithm, a real-time magnetic deviation parameter value of the magnetic deviation parameter is obtained, and the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer.

[0122] In this embodiment, the specific implementation method of using the optimized magnetic bias prediction algorithm in step S290 to obtain the real-time magnetic bias parameter value of the magnetic bias parameter is similar to the principle of directly using the magnetic bias prediction algorithm to obtain the first parameter value, which will not be repeated here. Furthermore, after step S290, the real-time magnetic data can be calibrated according to the magnetic calibration algorithm, the real-time magnetic bias parameter value and the parameter value of the second calibration parameter. After estimating the real-time magnetic bias parameter value, the parameter value of the pre-calculated non-time-varying parameter (i.e., the second calibration parameter) is obtained, and the real-time magnetic data collected by the magnetometer is calibrated using the magnetic calibration formula mentioned above.

[0123] In this embodiment, the target optimization algorithm can be used in advance to estimate the error caused by the inaccurate factory calibration of the magnetometer itself, that is, to estimate the parameter value of the aforementioned second calibration parameter, thereby effectively improving the error caused by the inaccurate factory calibration of the magnetometer itself. In addition, the external magnetic interference caused by the environment is converted into magnetic bias parameters for real-time estimation, so that the magnetic calibration can be completed autonomously, in real time, and without human intervention, that is, no manual operation is required, which improves the user experience. At the same time, the availability of the magnetometer is guaranteed in the magnetic interference area.

[0124] Please refer to Figure 3 , which shows a structural block diagram of a magnetic calibration device 300 provided by an embodiment of the present application, which is applied to an electronic device, wherein the electronic device includes a magnetometer. The device 300 may include: a magnetic deviation parameter value acquisition module 310, a magnetic deviation change acquisition module 320, a parameter optimization module 330 and a real-time magnetic deviation acquisition module 340.

[0125] The magnetic deviation parameter value acquisition module 310 is used to obtain a first parameter value of the magnetic deviation parameter of the magnetometer at a current moment based on a magnetic deviation prediction algorithm.

[0126] The magnetic deviation variation acquisition module 320 is used to obtain the variation of the first parameter value relative to the historical parameter value as the magnetic deviation variation. The historical parameter value is the parameter value of the magnetic deviation parameter at a target time before the current time.

[0127] The parameter optimization module 330 is used to iteratively optimize the target parameters in the magnetic deviation prediction algorithm if the magnetic deviation change is greater than a first threshold value, until the magnetic deviation prediction algorithm converges, thereby obtaining the optimized magnetic deviation prediction algorithm.

[0128] The real-time magnetic deviation acquisition module 340 is used to obtain the real-time magnetic deviation parameter value of the magnetic deviation parameter based on the optimized magnetic deviation prediction algorithm, and the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer.

[0129] In some embodiments, the magnetic deviation prediction algorithm is a Kalman filter algorithm, and the parameter optimization module 430 can be specifically used to: if the magnetic deviation change is greater than the first threshold, increase the parameter value of the error covariance in the magnetic deviation prediction algorithm at the target time; perform time updating on the algorithm parameters in the magnetic deviation prediction algorithm after increasing the error covariance, until the parameter value of the magnetic deviation parameter predicted by the updated magnetic deviation prediction algorithm is less than the second threshold value relative to the parameter value of the magnetic deviation parameter predicted last time, thereby obtaining the optimized magnetic deviation prediction algorithm, wherein the second threshold value is less than the first threshold value.

[0130] In some embodiments, the magnetic bias parameter is a first calibration parameter in a magnetic calibration algorithm, the magnetic calibration algorithm further includes a second calibration parameter, and the magnetic calibration device 300 may further include: a magnetic bias calibration module. The magnetic bias calibration module may be used to calibrate the real-time magnetic data according to the magnetic calibration algorithm, the real-time magnetic bias parameter value, and the parameter value of the second calibration parameter after obtaining the real-time parameter value of the magnetic bias parameter based on the optimized magnetic bias prediction algorithm.

[0131] In some embodiments, the magnetic calibration device 300 may further include: a historical magnetic data acquisition module, a standard magnetic data acquisition module, a historical calibration data acquisition module, and a second parameter value acquisition module. The historical magnetic data acquisition module may be used to acquire a plurality of historical magnetometer data collected by the magnetometer before calibrating the real-time magnetic data according to the magnetic calibration algorithm, the real-time magnetic deflection parameter value, and the parameter value of the second calibration parameter. The standard magnetic data acquisition module may be used to determine the standard magnetometer data corresponding to the historical position according to the historical position at which the magnetometer collects each of the historical magnetometer data, as the standard magnetometer data corresponding to each of the historical magnetometer data, to obtain a plurality of the standard magnetometer data. The historical calibration data acquisition module may be used to calibrate each of the historical magnetometer data according to the magnetic calibration algorithm, the initial parameter value of the magnetic deflection parameter, and the initial parameter value of the second calibration parameter, to obtain a plurality of historical calibration data, wherein the plurality of historical calibration data corresponds to the plurality of standard magnetometer data one by one. The second parameter value acquisition module can be used to iteratively optimize the initial parameter value of the second calibration parameter based on the degree of difference between each of the historical calibration data and the standard magnetometer data corresponding to each of the historical calibration data, and use the optimal estimation algorithm until the degree of difference is less than the target difference threshold or the degree of difference no longer changes, thereby obtaining the parameter value of the second calibration parameter.

[0132] In this manner, the historical magnetic data acquisition module can be specifically used to: determine the target area where the magnetometer is currently located; and acquire a plurality of historical magnetometer data collected by the magnetometer in the target area.

[0133] In some other embodiments, the magnetic calibration device 300 may further include: an area determination module and a second parameter value matching module. The area determination module may be used to determine the target area where the magnetometer is currently located before calibrating the real-time magnetic data according to the magnetic calibration algorithm, the real-time magnetic deviation parameter value and the parameter value of the second calibration parameter. The second parameter value matching module may be used to determine the target parameter value matching the target area as the parameter value of the second calibration parameter if there is a target parameter value matching the target area among the stored multiple target parameter values.

[0134] In some embodiments, the electronic device further includes an accelerometer and a gyroscope, and the magnetic calibration device 400 may further include: a magnetic calibration module. The magnetic calibration module may be specifically used to obtain the acceleration data measured by the accelerometer and the gyroscope data measured by the gyroscope after calibrating the real-time magnetic data according to the magnetic calibration algorithm, the real-time magnetic deviation parameter value, and the parameter value of the second calibration parameter; and determine the real-time attitude information of the electronic device according to the acceleration data, the gyroscope data, and the calibrated real-time magnetic data.

[0135] In some embodiments, the magnetic deflection prediction algorithm includes a state equation and an observation equation, wherein the state equation is established based on the gyro model and the quaternion kinematic equation for the change state information of the magnetic deflection parameter, and the observation equation is established based on the change state information of the magnetic deflection parameter. The magnetic deflection parameter value acquisition module 310 can be specifically used to: determine the priori error covariance at the current moment according to the error covariance of the magnetic deflection parameter at the target moment, the state noise at the target moment, and the state matrix at the target moment; determine the Kalman gain coefficient at the current moment based on the conversion matrix between the state quantity at the current moment and the observation quantity, the priori error covariance, and the observation noise at the current moment for the magnetic deflection parameter; determine the error covariance at the current moment based on the Kalman gain coefficient at the current moment, the conversion matrix, and the priori error covariance; update the state quantity of the state equation and the observation quantity of the observation equation based on the priori error covariance, the Kalman gain coefficient, and the error covariance to obtain the updated state quantity; and predict the first parameter value of the magnetic deflection parameter based on the updated state quantity.

[0136] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0137] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.

[0138] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0139] In summary, the target optimization algorithm can be used in advance to estimate the error caused by the inaccurate factory calibration of the magnetometer itself, that is, to estimate the parameter value of the aforementioned second calibration parameter, thereby effectively improving the error caused by the inaccurate factory calibration of the magnetometer itself. In addition, the external magnetic interference caused by the environment is converted into magnetic bias parameters for real-time estimation, so that the magnetic calibration can be completed autonomously, in real time, and without human intervention, that is, no manual operation is required, which improves the user experience. At the same time, the availability of the magnetometer is guaranteed in the magnetic interference area.

[0140] The following will be combined Figure 4 An electronic device provided by the present application is described.

[0141] Reference Figure 4 , Figure 4 The structural block diagram of an electronic device 400 provided in an embodiment of the present application is shown, and the above method provided in an embodiment of the present application can be executed by the electronic device 400. The electronic device can be an electronic terminal with a data processing function, and the electronic terminal includes but is not limited to a smart phone, a smart watch, a tablet computer, a laptop computer, an e-book reader, an MP3 (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3) player, an MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) player, a game controller, and a head-mounted display device.

[0142] The electronic device 400 in the embodiment of the present application may include one or more of the following components: a processor 401, a memory 402, and one or more applications, wherein the one or more applications may be stored in the memory 402 and configured to be executed by one or more processors 401, and the one or more programs are configured to execute the method as described in the aforementioned method embodiment.

[0143] The processor 401 may include one or more processing cores. The processor 401 uses various interfaces and lines to connect the various parts of the entire electronic device 500, and executes various functions and processes data of the electronic device 400 by running or executing instructions, programs, code sets or instruction sets stored in the memory 402, and calling data stored in the memory 402. Optionally, the processor 401 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 401 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem can also be integrated into the processor 701 and implemented separately through a communication chip.

[0144] The memory 402 may include a random access memory (RAM) or a read-only memory (ROM). The memory 402 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 402 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as the various corresponding relationships described above) created by the electronic device 400 during use.

[0145] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0146] In several embodiments provided in the present application, the coupling or direct coupling or communication connection between the modules shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or modules, which may be electrical, mechanical or other forms.

[0147] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0148] Please refer to Figure 5 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 500 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.

[0149] The computer-readable storage medium 500 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer-readable storage medium 600 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 500 has storage space for program code 510 that performs any method step of the above method. These program codes can be read from or written to one or more computer program products. The program code 510 can be compressed, for example, in an appropriate form.

[0150] In some embodiments, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device performs the steps in the above-mentioned method embodiments.

[0151] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A magnetic calibration method, characterized in that: Applied to an electronic device, the electronic device includes a magnetometer, and the method includes: Based on the magnetic deflection prediction algorithm, obtaining a first parameter value of the magnetic deflection parameter of the magnetometer at the current moment; Obtaining a change value of the first parameter value relative to a historical parameter value as a magnetic deviation change amount, wherein the historical parameter value is a parameter value of the magnetic deviation parameter at a target time before the current time; If the magnetic deviation change is greater than a first threshold, iteratively optimizing the target parameters in the magnetic deviation prediction algorithm until the magnetic deviation prediction algorithm converges, thereby obtaining an optimized magnetic deviation prediction algorithm; Based on the optimized magnetic deviation prediction algorithm, a real-time magnetic deviation parameter value of the magnetic deviation parameter is obtained, and the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer.

2. The method according to claim 1, characterized in that: The magnetic deviation prediction algorithm is a Kalman filter algorithm. If the magnetic deviation change is greater than a first threshold, iteratively optimizing the target parameters in the magnetic deviation prediction algorithm until the magnetic deviation prediction algorithm converges, and obtaining the optimized magnetic deviation prediction algorithm, including: If the magnetic deviation change is greater than the first threshold, increasing the parameter value of the error covariance in the magnetic deviation prediction algorithm at the target time; The algorithm parameters in the magnetic deviation prediction algorithm after increasing the error covariance are updated over time until the parameter value of the magnetic deviation parameter predicted by the updated magnetic deviation prediction algorithm is less than a second threshold value relative to the parameter value of the magnetic deviation parameter predicted last time, thereby obtaining an optimized magnetic deviation prediction algorithm, wherein the second threshold value is less than the first threshold value.

3. The method according to claim 1, characterized in that The magnetic deviation parameter is a first calibration parameter in a magnetic calibration algorithm, and the magnetic calibration algorithm also includes a second calibration parameter; After obtaining the real-time parameter value of the magnetic deviation parameter based on the optimized magnetic deviation prediction algorithm, the method further includes: The real-time magnetic data is calibrated according to the magnetic calibration algorithm, the real-time magnetic deviation parameter value and the parameter value of the second calibration parameter.

4. The method according to claim 3, characterized in that Before calibrating the real-time magnetic data according to the magnetic calibration algorithm, the real-time magnetic deviation parameter value and the parameter value of the second calibration parameter, the method further includes: Acquire a plurality of historical magnetometer data collected by the magnetometer; Determining, according to the historical position at which the magnetometer collected each of the historical magnetometer data, standard magnetometer data corresponding to the historical position as the standard magnetometer data corresponding to each of the historical magnetometer data, to obtain a plurality of standard magnetometer data; Calibrate each of the historical magnetometer data according to the magnetic calibration algorithm, the initial parameter value of the magnetic deviation parameter, and the initial parameter value of the second calibration parameter to obtain a plurality of historical calibration data, wherein the plurality of historical calibration data correspond one-to-one to the plurality of standard magnetometer data; Based on the degree of difference between each of the historical calibration data and the standard magnetometer data corresponding to each of the historical calibration data, and using an optimal estimation algorithm, the initial parameter value of the second calibration parameter is iteratively optimized until the degree of difference is less than a target difference threshold or the degree of difference no longer changes, thereby obtaining the parameter value of the second calibration parameter.

5. The method according to claim 4, characterized in that The acquiring of a plurality of historical magnetometer data collected by the magnetometer comprises: Determining a target area where the magnetometer is currently located; A plurality of historical magnetometer data collected by the magnetometer in the target area is acquired.

6. The method according to claim 3, characterized in that: Before calibrating the real-time magnetic data according to the magnetic calibration algorithm, the real-time magnetic deviation parameter value and the parameter value of the second calibration parameter, the method further includes: Determining a target area where the magnetometer is currently located; If there is a target parameter value matching the target area among the stored multiple target parameter values, the target parameter value matching the target area is determined as the parameter value of the second calibration parameter.

7. The method according to claim 3, characterized in that The electronic device further includes an accelerometer and a gyroscope. After calibrating the real-time magnetic data according to the magnetic calibration algorithm, the real-time magnetic deviation parameter value and the parameter value of the second calibration parameter, the method further includes: Acquiring acceleration data measured by the accelerometer and gyroscope data measured by the gyroscope; The real-time attitude information of the electronic device is determined according to the acceleration data, the gyroscope data and the calibrated real-time magnetic data.

8. The method according to any one of claims 1 to 7, characterized in that: The magnetic deflection prediction algorithm includes a state equation and an observation equation, wherein the state equation is established based on the gyro model and the quaternion kinematic equation for the change state information of the magnetic deflection parameter, and the observation equation is established based on the change state information of the magnetic deflection parameter. The method of obtaining a first parameter value of a magnetic deviation parameter of the magnetometer at a current moment based on a magnetic deviation prediction algorithm includes: Determine a priori error covariance at a current moment according to the error covariance of the magnetic deviation parameter at the target moment, the state noise at the target moment, and the state matrix at the target moment; Determine the Kalman gain coefficient at the current moment based on the conversion matrix between the state quantity at the current moment to the observation quantity, the priori error covariance, and the observation noise for the magnetic deflection parameter at the current moment; Determine the error covariance at the current moment based on the Kalman gain coefficient at the current moment, the conversion matrix and the priori error covariance; Based on the prior error covariance, the Kalman gain coefficient and the error covariance, the state quantity of the state equation and the observation quantity of the observation equation are updated to obtain an updated state quantity; Based on the updated state quantity, a first parameter value of the magnetic deviation parameter is predicted.

9. A magnetic calibration device, characterized in that: Applied to electronic equipment, the electronic equipment includes a magnetometer, and the device includes: A magnetic deviation parameter value acquisition module, used to acquire a first parameter value of the magnetic deviation parameter of the magnetometer at a current moment based on a magnetic deviation prediction algorithm; A magnetic deviation variation acquisition module, used to acquire a variation of the first parameter value relative to a historical parameter value as the magnetic deviation variation, wherein the historical parameter value is a parameter value of the magnetic deviation parameter at a target time before the current time; A parameter optimization module, configured to iteratively optimize the target parameters in the magnetic deviation prediction algorithm if the magnetic deviation change is greater than a first threshold value, until a first target condition is met, thereby obtaining an optimized magnetic deviation prediction algorithm; The real-time magnetic deviation acquisition module is used to obtain the real-time magnetic deviation parameter value of the magnetic deviation parameter based on the optimized magnetic deviation prediction algorithm, and the real-time parameter value is used to calibrate the real-time magnetic data collected by the magnetometer.

10. An electronic device, characterized in that: include: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, which can be called by a processor to execute the method according to any one of claims 1 to 8.