A real-time calibration method and computer system for magnetometer based on variable forgetting factor
By adopting a magnetometer real-time calibration method based on variable forgetting factors on embedded devices, the problem that real-time calibration of magnetometers in the prior art is not possible, and high accuracy calibration of magnetometers is achieved in a dynamically changing environment.
Patent Information
- Application Number
- CN202210775232.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-01
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2042-07-01
Smart Images

Figure CN114993351B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of magnetometer calibration, and in particular to a real-time magnetometer calibration method and a computer system based on a variable forgetting factor. Background Art
[0002] MARG (Magnetic, Angular Rate, and Gravity, referred to as MARG) is a device that measures the three-axis attitude angle, acceleration, and magnetometer of an object. It is usually used in the fields of drones, aviation, and human attitude tracking. Although the attitude measurement system composed of a single gyroscope has good dynamic performance, the measurement drift will produce cumulative errors and is not suitable for long-term navigation attitude measurement. The electronic compass measurement system composed of an accelerometer and a magnetometer can also calculate the yaw angle information of the carrier. Usually, the data of the gyroscope, accelerometer, and magnetometer are fused by using a fusion algorithm to obtain relatively accurate attitude angle information.
[0003] Research on traditional sensor fusion algorithms such as complementary filtering, Kalman filtering, and gradient descent filtering shows that although the introduction of magnetometers is to reduce errors, it may also increase errors. The magnetometer must be calibrated before use. The usual practice for calibrating the magnetometer is to calibrate it once before leaving the factory or before use, and write the calibration parameters into the storage device.
[0004] The magnetometer signal is easily affected by surrounding electronic devices, which can interfere with the electronic compass and cause inaccurate measurement results. Because the magnetic declination is different in different latitudes of the earth, the calculated yaw angle will also deviate when the device is used in a new location after factory calibration. Changes in device temperature can also cause changes in magnetometer data and introduce errors.
[0005] In other words, a single calibration cannot provide a good method to reduce the actual error for the magnetometer, which is often in actual dynamic changes. The error of the magnetometer affects the sensor fusion algorithm, resulting in inaccurate calculated yaw angle, making the data inconsistent with the actual data of the device, affecting the use effect and the user experience.
[0006] To solve this problem, the magnetometer needs to be calibrated in real time. There are several optional methods for real-time calibration of magnetism, including ellipsoid fitting algorithm, XYZ axial extreme value collection method, etc. Among them, the ellipsoid fitting algorithm has high fitting accuracy, but requires too many computing resources, and the limited resources of embedded devices cannot meet the real-time computing requirements; the XYZ axial extreme value collection method will cause the outdated extreme values to be unable to be removed, and cannot smoothly reflect the impact of environmental changes.
[0007] Therefore, there is an urgent need for a real-time magnetometer calibration method that can be used on embedded devices. Summary of the invention
[0008] The purpose of the invention is to overcome the shortcomings of the above-mentioned prior art and to provide a real-time calibration method and computer system for a magnetometer based on a variable forgetting factor, which can complete the real-time calibration of the magnetometer under the condition of limited computing power of embedded devices.
[0009] In order to achieve the above-mentioned purpose, the invention has the following structure:
[0010] A real-time calibration method for a magnetometer based on a variable forgetting factor comprises the following steps:
[0011] SA, respectively collects the data of the X, Y, and Z axis values of the magnetometer and stores them in the buffer;
[0012] SB, respectively setting a forgetting factor for each of the large data value and the small data value to discard the expired large data value and the small data value to obtain buffer data;
[0013] SC, calculates the buffer value of the buffer data and obtains calibration parameters;
[0014] SD, recalibrates the magnetometer according to the calibration parameters.
[0015] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SA also includes the following steps before step SA:
[0016] Sa, read the X, Y, and Z axis values of the magnetometer in real time to determine whether the magnetometer is moving. If so, execute step SA.
[0017] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step Sa is specifically: reading the X, Y, and Z axial values of the magnetometer in real time, continuously storing the axial values in a FIFO, performing motion detection operations on the axial values in the FIFO, and if the X, Y, and Z axial values all change, it is determined that the magnetometer is moving, and step SA is executed.
[0018] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the method further includes a collection counter, the initial value of which is K. When it is determined that the magnetometer is not moving, the count of the collection counter is reduced by 1 each time the FIFO outputs a data;
[0019] The step Sa specifically includes:
[0020] Sa-1, read the X, Y, and Z axis values of the magnetometer in real time, and continuously store the axis values in a FIFO of length L. After the FIFO is full, perform motion detection operation on the axis values in the FIFO. If the X, Y, and Z axis values all change, it is determined that the magnetometer is moving, and step SA is executed and the acquisition counter count is reset to K; otherwise, it is determined that the magnetometer is not moving, and step Sa-2 is executed;
[0021] Sa-2, continue to execute step SA until the count of the acquisition counter is reduced to 0 and then stop executing step SA.
[0022] In a preferred real-time magnetometer calibration method based on a variable forgetting factor, the FIFO is filled with the axial value before the first use.
[0023] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the buffer includes a total of 6 buffers of length Q, which are respectively set for the X, Y, and Z axes of the magnetometer and are used to store large data values and small data values;
[0024] The step SA specifically includes obtaining the X, Y, and Z axis values of the magnetometer and respectively collecting the large and small data values of the X, Y, and Z axis values of the magnetometer and storing them in the corresponding buffers respectively.
[0025] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the buffers of the large data value and the small data value are respectively provided with a large data value buffer threshold and a small data value buffer threshold for screening and collecting the corresponding axial values.
[0026] In a preferred real-time calibration method for a magnetometer based on a variable forgetting factor, when the axial value of the corresponding axis obtained is greater than the data large value buffer threshold, it enters the corresponding buffer in the data large value buffer; when the axial value of the corresponding axis obtained is less than the data small value buffer threshold, it enters the corresponding buffer in the data small value buffer.
[0027] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SA is preceded by the following steps:
[0028] S0, obtaining the initial rough calibration data of the magnetometer, which includes the maximum value m of the readings in the X, Y, and Z axis directions of the magnetometer max , minimum value m min ;
[0029] S01, according to the maximum values m max , minimum value m min , calculate the diameter threshold m diameter , m diameter=m max -m min .
[0030] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the estimation formula of the data large value buffer threshold is:
[0031] ||m calc ||=m max -0.5×m diameter +ratio×0.5×m diameter ;
[0032] In other preferred embodiments, the estimation formula of the data large value buffer threshold may also be:
[0033] ||m calc ||=m min +0.5×m diameter +ratio×0.5×m diameter ;
[0034] The estimation formula of the data small value buffer threshold is:
[0035] ||m calc ′||=m min +0.5×m diameter -ratio×0.5×m diameter ;
[0036] Where m diameter is the diameter threshold, and ratio is the motion judgment threshold.
[0037] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SB is specifically as follows:
[0038] SB, for each axial value entering the buffer, a forgetting factor is set, the initial value of the forgetting factor is N, and each time a new value enters the buffer later, the forgetting factors of other axial values in the buffer are reduced by 1, and the axial values with small forgetting factors are discarded.
[0039] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SB specifically includes:
[0040] SB-1, for each axial value entering the buffer, a forgetting factor is set, the initial value of the forgetting factor is N, and each time a new value enters the buffer, the forgetting factor of the other axial values in the buffer is reduced by 1. When the forgetting factor is reduced to 0, it will no longer decrease.
[0041] SB-2, determine whether the buffer is full. If full, discard the extreme value and the axial value with the smallest forgetting factor.
[0042] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, each time a new axial value enters the buffer, the data in the corresponding buffer are reordered according to the size of the module value;
[0043] The step SB-2 is specifically as follows: determine whether the buffer is full. If not, do not discard the axial value; if full, for a large data value buffer, discard the axial value with the smallest modulus value obtained by adding the forgetting factor; for a small data value buffer, discard the axial value with the largest modulus value obtained by subtracting the forgetting factor.
[0044] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, step SB-3 is included after step SB-2, and a historical value counter is provided. Each time an axial value is discarded, the historical value counter is increased by 1; whenever the historical value counter is Z, the axial value with the smallest forgetting factor in the buffer is discarded, and the historical value counter is set to 0.
[0045] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, step SB-4 is also included which is executed simultaneously with step SB-3. Whenever the historical value counter is Z, the axial value obtained by entering the cache directly enters the buffer.
[0046] In a preferred real-time calibration method for a magnetometer based on a variable forgetting factor, the maximum count Z of the history value counter is 10.
[0047] In the preferred real-time calibration method for a magnetometer based on a variable forgetting factor, the step SC is specifically, when the buffer is full, respectively calculating the buffer value of each buffer to obtain the calibration parameters for calibrating the magnetometer.
[0048] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the calibration parameters include the factory axial scaling parameters of the magnetometer, the origin offset of the magnetometer X, Y, and Z axes calculated by the buffer value, and the sphere kneading coefficient.
[0049] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SD is specifically: notifying the upper-layer application that the magnetometer parameters have been updated through a function callback, and the upper-layer application recalibrates the magnetometer according to the new calibration parameters to obtain a heading angle that meets the current situation.
[0050] The present application also includes a computer system including a storage device storing computer instructions, wherein the computer system is connected to and controls the sensor; when the instructions are executed by the computer, a real-time calibration method of a magnetometer based on a variable forgetting factor is implemented, the method comprising the steps of:
[0051] SA, obtains the X, Y, and Z axis values of the magnetometer and respectively collects the data maximum value and data minimum value of the X, Y, and Z axis values of the magnetometer and stores them in a buffer;
[0052] SB, respectively setting a forgetting factor for each of the large data value and the small data value to discard the expired large data value and the small data value to obtain buffer data;
[0053] SC, calculates the buffer value of the buffer data and obtains calibration parameters;
[0054] SD, recalibrates the magnetometer according to the calibration parameters.
[0055] The present invention discloses a real-time calibration method and computer system for a magnetometer based on a variable forgetting factor. The method comprises the following steps: SA, obtaining the X, Y, and Z axis values of the magnetometer and respectively collecting the data large values and data small values of the X, Y, and Z axis values of the magnetometer and storing them in a buffer; SB, respectively setting a forgetting factor for each of the data large values and data small values to discard the expired data large values and data small values to obtain buffer data; SC, performing buffer value calculation on the buffer data and obtaining calibration parameters; SD, recalibrating the magnetometer according to the calibration parameters. The technical solution of the present invention can improve the influence of recent data on the calibration results, reduce the influence of expired data on the calibration results, and make the calibration parameters more accurate by setting a forgetting factor to discard expired values.
[0056] The real-time calibration method and computer system of the magnetometer based on the variable forgetting factor of the present application also include the buffer including 6 buffers of length Q respectively set for the magnetometer X, Y, and Z axes for storing large data values and small data values; the step SA specifically includes collecting the large data values and small data values of the axial values of the magnetometer X, Y, and Z axes and storing them in the corresponding buffers respectively. By calculating the buffer value of the axial value in the buffer, the influence of occasional extreme values on the buffer value is reduced, and the influence of extreme data on the accuracy of the calibration parameters is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 A step diagram of a first embodiment of a preferred magnetometer real-time calibration method;
[0058] Figure 2 A step diagram of a second embodiment of a preferred magnetometer real-time calibration method;
[0059] Figure 3 The present invention is a schematic diagram of the structure of the real-time magnetometer calibration method and computer system for optimal use. DETAILED DESCRIPTION
[0060] The technical solutions in the embodiments of the present disclosure will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work also fall within the scope of protection of the present invention.
[0061] The present application is a real-time calibration method for a magnetometer based on a variable forgetting factor. The method is applicable to MARG devices that use algorithms such as Kalman filtering or complementary filtering to provide users with pitch angles, roll angles, and heading angles. Because the heading angle is calculated by fusion of a gyroscope and a magnetometer, but the geomagnetic field itself is very weak and is often interfered by surrounding electronic devices or magnetic objects such as magnets, how to dynamically resist various magnetic interferences has become a hot topic in MARG research. The calibration method of the present application performs real-time calibration of the magnetometer during motion in the case where the computing power of embedded devices is generally limited, and at the same time eliminates the influence of dynamic changes in temperature and external magnetic environment on the magnetometer through a variable forgetting factor. The calibration method of the present invention is simple to implement and has a wide range of applications.
[0062] First, the magnetometer mathematical model is as follows (measure is the measured value, real is the true value, noise is the measurement error, and drift is the drift):
[0063] m measure= m real +m noise +m drift
[0064] Since the long-term drift of the magnetometer is small, the drift data can be ignored and the model can be simplified as follows:
[0065] m measure ≈m real +m noise
[0066] Diameter m diameter =m max measure -m min measure ≈m max real -m min real ;
[0067] The specific calibration method is as follows Figure 1 and Figure 2 A real-time calibration method for a magnetometer based on a variable forgetting factor is shown, comprising the steps of:
[0068] SA, obtains the X, Y, and Z axis values of the magnetometer and respectively collects the data maximum value and data minimum value of the X, Y, and Z axis values of the magnetometer and stores them in a buffer;
[0069] SB, respectively setting a forgetting factor for each large value and small value of the data to discard the expired large value and small value of the data to obtain buffer data;
[0070] SC, calculates the buffer value of the buffer data and obtains calibration parameters;
[0071] SD, according to the calibration parameters, recalibrates the magnetometer to obtain a heading angle that meets the current situation.
[0072] The present invention proposes a real-time calibration method for a magnetometer based on a variable forgetting factor. With a small amount of calculation, when the computing power of an embedded device is limited, by setting a forgetting factor, on the one hand, the influence of recent data on the calibration result can be increased, and the influence of expired data on the calibration result can be reduced; on the other hand, the influence of extreme values on the data can be reduced, and expired extreme values can also be gradually excluded through the variable forgetting factor, as described below.
[0073] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SA also includes the following steps before step SA:
[0074] Sa, data acquisition, real-time reading of the X, Y, and Z axis values of the magnetometer, respectively detecting whether the module values of the X, Y, and Z axes change. If so, it is considered that the magnetometer is in motion, and step SA is executed to transmit the acquired axial values to the corresponding buffer in the acquisition order.
[0075] Preferably, the technical solution of the present application obtains the axial value measured by the three-axis magnetometer in real time, which is used to monitor whether the magnetometer is in motion or whether the device or carrier on which the magnetometer is installed is in motion. If in motion, the magnetometer data is collected and stored in the buffer.
[0076] Preferably, the magnetometer is in operation by determining whether the modulus values of the X, Y, and Z axes meet the definition of motion in this application through motion detection operations (specific motion detection operations are described in detail below). If the axial values of the X, Y, and Z axes of the magnetometer are all considered to be moving, the magnetometer is determined to be moving; if a unidirectional axis is considered to be stationary, the magnetometer is determined to be not moving.
[0077] Preferably, the present application is provided with a FIFO memory, and the collected magnetometer data first enters the FIFO, and then is transmitted to a specific buffer by the FIFO. Based on the characteristics of the FIFO memory, that is, first-in-first-out, the data entering the FIFO memory is transmitted to the buffer in sequence. At the same time, the X, Y, and Z axial values of the magnetometer in the FIFO can be screened and processed and then transmitted to a specific buffer according to the characteristics and size of the axial values.
[0078] Read the X, Y, and Z axis values of the three-axis magnetometer in real time, store the axis values in FIFO continuously, perform motion detection operation on the axis values in the FIFO, and if the X, Y, and Z axis values all change, determine that the magnetometer is moving and execute step SA.
[0079] The FIFO memory of the present application continuously acquires the three-axis axial value data of the magnetometer in the default state, that is, the acquisition of the X, Y, and Z axial values of the magnetometer in SA; the acquisition in step SA means screening the axial values that meet the set state and conditions in the FIFO and transferring them to the buffer for storage. The acquisition action may not be continuous. The acquisition step is only executed when the set state (i.e., magnetometer movement) and conditions (meeting the data large value buffer threshold or the data small value buffer threshold) are met.
[0080] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, an acquisition counter is also provided. The initial value of the acquisition counter is K, which is expressed as a countdown. When the magnetometer is determined to be not moving, the count of the acquisition counter is reduced by 1 each time the FIFO outputs a data. When the count of the acquisition counter is reduced to 0, it is considered that the magnetometer has not moved continuously within the set time, and the FIFO stops transmitting the axial value to the buffer, and the calibration behavior of the magnetometer stops.
[0081] The step Sa specifically includes:
[0082] Sa-1, read the X, Y, and Z axis values of the magnetometer in real time, and continuously store the axis values in a FIFO of length L. After the FIFO is full, perform motion detection operation on the axis values in the FIFO. If the X, Y, and Z axis values all change, it is determined that the magnetometer is moving, and step SA is executed and the acquisition counter count is reset to K; otherwise, it is determined that the magnetometer is not moving, and step Sa-2 is executed;
[0083] Sa-2, continue to execute step SA until the count of the acquisition counter is reduced to 0 and then stop executing step SA.
[0084] Specifically, the FIFO of the present application continuously obtains the three-axis axial values of the magnetometer. When the motion detection operation determines that the magnetometer is moving, the acquisition counter is the initial value K. If the magnetometer continues to move, the FIFO continues to transmit the axial value to the buffer. When continuous movement is detected, the acquisition counter always maintains the initial value K. When the motion detection operation determines that the magnetometer is not moving, the FIFO continues to transmit the axial value to the buffer while there is still data in the memory. After each transmission, the acquisition counter value is reduced by 1 until the acquisition counter value is reduced to 0, at which time the FIFO stops transmitting the axial value to the buffer. If the axial value newly entering the FIFO is found to be moving in all three directions through the motion detection operation, the acquisition counter is reset to K and the above steps are repeated.
[0085] Preferably, the values of K and L can be determined according to the equipment environment, characteristics and calibration requirements, and the equipment environment and characteristics include the actual measurement environment, magnetometer equipment characteristics or FIFO memory characteristics, etc. Preferably, the value can be variable, and the user can actively adjust the values of K and L, and the values of K and L can also automatically adjust the value of K according to the above equipment environment.
[0086] In a preferred embodiment, before the first use, the FIFO needs to be filled, and after the FIFO is full, the value in the FIFO is subjected to motion detection operation. When the calibration method of the present application is executed, the FIFO memory is always filled with magnetometer data, and the motion detection operation is used to determine in real time whether the magnetometer is moving based on the data in the FIFO memory.
[0087] The specific formula of the motion detection operation is:
[0088] ||move measure ||=max(A)-min(A)-ratio*m diameter ;
[0089] Where A is a FIFO array, max(A) is the maximum axial value in the array, min(A) is the minimum axial value in the array, and m is the maximum axial value in the array. diameter is the diameter threshold, and ratio is the motion judgment threshold.
[0090] If move measure If the calculated value is greater than 0, it is determined that there is motion. Preferably, the present application can adjust the sensitivity of motion judgment by adjusting the ratio.
[0091] In a preferred embodiment, the step SA is specifically to establish a total of 6 buffers of length Q for storing large data values and small data values for the magnetometer X, Y, and Z axes, and store the acquired axial values in the corresponding buffers according to the axial direction and the large data values and small data values.
[0092] Specifically, the buffers of the axial values transmitted by the receiving FIFO are specifically 6 buffers of length Q for storing large data values and small data values for the magnetometer X, Y, and Z axes. Specifically, there are two buffers for storing large data values and small data values of the X-axis axial values, two buffers for storing large data values and small data values of the Y-axis axial values, and two buffers for storing large data values and small data values of the Z-axis axial values.
[0093] Preferably, the length Q of the buffer can be selected according to the equipment environment, characteristics, calibration requirements and other conditions to select a buffer with a specific Q value.
[0094] The data large value buffer is provided with a data large value buffer threshold, and the collected axial value can enter the corresponding buffer in the data large value buffer only when it is greater than the data large value buffer threshold; the data small value buffer is provided with a data small value buffer threshold, and the collected axial value can enter the corresponding buffer in the data small value buffer only when it is less than the data small value buffer threshold. The X, Y, and Z axes of the magnetometer are respectively provided with a data large value buffer threshold and a data small value buffer threshold. By setting the data large value buffer threshold and the data small value buffer threshold, preliminary extreme values are screened and stored in the buffer. If the axial value does not meet the data large value buffer threshold or the data small value buffer threshold of the buffer, it will be discarded.
[0095] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SA is preceded by the following steps:
[0096] S0, obtaining the initial rough calibration data of the magnetometer, which includes the maximum value m of the readings in the X, Y, and Z axis directions of the magnetometer max , minimum value m min ;
[0097] S01, according to the maximum values m max , minimum value m min , calculate the diameter threshold m diameter , m diameter =m max -m min .
[0098] Preferably, step S0 is performed after step Sa.
[0099] The data large value buffer threshold estimation formula is:
[0100] ||m calc ||=m max -0.5*m diameter +ratio*0.5*mdiameter ;
[0101] In other preferred embodiments, the estimation formula of the data large value buffer threshold may also be:
[0102] ||m calc ||=m min +0.5×m diameter +ratio×0.5×m diameter ;
[0103] Where m max is the maximum value of the rough calibration axis, m min is the minimum value of the rough calibration axis, m diameter is the diameter threshold, ratio is the motion judgment threshold,
[0104] The data small value buffer threshold estimation formula is:
[0105] ||m calc ′||=m min +0.5*m diameter -ratio*0.5*m diameter ;
[0106] Where m min is the minimum value of the rough calibration axis, m diameter is the diameter threshold, ratio is the motion judgment threshold;
[0107] The source of the initial rough calibration data may be the calibration value of the device when it leaves the factory, or the value stored in the memory during the last calibration. It can be seen that the data large value buffer threshold and the data large value buffer threshold may be variable, and m is selected according to the actual situation. max and m min , select the m obtained during the last calibration max and m min It can also avoid errors when the equipment leaves the factory.
[0108] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the related technical solution of the forgetting factor of the present application includes step SB, specifically including the steps of:
[0109] SB-1, for each axial value entering the buffer, a forgetting factor is set, the initial value of the forgetting factor is N, and each time a new value enters the buffer, the forgetting factor of the other axial values in the buffer is reduced by 1. When the forgetting factor is reduced to 0, it will no longer decrease.
[0110] SB-2, determine whether the buffer is full. If full, discard the axial value with the smallest forgetting factor.
[0111] Preferably, each time a new axial value enters the buffer, the corresponding data in the buffer are reordered according to the size of the module value to determine the value to be discarded. The module value refers to the value obtained by adding or subtracting the axial value and the forgetting factor.
[0112] In a preferred embodiment, the step SB-2 is specifically as follows: determine whether the buffer is full, if not, do not discard the axial value; if full, for a large data value buffer, discard the axial value with the smallest modulus value obtained by adding the forgetting factor; for a small data value buffer, discard the axial value with the largest modulus value obtained by subtracting the forgetting factor.
[0113] The difference between new data and old data (expired data) is marked by setting a forgetting factor, because the old data has less impact on the real-time state of the magnetometer than the new data. Therefore, when the buffer is full, the data that enters the buffer earliest is discarded through the forgetting factor to reduce the impact of the old data on the calibration results of the magnetometer. Specifically, when the axial value enters the buffer, each axial value is assigned a forgetting factor; when the axial value just enters the buffer, the forgetting factor is the initial value N, and when a new axial value enters the buffer, the forgetting factors of all other axial values in the buffer are reduced by 1. For example, the forgetting factor of the axial value that enters the buffer before becomes N-1, and the forgetting factor of the axial value that enters the buffer before the two axial values becomes N-2, and so on. The smaller the value of the forgetting factor, the higher the order of the data corresponding to the forgetting factor being discarded.
[0114] Preferably, the forgetting factor stops decreasing after decreasing to 0.
[0115] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SB-2 further includes the following steps:
[0116] SB-3 is provided with a history value counter. Each time an axial value is discarded, the history value counter is increased by 1. Whenever the history value counter is Z, the axial value with the smallest forgetting factor in the buffer is discarded, and the history value counter is set to 0.
[0117] Also included is a step performed simultaneously with the step SB-3,
[0118] SB-4, whenever the historical value counter is Z, the axial value obtained by entering the cache directly enters the buffer.
[0119] Preferably, the specific value of the maximum value Z of the historical value counter is 10.
[0120] Preferably, in addition to discarding the value with the smallest forgetting factor when the buffer is full, the present application can also discard the value with the smallest forgetting factor at fixed intervals to further reduce the impact of old data on the calibration result. Specifically, by setting a historical value counter, each time an axial value is discarded in the above step SB-2, the historical value counter is incremented by 1, and whenever the historical value counter is 10, the axial value with the smallest forgetting factor in the current buffer is discarded.
[0121] In a preferred embodiment, whenever the historical value counter is 10, the axial value with the smallest forgetting factor in the current buffer is discarded, and the new axial value entering at this time is directly entered into the buffer zone. Because the axial value with the smallest forgetting factor was discarded before, the buffer must have the length required by the new axial value.
[0122] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SC is specifically as follows: when the buffer is full, the buffer straight buffer value is calculated for each buffer, the factory axial scaling parameters of the magnetometer are read, the origin offset of the X, Y, and Z axes, and the sphere kneading coefficient of the X, Y, and Z axes are calculated, and the calibration parameters for calibrating the magnetometer are obtained.
[0123] The buffer is an area in the cache where data is stored. The calculation formula for the buffer value is:
[0124]
[0125] A is a buffer array, and the axial values in each buffer are averaged to obtain the buffer value used for calibration parameter calculation.
[0126] In other preferred embodiments, a forgetting factor may be included in the calculation of each axial value in the buffer zone, that is, the buffer zone value is obtained by weighted average calculation.
[0127] By performing addition and averaging calculation on the axial values in the buffer, the influence of occasional extreme values on the buffer value is reduced, and the influence of extreme data on the accuracy of the calibration parameters is reduced.
[0128] The calibration parameters are generated by the formula:
[0129] m zero =(M min +M max )*0.5*m factory ;
[0130] m radius =(M max -M min )*0.5*m factory ;
[0131]
[0132] m scale =m avg_radius / m radius ;
[0133] Assume M min Calculate the minimum value for the buffer value, M max Calculate the maximum value for the buffer value, m factory is the factory axial scaling parameter, m zero is the origin offset, m radius is the axial radius, m avg_radius is the mean of the three-axis radius, m scale is the ball kneading coefficient.
[0134] Among them, M min The buffer value calculated in the data small value buffer corresponding to the X, Y, and Z axes; max The buffer values calculated in the data large value buffer corresponding to the X, Y, and Z axes.
[0135] In the preferred real-time calibration method of a magnetometer based on a variable forgetting factor, the step SD is specifically to notify the upper-layer application through a function callback that the parameters have been updated, and the upper-layer application recalibrates the magnetometer according to the new calibration parameters to obtain a heading angle that meets the current situation.
[0136] The present application also includes a computer system including a storage device storing computer instructions, wherein the computer system is connected to and controls the sensor; when the instructions are executed by the computer, a real-time calibration method of a magnetometer based on a variable forgetting factor is implemented, the method comprising the steps of:
[0137] SA, the buffer acquires data, respectively acquires the large and small values of the X, Y, and Z axis values of the magnetometer and stores them in the buffer;
[0138] SB, respectively setting a forgetting factor for each large value and small value of the data to discard the expired large value and small value of the data to obtain buffer data;
[0139] SC, calculates the buffer value of the buffer data and obtains calibration parameters;
[0140] SD, according to the calibration parameters, recalibrates the magnetometer to obtain a heading angle that meets the current situation.
[0141] like Figure 3The figure shows a schematic diagram of a preferred system structure, in which the three-axis axial value data is obtained through the sensor of the magnetometer, and the FIFO obtains the axial value data in real time and stores it in the FIFO. The use of the FIFO reduces the frequency of the processor distributing data to the cache, thereby improving the computer's working efficiency.
[0142] The FIFO distributes and stores the data acquired by the sensor to the corresponding storage according to the defined conditions (including axial direction and threshold) of each buffer when the magnetometer is determined to be in motion. Then, the technical solution of the specific magnetometer real-time calibration method described above in this application is executed.
[0143] The technical solutions in the above-mentioned real-time calibration method of a magnetometer based on a variable forgetting factor can be applied to a computer system as instructions.
[0144] As shown in this application and claims, generally speaking, the terms "comprises" and "includes" only indicate the inclusion of explicitly identified steps and elements, and these steps and elements do not constitute an exclusive list, and the method or device may also include other steps or elements.
[0145] Unless otherwise specifically stated, the components, relative arrangements, functions, and numerical values described in these embodiments do not limit the scope of the present invention. At the same time, it is obvious that for ease of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship. The techniques, methods, and equipment known to ordinary technicians in the relevant fields are not described in detail, but where appropriate, the techniques, methods, and equipment should be regarded as part of the authorization specification. In all examples shown and discussed here, any specific values should be interpreted as merely exemplary and not as a limitation. Therefore, other examples of step-by-step embodiments may have different sequences.
[0146] The above is an explanation of the present invention and should not be considered as a limitation thereof. Although several exemplary embodiments of the present invention have been described, it will be readily understood by those skilled in the art that many modifications may be made to the exemplary embodiments without departing from the technical features of the present invention. Therefore, all of these modifications are intended to be included within the scope of the present invention as defined in the claims. It should be understood that the above is an explanation of the present invention and should not be considered as being limited to the specific embodiments disclosed, and modifications to the disclosed embodiments and other embodiments are intended to be included within the scope of the appended claims. The present invention is defined by the claims and their equivalents.
Claims
1. A real-time calibration method for a magnetometer based on a variable forgetting factor, characterized in that: Includes steps: SA, respectively collects the data large value and data small value of the X, Y, Z axis values of the magnetometer and stores them in the corresponding buffers respectively, wherein the buffers of the data large value and data small value are respectively provided with a data large value buffer threshold and a data small value buffer threshold for screening and collecting the corresponding axial values; SB, respectively set a forgetting factor for each of the large data values and the small data values to discard the expired large data values and the small data values to obtain buffer data, specifically, set a forgetting factor for each axial value entering the buffer, the initial value of the forgetting factor is N, and each time a new value enters the buffer in the later period, the forgetting factors of other axial values in the buffer are reduced by 1, and the axial value with a small forgetting factor is discarded; SC, when the buffer is full, the buffer value is calculated for each of the buffer data, and the calibration parameter is obtained using the following formula: m zero =(M min +M max )*0.5*m factory ; m radius =(M max -M min )*0.5*m factory ; m scale =m avg_radius / m radius ; M min The buffer value calculated in the data small value buffer corresponding to the X, Y, and Z axes; M max is the buffer value calculated in the data large value buffer corresponding to the X, Y, and Z axes, m factory is the factory axial scaling parameter, m zero is the origin offset, m radius is the axial radius, m avg_radius is the mean of the three-axis radius, m scale is the ball kneading coefficient; SD, recalibrates the magnetometer according to the calibration parameters.
2. The real-time calibration method for a magnetometer based on a variable forgetting factor according to claim 1, characterized in that: The step SA also includes the following steps before: Sa, read the X, Y, and Z axis values of the magnetometer in real time to determine whether the magnetometer is moving. If so, execute step SA.
3. The real-time calibration method for a magnetometer based on a variable forgetting factor according to claim 2, characterized in that: The step Sa is specifically as follows: reading the X, Y, and Z axial values of the magnetometer in real time, continuously storing the axial values in the FIFO, performing motion detection operations on the axial values in the FIFO, and if the X, Y, and Z axial values all change, it is determined that the magnetometer is moving, and step SA is executed.
4. The real-time calibration method for a magnetometer based on a variable forgetting factor according to claim 3, characterized in that: The method also includes a collection counter, the initial value of which is K. When it is determined that the magnetometer is not moving, the count of the collection counter is reduced by 1 each time the FIFO outputs a data; The step Sa specifically includes: Sa-1, read the X, Y, and Z axis values of the magnetometer in real time, and continuously store the axis values in a FIFO of length L. After the FIFO is full, perform motion detection operation on the axis values in the FIFO. If the X, Y, and Z axis values all change, it is determined that the magnetometer is moving, and step SA is executed and the acquisition counter count is reset to K; otherwise, it is determined that the magnetometer is not moving, and step Sa-2 is executed; Sa-2, continue to execute step SA until the count of the acquisition counter is reduced to 0 and then stop executing step SA.
5. The real-time calibration method of a magnetometer based on a variable forgetting factor according to claim 3 or 4, characterized in that: The FIFO is filled with the axial value before first use.
6. The real-time calibration method for a magnetometer based on a variable forgetting factor according to claim 1, characterized in that: The buffer includes 6 buffers with a length of Q, which are respectively set for the X, Y, and Z axes of the magnetometer and are used to store large data values and small data values.
7. The real-time calibration method for a magnetometer based on a variable forgetting factor according to claim 6, characterized in that: When the axial value of the corresponding axis obtained is greater than the data large value buffer threshold, it enters the corresponding buffer in the data large value buffer; when the axial value of the corresponding axis obtained is less than the data small value buffer threshold, it enters the corresponding buffer in the data small value buffer.
8. The real-time calibration method for a magnetometer based on a variable forgetting factor according to claim 6, characterized in that: The step SA also includes the following steps before: S0, obtaining the initial rough calibration data of the magnetometer, which includes the maximum value m of the readings in the X, Y, and Z axis directions of the magnetometer max , minimum value m min ; S01, according to the maximum values m max , minimum value m min , calculate the diameter threshold m diameter , m diameter= m max -m min .
9. The real-time calibration method for a magnetometer based on a variable forgetting factor according to claim 8, characterized in that: The estimation formula of the data large value buffer threshold is: ||m calc ||=m max -0.5×m diameter +ratio×0.5×m diameter ; or ||m calc ||=m min +0.5×m diameter +ratio×0.5×m diameter ; The estimation formula of the data small value buffer threshold is: ||m calc ′||=m min +0.5×m diameter -ratio×0.5×m diameter ; Where ratio is the motion judgment threshold.
10. The real-time calibration method of a magnetometer based on a variable forgetting factor according to claim 1 or 6, characterized in that: The step SB specifically includes: SB-1, for each axial value entering the buffer, a forgetting factor is set, the initial value of the forgetting factor is N, and each time a new value enters the buffer, the forgetting factor of the other axial values in the buffer is reduced by 1, and the forgetting factor will no longer decrease when it reaches 0; SB-2, determine whether the buffer is full. If full, discard the axial value with the smallest forgetting factor.
11. The real-time calibration method of a magnetometer based on a variable forgetting factor according to claim 10, characterized in that: Each time a new axial value enters the buffer, the data in the corresponding buffer is reordered according to the size of the module value; The step SB-2 is specifically as follows: determine whether the buffer is full. If not, do not discard the axial value; if full, for a large data value buffer, discard the axial value with the smallest modulus value obtained by adding the forgetting factor; for a small data value buffer, discard the axial value with the largest modulus value obtained by subtracting the forgetting factor.
12. The real-time calibration method of a magnetometer based on a variable forgetting factor according to claim 11, characterized in that: The step SB-2 further comprises the following steps: SB-3 is provided with a history value counter. Each time an axial value is discarded, the history value counter is increased by 1. Whenever the history value counter is accumulated to Z, the axial value with the smallest forgetting factor in the buffer is discarded, and the history value counter is set to 0.
13. The real-time calibration method of a magnetometer based on a variable forgetting factor according to claim 12, characterized in that: The step SB-3 is also performed simultaneously with the step SB-3: SB-4, whenever the historical value counter is Z, the axial value obtained by entering the cache directly enters the buffer.
14. The real-time calibration method of a magnetometer based on a variable forgetting factor according to claim 12 or 13, characterized in that: The maximum count Z of the history value counter is 10.
15. The real-time calibration method of a magnetometer based on a variable forgetting factor according to claim 1, characterized in that: The step SD is specifically as follows: notifying the upper layer application that the magnetometer parameters have been updated through a function callback, and the upper layer application recalibrates the magnetometer according to the new calibration parameters to obtain a heading angle that meets the current situation.
16. A computer system comprising a storage device storing computer instructions, characterized in that The computer system is connected to and controls the sensor; when the instruction is executed by the computer, a real-time calibration method of a magnetometer based on a variable forgetting factor is implemented, the method comprising the steps of: SA, obtain the X, Y, Z axial values of the magnetometer and respectively collect the data large value and data small value of the X, Y, Z axial values of the magnetometer and store them in corresponding buffers respectively, wherein the buffers of the data large value and data small value are respectively provided with a data large value buffer threshold and a data small value buffer threshold for screening and collecting the corresponding axial values; SB, respectively set a forgetting factor for each of the large data values and the small data values to discard the expired large data values and the small data values to obtain buffer data, specifically, set a forgetting factor for each axial value entering the buffer, the initial value of the forgetting factor is N, and each time a new value enters the buffer in the later period, the forgetting factors of other axial values in the buffer are reduced by 1, and the axial value with a small forgetting factor is discarded; SC, when the buffer is full, the buffer value is calculated for each of the buffer data, and the calibration parameter is obtained using the following formula: m zero =(M min +M max )*0.5*m factory ; m radius =(M max -M min )*0.5*m factory ; m scale =m avg_radius / m radius ; M min The buffer value calculated in the data small value buffer corresponding to the X, Y, and Z axes; M max is the buffer value calculated in the data large value buffer corresponding to the X, Y, and Z axes, m factory is the factory axial scaling parameter, m zero is the origin offset, m radius is the axial radius, m avg_radius is the mean of the three-axis radius, m scale is the ball kneading coefficient; SD, recalibrates the magnetometer according to the calibration parameters.
Citation Information
Patent Citations
Cache management method and apparatus
CN108351873A
Method for calibration of magnetic sensor
US20170176546A1