Method and terminal for calibrating magnetometer

By using an inertial measurement unit to collect data when the terminal is off and responding to preset conditions to start the magnetometer in the background for calibration, the bias problem caused by interference from hard magnetic materials in the terminal of the magnetometer is solved. This achieves the effect of being ready to use and accurate immediately, reducing user intervention and power consumption, and improving calibration efficiency and accuracy.

CN121633930APending Publication Date: 2026-03-10HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-28
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

Magnetometers are susceptible to bias due to interference from hard magnetic materials in the terminal. Existing technology requires user intervention for calibration, making it difficult to achieve a ready-to-use effect.

Method used

Data is collected by the inertial measurement unit when the terminal is off. The magnetometer is activated in the background to perform calibration in response to preset conditions. Hard magnetic calibration is performed using data from the magnetometer and the inertial measurement unit, which reduces power consumption and improves calibration accuracy.

Benefits of technology

This enables the magnetometer to be used immediately and accurately at the terminal, reducing user intervention and power consumption, and improving calibration efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121633930A_ABST
    Figure CN121633930A_ABST
Patent Text Reader

Abstract

The invention provides a method for calibrating a magnetometer and a terminal, and relates to the field of terminals.The method is applied to the terminal, the terminal comprises an inertial measurement unit and a magnetometer, the magnetometer is in a closed state, and the method comprises the steps that first data are collected through the inertial measurement unit; starting the magnetometer in the background in response to the condition that the first data meets a preset condition; acquiring second data through the magnetometer; and calibrating the magnetometer based on the second data. According to the technical scheme provided by the invention, the magnetometer can achieve the effects of instant opening, instant use and instant accuracy, and the calibration process does not need user intervention, so that the difficulty of calibrating the magnetometer is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminals, and more particularly to a method and terminal for calibrating a magnetometer. Background Technology

[0002] A magnetometer is a sensor that measures magnetic fields. It can detect orientation by measuring the Earth's magnetic field and is widely used in various terminals. When a magnetometer is placed on a terminal carrier, if there are hard magnetic materials around the terminal that are difficult to demagnetize after being magnetized, the magnetic field sensed by the magnetometer will be biased. Therefore, the magnetometer needs to be calibrated. Summary of the Invention

[0003] In view of this, this application provides a method and terminal for calibrating a magnetometer, which enables the magnetometer to be turned on, used, and accurate immediately, and the calibration process does not require user intervention, thus reducing the difficulty of calibrating the magnetometer.

[0004] To achieve the above objectives, in a first aspect, embodiments of this application provide a method for calibrating a magnetometer, applied to a terminal, the terminal including an inertial measurement unit and a magnetometer, the magnetometer being in a turned-off state, the method including: acquiring first data through the inertial measurement unit; activating the magnetometer in the background in response to the first data satisfying preset conditions; acquiring second data through the magnetometer; and calibrating the magnetometer based on the second data.

[0005] In this embodiment, the terminal includes a magnetometer. When the magnetometer is off, the terminal can collect first data through an inertial measurement unit. In response to the first data meeting preset conditions, the magnetometer is turned on in the background, and second data is collected through the magnetometer. The magnetometer is then calibrated based on the second data. By automatically calibrating the magnetometer in the background, calibration is achieved during idle time when the terminal does not need the magnetometer to run. This allows the magnetometer to run immediately without further calibration after calibration, enabling the terminal and user to experience instant operation and accuracy when using the magnetometer. Furthermore, the calibration process does not require user intervention, reducing the difficulty of calibrating the magnetometer.

[0006] In some implementations, the step of collecting the first data through the inertial measurement unit includes: collecting the first data through the inertial measurement unit when the orientation service is not enabled, wherein the orientation service is a service executed based on the orientation of the terminal in the geographic magnetic field.

[0007] In some implementations, the orientation service includes maps, navigation, or a compass.

[0008] Since the orientation service relies on the magnetometer, the inertial measurement unit collects initial data when the orientation service is not activated. Based on this initial data, it is determined whether the magnetometer needs to be calibrated. This allows the magnetometer to be calibrated during idle time when the orientation service is not being executed. As a result, when the orientation service is triggered, the magnetometer has already been calibrated, and the orientation service can operate directly based on the calibrated magnetometer without needing to calibrate it after the orientation service is triggered. This enables the magnetometer to achieve an instant, ready-to-use, and accurate experience in the orientation service scenario, improving the efficiency of the orientation service and the user experience.

[0009] In some embodiments, after calibrating the magnetometer based on the second data, the method further includes turning off the magnetometer.

[0010] After determining the hard magnetic bias, the terminal can turn off the magnetometer until the orientation service is activated, thereby further reducing power consumption.

[0011] In some implementations, the first data includes multiple gravity vectors of the terminal within a first duration. Before activating the magnetometer in the background in response to the first data satisfying a preset condition, the method further includes: determining a first change in the gravitational acceleration of the terminal within the first duration based on the multiple gravity vectors of the terminal within the first duration; activating the magnetometer in the background in response to the first data satisfying the preset condition includes: activating the magnetometer in the background in response to the first change being greater than or equal to a preset second change.

[0012] For example, the second change could be 10°.

[0013] In some implementations, the first data includes multiple gravity vectors of the terminal within a first duration. Before activating the magnetometer in the background in response to the first data satisfying a preset condition, the method further includes: determining a first motion state of the terminal within the first duration based on the multiple gravity vectors of the terminal within the first duration; activating the magnetometer in the background in response to the first data satisfying the preset condition includes: activating the magnetometer in the background in response to the first motion state being the same as a preset second motion state.

[0014] In some implementations, the first data includes multiple rotation matrices of the terminal within a first duration. Before activating the magnetometer in the background in response to the first data satisfying a preset condition, the method further includes: determining a third change in the attitude of the terminal based on the multiple rotation matrices of the terminal within the first duration; activating the magnetometer in the background in response to the first data satisfying the preset condition includes: activating the magnetometer in the background in response to the third change being greater than or equal to a preset fourth change.

[0015] In some implementations, the first data includes multiple gravity vectors of the terminal during a first time period and multiple rotation matrices of the terminal during the first time period. Preset conditions may include the change in gravitational acceleration of the terminal during the first time period being greater than or equal to a preset second change, and the change in angular velocity of the terminal during the first time period being greater than or equal to a preset fourth change. The terminal may activate the magnetometer in the background in response to the first change being greater than or equal to the preset second change and the third change being greater than or equal to the preset fourth change. Alternatively, preset conditions may include the terminal being in a preset second motion state during the first time period, and the change in angular velocity of the terminal during the first time period being greater than or equal to the preset fourth change. The terminal may activate the magnetometer in the background in response to the first motion state being the same as the preset second motion state and the third change being greater than or equal to the preset fourth change. Alternatively, in other embodiments, the preset conditions may include a first change in the gravitational acceleration of the terminal within a first duration being greater than or equal to a preset second change, the terminal being in a preset second motion state within the first duration, and a third change in the angular velocity of the terminal within the first duration being greater than or equal to a preset fourth change. The terminal may activate the magnetometer in the background in response to the first change being greater than or equal to the preset second change, the first motion state being the same as the preset second motion state, and the third change being greater than or equal to the preset fourth change.

[0016] In some embodiments, the second data includes multiple geomagnetic vectors of the terminal within a second time period, and the calibration of the magnetometer based on the second data includes: determining a hard magnetic bias based on the multiple geomagnetic vectors of the terminal within the second time period, the hard magnetic bias being used to calibrate the magnetometer.

[0017] In some embodiments, the second data includes multiple geomagnetic vectors of the terminal within a second time period, and the method further includes: when the multiple geomagnetic vectors of the terminal within the second time period are collected by the magnetometer, multiple gravity vectors of the terminal within the second time period are also collected by the inertial measurement unit; the calibration of the magnetometer based on the second data includes: determining a hard magnetic bias based on the multiple geomagnetic vectors of the terminal within the second time period and the multiple gravity vectors of the terminal within the second time period, wherein the hard magnetic bias is used to calibrate the magnetometer.

[0018] In some embodiments, the second data includes multiple geomagnetic vectors of the terminal within a second time period, and the method further includes: when the multiple geomagnetic vectors of the terminal within the second time period are acquired by the magnetometer, multiple rotation matrices of the terminal within the second time period are also acquired by the inertial measurement unit; the calibration of the magnetometer based on the second data includes: determining a hard magnetic bias based on the multiple geomagnetic vectors of the terminal within the second time period and the multiple rotation matrices of the terminal within the second time period, wherein the hard magnetic bias is used to calibrate the magnetometer.

[0019] In some embodiments, the second data includes multiple geomagnetic vectors of the terminal within a second time period. The method further includes: when the multiple geomagnetic vectors of the terminal within the second time period are acquired by the magnetometer, multiple gravity vectors of the terminal within the second time period and multiple rotation matrices of the terminal within the second time period are also acquired by the inertial measurement unit. The calibration of the magnetometer based on the second data includes: determining a hard magnetic bias based on the multiple geomagnetic vectors of the terminal within the second time period, the multiple gravity vectors of the terminal within the second time period, and the multiple rotation matrices of the terminal within the second time period, wherein the hard magnetic bias is used to calibrate the magnetometer.

[0020] The terminal calibrates the magnetometer using data collected by the magnetometer and the inertial measurement unit. This reduces the impact of magnetic field changes during the terminal's movement on the magnetometer calibration, thereby further improving the anti-interference capability of the magnetometer calibration function and enhancing the magnetometer's accuracy.

[0021] In some implementations, the terminal includes a magnetometer, a gyroscope, and an accelerometer, with the magnetometer and gyroscope in a switched-off state. With the magnetometer and gyroscope switched off, the terminal acquires multiple gravity vectors over a first time period via the accelerometer. In response to the multiple gravity vectors over the first time period satisfying preset conditions, the magnetometer and gyroscope are activated in the background. The terminal then acquires multiple geomagnetic vectors over a second time period via the magnetometer and multiple rotation matrices over the second time period via the gyroscope. Based on the multiple geomagnetic vectors and rotation matrices over the second time period, a hard magnetic bias is determined.

[0022] The terminal can first collect multiple gravity vectors within a first time period using an accelerometer. Then, when the multiple gravity vectors within the first time period meet preset conditions, the magnetometer and gyroscope are activated in the background. Since the accelerometer's power consumption is lower than that of the gyroscope and magnetometer, collecting multiple gravity vectors within the first time period using the accelerometer and activating the magnetometer and gyroscope in the background only after confirming that the multiple gravity vectors meet preset conditions further reduces the power consumption required for magnetometer calibration. When the terminal collects multiple geomagnetic vectors within a second time period using the magnetometer, it also collects multiple rotation matrices within the second time period using the gyroscope. Based on these geomagnetic vectors and rotation matrices, a hard magnetic bias is determined. This also reduces the impact of magnetic field changes during the terminal's movement on the magnetometer calibration, thereby further improving the anti-interference capability of the magnetometer calibration function and increasing the magnetometer's accuracy.

[0023] In some embodiments, before calibrating the magnetometer based on the second data, the method further includes: in response to the activation of a location service, if the calibration of the magnetometer has not been completed, displaying a first interface, the first interface including first indication information for indicating that the calibration of the magnetometer has not been completed, the location service being a service executed based on the location of the terminal in the geographic magnetic field; after calibrating the magnetometer based on the second data, the method further includes: displaying a second interface, the second interface including location information.

[0024] When the location service is enabled on the terminal, if the magnetometer calibration is not completed, a first interface can be displayed first, and the magnetometer can be automatically calibrated using the magnetometer calibration method provided in this application embodiment. When the calibration is completed, a second interface including location information can be displayed. This realizes that when the user opens the location service and the magnetometer calibration is not completed, the magnetometer can be automatically calibrated without user intervention, which reduces the difficulty of calibrating the magnetometer and improves the user experience when using the location service.

[0025] In some implementations, the step of activating the magnetometer in the background in response to the first data meeting a preset condition includes: activating the magnetometer in the background in response to the first data meeting the preset condition and a third time interval between the current time and the time of the previous calibration of the magnetometer being greater than or equal to a preset fourth time interval.

[0026] Specifically, the longer the fourth duration, the lower the frequency at which the terminal calibrates the magnetometer, the lower the accuracy of the magnetometer, and the lower the power consumption; conversely, the shorter the fourth duration, the higher the frequency at which the terminal calibrates the magnetometer, the higher the accuracy of the magnetometer, and the greater the power consumption.

[0027] In some implementations, the fourth duration can be set by the terminal based on its device type. For example, the fourth duration set for low-power devices (such as smartwatches) can be longer than the fourth duration set for non-low-power devices (such as mobile phones). Alternatively, in some implementations, the fourth duration can be set by the user based on their usage preferences for the terminal, magnetometer, or orientation service.

[0028] In some implementations, after determining the hard magnetic bias, the terminal can use the hard magnetic bias to calibrate the magnetic data collected by the magnetometer in a hard magnetic environment, thereby obtaining the terminal's true magnetic data in the Earth's magnetic field.

[0029] For example, the actual magnetic data of the Earth's magnetic field m0 = m j -m offset m j The magnetic data collected by the magnetometer under hard magnetic interference, m offset This indicates a hard magnetic bias.

[0030] Secondly, embodiments of this application provide an apparatus for calibrating a magnetometer, which has the function of implementing the terminal behaviors described in the above aspects and possible implementations of the above aspects. The functions can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above functions. For example, a transceiver module or unit, a processing module or unit, an acquisition module or unit, etc.

[0031] Thirdly, embodiments of this application provide a terminal, including: a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the method described in any one of the first aspects when the computer program is invoked.

[0032] Fourthly, embodiments of this application provide a chip system including a processor coupled to a memory, wherein the processor executes a computer program stored in the memory to implement the method described in any one of the first aspects above.

[0033] The chip system can be a single chip or a chip module composed of multiple chips.

[0034] Fifthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in any one of the first aspects above.

[0035] Sixthly, embodiments of this application provide a computer program product that, when run on a terminal, causes the terminal to execute the method described in any one of the first aspects.

[0036] It is understood that the beneficial effects of the second to sixth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0037] Figure 1 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application;

[0038] Figure 2 A software structure block diagram of a terminal provided in an embodiment of this application;

[0039] Figure 3 A flowchart illustrating a method for determining orientation information provided in an embodiment of this application;

[0040] Figure 4 A flowchart illustrating a method for calibrating a magnetometer, as provided in this application embodiment;

[0041] Figure 5 A flowchart illustrating another method for calibrating a magnetometer provided in this application embodiment;

[0042] Figure 6 A flowchart illustrating another method for calibrating a magnetometer provided in this application embodiment;

[0043] Figure 7 A flowchart illustrating another method for calibrating a magnetometer provided in this application embodiment;

[0044] Figure 8 A schematic diagram of a display interface provided in an embodiment of this application;

[0045] Figure 9 A schematic diagram of another display interface provided in an embodiment of this application;

[0046] Figure 10 This is a schematic diagram of another display interface provided in an embodiment of this application. Detailed Implementation

[0047] The method for calibrating a magnetometer provided in this application can be applied to terminals such as mobile phones, tablets, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). This application does not impose any restrictions on the specific type of terminal.

[0048] Figure 1 This is a schematic diagram of the structure of a terminal 100 provided in an embodiment of this application. The terminal 100 may include a processor 110, a memory 120, a communication module 130, a magnetometer 140, an inertial measurement unit 150, etc.

[0049] The processor 110 may include one or more processing units, and the memory 120 is used to store program code and data. In this embodiment, the processor 110 can execute computer execution instructions stored in the memory 120 for controlling and managing the actions of the terminal 100.

[0050] The communication module 130 can be used for communication between various internal modules of the terminal 100, or for communication between the terminal 100 and other external terminals, such as communication with a network or other external terminals. For example, the communication module 130 can provide wireless communication solutions applied to the terminal 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), and other wireless communication technologies. Alternatively, the communication module 130 can provide wireless communication solutions applied to the terminal 100, including 2G / 3G / 4G / 5G.

[0051] The magnetometer 140 can be used to identify the terminal's orientation in the Earth's magnetic field. Services performed based on this orientation can be called orientation services. For example, orientation services may include map, navigation, or compass services.

[0052] The inertial measurement unit 150 can be used to measure the attitude angle and angular velocity of an object. In some embodiments, the inertial measurement unit 150 includes an accelerometer 151 and / or a gyroscope 152. Alternatively, in other embodiments, the inertial measurement unit 150 can perform the functions of the accelerometer 151 and / or the gyroscope 152.

[0053] Accelerometer 151 can detect the magnitude of acceleration of terminal 100 in various directions (generally three axes: x, y, and z). When terminal 100 is stationary, it can detect the magnitude and direction of gravity. Accelerometer 151 can also be used to identify the user's behavioral state, such as step counting, walking, running, etc.

[0054] The gyroscope 152 can be used to determine the motion posture of the terminal 100. In some embodiments, the gyroscope 152 can be used to determine the angular velocity of the terminal 100 around three axes. The gyroscope 152 can also be used for navigation and motion-sensing game scenarios.

[0055] Optionally, the terminal 100 may also include a display screen 160, which can display images or videos in the human-computer interaction interface, such as location services, location information, etc.

[0056] Optionally, the terminal 100 may also include peripheral devices 170, such as a mouse, keyboard, speaker, microphone, etc.

[0057] It should be understood that, in addition to Figure 1 In addition to the various components or modules listed, the embodiments of this application do not specifically limit the structure of terminal 100. In other embodiments of this application, terminal 100 may also include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The components illustrated may be implemented in hardware, software, or a combination of software and hardware.

[0058] To facilitate understanding of the technical solutions in the embodiments of this application, the application scenarios of the embodiments of this application will be introduced first below.

[0059] Please refer to Figure 2 This is a schematic diagram illustrating an application scenario of a magnetometer provided in an embodiment of this application. The application scenario includes a raw data reporting layer, a fused attitude calculation layer, and an upper-layer application display layer.

[0060] The raw data reporting layer includes devices, architecture layout, and underlying software. Devices may include a magnetometer 140 and other related hardware, such as an inertial measurement unit 150, an accelerometer 151, or a gyroscope 152. The architecture layout, i.e., the arrangement of the aforementioned devices in the terminal, can be used to improve or eliminate soft and hard magnetic interference from the environment affecting the magnetometer 140. The underlying software can be... Figure 1The processor 110 is used to configure devices such as the magnetometer 140, such as configuring the working mode of the magnetometer 140; it can also be used to preprocess the data collected by the devices, such as filtering and resampling.

[0061] The fusion pose calculation layer can be derived from... Figure 1 The processor 110 in the system includes an algorithm module for processing data acquired by the device. For example, this algorithm module can calibrate the magnetometer 140 and calculate orientation information. For example, this algorithm module can also calculate acceleration based on data acquired by the accelerometer 151 and calculate attitude angles based on data acquired by the gyroscope 152.

[0062] The upper application display layer can be... Figure 1 The processor 110 in the system implements an application layer and a user layer. The application layer is used to implement the interaction between the user layer and the underlying layer. For example, the application layer can implement functions such as text rendering, graphics rendering, layer overlay, image interpolation, human-computer interaction logic, and smooth transition animations. The user layer includes orientation services, which are services executed based on the terminal's orientation in the geomagnetic field. Orientation services are an important service of the terminal. Taking wearable devices as an example, orientation services in wearable devices can include compasses, outdoor sports, map navigation, satellite messages, and games. Accurate orientation information can significantly improve the reliability of orientation services and user experience. For example, based on accurate orientation information, a compass can more accurately indicate the terminal's position relative to the geomagnetic north pole, outdoor sports and games can more accurately display movement trajectories, and satellite messages can more quickly align the terminal's orientation with the satellite direction.

[0063] The communication between the raw data reporting layer, the fused attitude calculation layer, and the upper application display layer, as well as the communication between multiple modules within each layer, can be achieved by... Figure 1 The communication module 130 is implemented in the middle.

[0064] As can be seen from the above description of application scenarios, the application scenarios of magnetometers may include soft magnetic interference and hard magnetic interference.

[0065] Soft magnetic interference is caused by soft magnetic materials near the magnetometer. These materials typically have high permeability and can be rapidly magnetized or demagnetized under the influence of an applied magnetic field. Under specific architectural layouts, soft magnetic effects can usually be characterized and calibrated by a stable soft magnetic matrix.

[0066] Hard magnetic interference is caused by permanent magnets or magnetized metals near the magnetometer. Hard magnetic materials typically have high remanence and coercivity, retaining stable magnetism even after the applied magnetic field is removed. Its effect on the magnetometer output is constant, causing a shift in the center of the magnetometer output curve. Furthermore, because hard magnetic materials are easily remagnetized by an applied magnetic field, the bias of hard magnetic interference can easily change upon contact with a strong magnetic environment, requiring recalibration to eliminate it.

[0067] Assuming the actual magnetic data of the magnetometer in the Earth's magnetic field is m0, then the data measured by the magnetometer under hard magnetic interference is m i For m i =m0+m offset Among them, m0 and m i and m offset All are three-dimensional vectors; m offset Let m be the offset of magnetic data in each direction under hard magnetic interference. offset It can also be called hard magnetic bias.

[0068] To improve the accuracy of the orientation information output by the magnetometer, soft magnetic calibration can be used to reduce soft magnetic interference, and hard magnetic calibration can be used to reduce hard magnetic interference.

[0069] Please refer to Figure 3 This is a schematic diagram illustrating a process for determining location information provided in an embodiment of this application. This method can be used... Figure 3 The application scenario shown includes the following steps:

[0070] Step 1: The magnetometer collects magnetic data.

[0071] In some implementations, the terminal powers on the magnetometer when the orientation service is enabled, thereby activating the magnetometer and enabling it to collect magnetic data.

[0072] In some implementations, it can be by Figure 2 The raw data reporting layer implements step 1.

[0073] Step 2: Perform soft magnetic calibration on the magnetic data.

[0074] It should be noted that the embodiments of this application do not limit the method of soft magnetic calibration.

[0075] In some implementations, the layout of the magnetometer in the terminal can be optimized through the aforementioned architectural layout, thereby omitting the soft magnetic calibration step.

[0076] In some implementations, it can be by Figure 2 Step 2 is implemented in the fusion pose calculation layer.

[0077] Step 3: Perform hard magnetic calibration on the magnetic data.

[0078] In some implementations, the offset of the magnetometer on each axis, i.e., the hard magnetic bias, can be determined by rotating the magnetometer and based on the magnetic data collected during the rotation. This hard magnetic bias is stored in a memory. In subsequent measurements, the magnetic field strength of each axis is subtracted from the offset of the corresponding axis, which can improve hard magnetic interference.

[0079] Taking the calibration of hard magnetic interference in the X-axis direction as an example, the magnetometer can be rotated around the Z-axis (which is perpendicular to the X-axis) for one revolution. During the rotation, magnetic field strength data of the X-axis is collected. Based on the maximum and minimum values ​​of the magnetic field strength data of the X-axis, the offset of the X-axis is half of the sum of the maximum and minimum values.

[0080] In addition, the method of hard magnetic calibration can be further described in detail in the following embodiments.

[0081] In some implementations, it can be by Figure 2 Step 3 is implemented in the fusion pose calculation layer.

[0082] In some implementations, at least one step after step 3 may be omitted.

[0083] Step 4: Calculate the orientation information.

[0084] After the above calibration, the magnetic data of each axis is the same as or very close to the actual magnetic data of the terminal in the Earth's magnetic field at this moment. Therefore, the terminal can further calculate the current orientation information of the terminal based on the magnetic data of each axis.

[0085] In some implementations, it can be by Figure 2 The fusion pose calculation layer shown in step 4 is implemented.

[0086] Step 5: Result fusion.

[0087] In some implementations, the terminal can fuse the calculation results of step 4 with data from other sensors (such as accelerometers and gyroscopes). The fusion result can more accurately indicate the terminal's orientation, acceleration, attitude, and other states.

[0088] In some implementations, it can be by Figure 2 The fusion attitude calculation layer shown in step 5 is implemented.

[0089] In some implementations, the terminal can be accessed via Figure 2 The upper application display layer shown displays the data output from step 4 or step 5, or performs one or more location services based on the data output from step 4 or step 5.

[0090] The following sections will introduce several methods for performing hard magnetic calibration in step 3 above.

[0091] In some implementations, after the orientation service is activated on the terminal, the user manually rotates the terminal to allow the magnetometer to acquire data from various orientations during rotation for calibration. However, this method has two drawbacks. First, because the orientation service must be activated before the magnetometer can be calibrated in the foreground, the orientation service cannot operate normally until the magnetometer calibration is complete, resulting in significant latency. Second, the user needs to manually select the terminal, and the user may not know how to rotate the terminal to calibrate the magnetometer, making the calibration process difficult.

[0092] In some implementations, the hard magnetic calibration algorithm module can reside in the background of the terminal, calibrating the magnetometer as the terminal's posture changes during use. However, this calibration method is unsuitable for power-sensitive terminals, such as smartwatches, due to the high power consumption of the magnetometer. Furthermore, the entire calibration process requires maintaining a stable magnetic field, making it difficult to guarantee calibration accuracy during daily user activities and exhibiting poor resistance to magnetic interference.

[0093] To address at least some of the aforementioned technical problems, this application provides a method for calibrating magnetism. This method uses an inertial measurement unit to detect the state of the terminal. When the terminal's state meets the requirements for magnetometer calibration, the magnetometer is actively activated in the background for calibration, thereby achieving background hard magnetic calibration. This enables the orientation service to achieve an instant, ready-to-use, and accurate experience in relevant user scenarios; improves the power consumption of hard magnetic calibration; and optimizes the interaction logic, reducing disruption to the user.

[0094] The technical solutions of this application will be described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.

[0095] Please refer to Figure 4 This is a flowchart illustrating a method for calibrating a magnetometer according to an embodiment of this application. The method calibrates the magnetometer using data collected by the magnetometer. It should be noted that this method does not rely on... Figure 4 The specific order described below is a limitation. It should be understood that in some embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0096] S401, the terminal acquires the first data through the inertial measurement unit when the magnetometer is in the off state.

[0097] When the magnetometer is off, the terminal collects first data through the inertial measurement unit and determines whether to calibrate the magnetometer based on the first data. This allows the magnetometer to be calibrated during idle time when the terminal does not need to run the magnetometer. After calibration, when the magnetometer is pulled up, it can run immediately without calibration, so that the terminal and the user can achieve an instant, ready-to-use, and accurate experience when using the magnetometer.

[0098] In some embodiments, the inertial measurement unit (IMU) may include at least one of an accelerometer and a gyroscope, or the IMU may be used to implement the functions of an accelerometer and / or a gyroscope. In some embodiments, the first data may include at least one of the terminal's gravity vector and the terminal's rotation matrix within a first duration. In some embodiments, the terminal may acquire multiple gravity vectors within a first duration via an accelerometer or an IMU with accelerometer functionality; and acquire multiple rotation matrices within a first duration via a gyroscope or an IMU with gyroscope functionality. In some embodiments, the first duration may be a pre-set duration, and it should be noted that the embodiments of this application do not limit the method of setting the first duration or the numerical value of the first duration.

[0099] In some implementations, the terminal can collect first data via an inertial measurement unit (IMU) when the magnetometer is off and the orientation service is not activated. The orientation service is a service executed based on the terminal's orientation within the geographic magnetic field. Since the orientation service relies on the magnetometer, collecting the first data via the IMU when the orientation service is not activated, and determining whether to calibrate the magnetometer based on the first data, allows for magnetometer calibration during idle time when the orientation service is not being executed. This ensures that the magnetometer is already calibrated when the orientation service is triggered, allowing the orientation service to operate directly based on the calibrated magnetometer without requiring calibration after the orientation service is triggered. This provides an immediate, ready-to-use, and accurate experience for the magnetometer in orientation service scenarios, improving the efficiency of the orientation service and the user experience.

[0100] In some implementations, the terminal can be accessed via Figure 2The raw data reporting layer shown implements S401. For example, the underlying software configures devices such as accelerometers and gyroscopes, preprocesses the data collected by these devices, and collects data through the accelerometers, gyroscopes, etc. For instance, the terminal can be configured through the underlying software to collect first data via an accelerometer, via a gyroscope, or via both an accelerometer and a gyroscope; the underlying software can also configure the first duration, frequency, etc., of collecting the first data. In some implementations, the first data can be the raw data collected by the accelerometer and / or gyroscope, or it can be data that has been preprocessed by the underlying software.

[0101] S402, the terminal responds to the first data meeting the preset conditions and starts the magnetometer in the background.

[0102] The preset conditions can be set to ensure the terminal meets the requirements for calibrating the magnetometer. When the first data meets these conditions, the magnetometer can be activated in the background, triggering calibration. Activating and calibrating the magnetometer in the background reduces interference with other foreground functions, improving user experience. Furthermore, since the power consumption of the inertial measurement unit (IMU) is significantly lower than that of the magnetometer, determining that the first data meets the preset conditions before triggering calibration, even when the magnetometer is off, further reduces the power consumption required for calibration, significantly improving the terminal's battery life.

[0103] In some implementations, during the calibration of the magnetometer in the terminal, the terminal needs to change its state or posture in space, such as moving or rotating. Therefore, the preset conditions can correspond to the specific state or posture change process of the terminal. When the first data meets the preset conditions, the terminal is currently in that specific state or posture change process, thereby enabling the calibration of the magnetometer.

[0104] In some embodiments, the first data includes multiple gravity vectors of the terminal within a first duration. A preset condition may be that a first change in the terminal's gravitational acceleration within the first duration is greater than or equal to a preset second change. The terminal can determine the first change in its gravitational acceleration within the first duration based on the multiple gravity vectors, and activate the magnetometer in the background in response to the first change being greater than or equal to the preset second change. In some embodiments, gravity vectors at any two moments (e.g., the start and end of the first duration) can be obtained from the multiple gravity vectors within the first duration, and the first change can be determined based on the gravity vectors at these two moments. In some embodiments, the first and second changes are vector changes, including the magnitude and / or direction of the vector. For example, the second change may be 10°, or in other embodiments, the second change may be other values.

[0105] In some implementations, the first data includes multiple gravity vectors of the terminal within a first duration, and the preset condition can be that the terminal is in a preset second motion state within the first duration. The terminal can determine its first motion state within the first duration based on these multiple gravity vectors, and activate the magnetometer in the background if the first motion state matches the preset second motion state. For example, the second motion state can be steps, walking, running, etc., or in other implementations, the second motion state can be any other state.

[0106] In some implementations, the first data includes multiple rotation matrices of the terminal within a first duration, and the preset condition may include a third change in the terminal's angular velocity within the first duration that is greater than or equal to a preset fourth change. The terminal can determine the third change in its attitude based on the multiple rotation matrices within the first duration, and activate the magnetometer in the background in response to the third change being greater than or equal to the preset fourth change. In some implementations, the rotation matrices at any two moments (e.g., the start and end of the first duration) can be obtained from the multiple rotation matrices within the first duration, and the third change can be determined based on the rotation matrices at any two moments.

[0107] In some implementations, the first data includes multiple gravity vectors of the terminal during a first time period and multiple rotation matrices of the terminal during the first time period. Preset conditions may include the change in gravitational acceleration of the terminal during the first time period being greater than or equal to a preset second change, and the change in angular velocity of the terminal during the first time period being greater than or equal to a preset fourth change. The terminal may activate the magnetometer in the background in response to the first change being greater than or equal to the preset second change and the third change being greater than or equal to the preset fourth change. Alternatively, preset conditions may include the terminal being in a preset second motion state during the first time period, and the change in angular velocity of the terminal during the first time period being greater than or equal to the preset fourth change. The terminal may activate the magnetometer in the background in response to the first motion state being the same as the preset second motion state and the third change being greater than or equal to the preset fourth change. Alternatively, in other embodiments, the preset conditions may include a first change in the gravitational acceleration of the terminal within a first duration being greater than or equal to a preset second change, the terminal being in a preset second motion state within the first duration, and a third change in the angular velocity of the terminal within the first duration being greater than or equal to a preset fourth change. The terminal may activate the magnetometer in the background in response to the first change being greater than or equal to the preset second change, the first motion state being the same as the preset second motion state, and the third change being greater than or equal to the preset fourth change.

[0108] In some embodiments, the second change, the fourth change, and the second motion state can be obtained through pre-setting. Alternatively, in other embodiments, during the process of the user manually rotating the terminal to calibrate the magnetometer, the change in gravity of the terminal during this process can be obtained as the second change, the change in angular velocity of the terminal during this process can be obtained as the fourth change, and the motion state of the terminal during this process can be obtained as the second motion state. Alternatively, in other embodiments, the second change, the fourth change, and the second motion state can be determined through other methods.

[0109] In some implementations, when it is determined that the first data meets the preset conditions, it can also be determined whether the third duration between the current time (for example, the current time can be the time when it is determined that the first data meets the preset conditions) and the time when the magnetometer was calibrated last time is greater than or equal to a preset fourth duration. If the third duration is greater than or equal to the preset fourth duration, in response to the first data meeting the preset conditions and the third duration being greater than or equal to the fourth duration, the magnetometer is turned on in the background.

[0110] Specifically, the longer the fourth duration, the lower the frequency at which the terminal calibrates the magnetometer, the lower the accuracy of the magnetometer, and the lower the power consumption; conversely, the shorter the fourth duration, the higher the frequency at which the terminal calibrates the magnetometer, the higher the accuracy of the magnetometer, and the greater the power consumption.

[0111] In some implementations, the fourth duration can be set by the terminal based on its device type. For example, the fourth duration set for low-power devices (such as smartwatches) can be longer than the fourth duration set for non-low-power devices (such as mobile phones). Alternatively, in some implementations, the fourth duration can be set by the user based on their usage preferences for the terminal, magnetometer, or orientation service.

[0112] For example, the terminal can provide users with an automatic calibration mode setting interface, which includes three options: low power, off, and custom. When the user selects the low power mode, the magnetometer is automatically calibrated in the background based on a preset fourth duration. When the user selects the off mode, the magnetometer is not automatically calibrated in the background. When the user selects the custom mode, the magnetometer is automatically calibrated in the background based on the fourth duration set by the user.

[0113] In some implementations, the terminal can be via, for example... Figure 2 The fusion pose algorithm layer implementation step S402 is shown.

[0114] S403, the terminal collects second data through a magnetometer.

[0115] In some implementations, the second data may include multiple geomagnetic vectors of the terminal within a second time period. In some implementations, each of the multiple geomagnetic vectors corresponds to a specific time point. For example, the second data may include a first geomagnetic vector corresponding to a first time point and a second geomagnetic vector corresponding to a second time point, wherein the first and second times are within the second time period.

[0116] In some implementations, the second duration can be obtained by presetting.

[0117] In some implementations, the terminal can be via, for example... Figure 2 The magnetometer implementation step S403 of the raw data reporting layer is shown. In some embodiments, the second data can be data directly acquired by the magnetometer, or the second data can be data after preprocessing the data directly acquired by the magnetometer.

[0118] S404, the terminal calibrates the magnetometer based on the second data.

[0119] In some embodiments, the second data includes multiple geomagnetic vectors of the terminal within a second time period. Based on these geomagnetic vectors, the terminal can determine a hard magnetic bias used to calibrate the magnetometer. In some embodiments, the terminal can perform parameter estimation operations such as least squares calculations or Kalman filtering on the multiple geomagnetic vectors to obtain the hard magnetic bias.

[0120] For example, the second data includes a first geomagnetic vector corresponding to the first time and a second geomagnetic vector corresponding to the second time, and the terminal can determine the hard magnetic bias using the following formula 1.

[0121] |m i -m offset |=|m i+1 -m offset | (Formula 1)

[0122] Where, m offset = (a, b, c), m offset Indicates hard magnetic bias, where a, b, and c represent the hard magnetic bias of the x-axis, y-axis, and z-axis, respectively; m i This represents the geomagnetic vector at time i, i.e., the first geomagnetic vector corresponding to the first time; m i+1 This represents the geomagnetic vector at time i+1, which is the second geomagnetic vector corresponding to the second time.

[0123] In some implementations, the terminal can also use other methods to calculate multiple geomagnetic vectors of the terminal within a second time period to obtain a hard magnetic bias.

[0124] In some implementations, the terminal can determine the hard magnetic bias through iterative solution. In each iteration, it is determined whether the error of the hard magnetic bias is less than a preset error threshold. If so, the iteration continues to determine a new hard magnetic bias until the obtained hard magnetic bias converges.

[0125] For example, similar to the first geomagnetic vector corresponding to the first time point and the second geomagnetic vector corresponding to the second time point, multiple geomagnetic vectors within the second time period can be grouped in pairs according to their corresponding times to obtain multiple groups. Each group of data includes two geomagnetic vectors corresponding to different times. Each group of data can be used to determine the geomagnetic vector. Therefore, the hard magnetic bias can be solved iteratively through these multiple groups.

[0126] In some implementations, after determining the hard magnetic bias, the terminal can use the hard magnetic bias to calibrate the magnetic data collected by the magnetometer in a hard magnetic environment, thereby obtaining the terminal's true magnetic data in the Earth's magnetic field.

[0127] For example, the actual magnetic data of the Earth's magnetic field m0 = m j -m offset m j This is magnetic data collected by a magnetometer under hard magnetic interference.

[0128] In some implementations, the terminal can be via, for example... Figure 2 The fusion pose algorithm layer implementation step S404 is shown.

[0129] In some implementations, after the terminal determines the hard magnetic bias, it can turn off the magnetometer until the orientation service is activated, thereby further reducing power consumption.

[0130] In this embodiment, the terminal includes a magnetometer. When the magnetometer is off, the terminal can collect first data through an inertial measurement unit. In response to the first data meeting preset conditions, the magnetometer is turned on in the background, and second data is collected through the magnetometer. The magnetometer is then calibrated based on the second data. By automatically calibrating the magnetometer in the background, calibration is achieved during idle time when the terminal does not need the magnetometer to run. This allows the magnetometer to run immediately without further calibration after calibration, enabling the terminal and user to experience instant operation and accuracy when using the magnetometer. Furthermore, the calibration process does not require user intervention, reducing the difficulty of calibrating the magnetometer.

[0131] Please refer to Figure 5 This is a flowchart illustrating another method for calibrating a magnetometer provided in an embodiment of this application. This method calibrates the magnetometer using data collected by the magnetometer and the inertial measurement unit, thereby further improving the accuracy of the magnetometer calibration. It should be noted that this method does not rely on...Figure 5 The specific order described below is a limitation. It should be understood that in some embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0132] S501, the terminal collects the first data through the inertial measurement unit when the magnetometer is in the off state.

[0133] In some implementations, the way the terminal executes S501 to collect the first data through the inertial measurement unit can be the same as or similar to the way the terminal executes S401 to collect the first data through the inertial measurement unit.

[0134] S502, the terminal responds to the first data meeting the preset conditions and starts the magnetometer in the background.

[0135] In some implementations, the way the terminal executes S502 in response to the first data meeting the preset conditions and starts the magnetometer in the background can be the same as or similar to the way the terminal executes S402 in response to the first data meeting the preset conditions and starts the magnetometer in the background.

[0136] S503: The terminal collects second data through a magnetometer and third data through an inertial measurement unit.

[0137] In some implementations, the data type of the third data is the same as that of the first data, and the terminal can acquire the third data in the same way it acquires the first data. In some implementations, both the first and third data include a gravity vector, allowing the terminal to acquire the first data via the accelerometer without needing to activate the gyroscope if the first data meets preset conditions. Alternatively, both the first and third data include a rotation matrix, allowing the terminal to acquire the first data via the gyroscope if the first data meets preset conditions without needing to activate the accelerometer. Having the same data type for the third data as the first data eliminates the need to activate the gyroscope or accelerometer when acquiring the third data, further reducing the power consumption required to calibrate the magnetometer.

[0138] In some implementations, the data type of the third data is not exactly the same as the data type of the first data. In some implementations, the first data includes either a gravity vector or a rotation matrix, and the third data includes the other of a gravity vector and a rotation matrix.

[0139] In some implementations, the terminal can collect third data while collecting second data, so that one second data and one third data correspond at the same time.

[0140] In some implementations, the third data includes multiple gravity vectors of the terminal during a second time period. In some implementations, the same moment within the second time period corresponds to a weight vector and a geomagnetic vector. For example, the third data includes a first gravity vector corresponding to a first moment and a second gravity vector corresponding to a second moment.

[0141] In some implementations, the third data includes multiple rotation matrices of the terminal within a second time period. In some implementations, a rotation matrix and a geomagnetic vector correspond to the same moment within the second time period. For example, the third data includes a first rotation matrix corresponding to a first moment and a second rotation matrix corresponding to a second moment.

[0142] In some embodiments, the third data includes multiple gravity vectors of the terminal during the second time period and multiple rotation matrices of the terminal during the second time period. In some embodiments, a weight vector, a geomagnetic vector, and a rotation matrix correspond to the same moment within the second time period.

[0143] S504, the terminal calibrates the magnetometer based on the second and third data.

[0144] The terminal calibrates the magnetometer using data collected by the magnetometer and the inertial measurement unit. This reduces the impact of magnetic field changes during the terminal's movement on the magnetometer calibration, thereby further improving the anti-interference capability of the magnetometer calibration function and enhancing the magnetometer's accuracy.

[0145] In some implementations, the second data includes multiple geomagnetic vectors of the terminal during the second time period, and the third data includes multiple gravity vectors of the terminal during the second time period. The terminal can determine the hard magnetic bias based on the multiple geomagnetic vectors and the multiple gravity vectors of the terminal during the second time period.

[0146] For example, the second data includes a first geomagnetic vector corresponding to the first time and a second geomagnetic vector corresponding to the second time, and the third data includes a first gravity vector corresponding to the first time and a second gravity vector corresponding to the second time. The terminal can determine the hard magnetic bias using the following formula 2.

[0147] (A i+1 -A i )m offset =A i+1 m i+1 -A i m i (Formula 2)

[0148] Where, m offset = (a, b, c), m offsetIndicates hard magnetic bias, where a, b, and c represent the hard magnetic bias of the x-axis, y-axis, and z-axis, respectively; m i This represents the geomagnetic vector at time i, i.e., the first geomagnetic vector at the first moment; m i+1 A represents the geomagnetic vector at time i+1, which is the second geomagnetic vector at the second time; i A represents the gravity vector at time i, i.e., the first gravity vector corresponding to the first time. i+1 This represents the gravity vector at time i+1, which is the second gravity vector corresponding to the second time.

[0149] In some implementations, the second data includes multiple geomagnetic vectors of the terminal during the second time period, and the third data includes multiple rotation matrices of the terminal during the second time period. The terminal can determine the hard magnetic bias based on the multiple geomagnetic vectors and rotation matrices of the terminal during the second time period.

[0150] For example, the second data includes a first geomagnetic vector corresponding to the first time and a second geomagnetic vector corresponding to the second time, and the third data includes a first rotation matrix corresponding to the first time and a second rotation matrix corresponding to the second time. The terminal can determine the hard magnetic bias using the following formula 3.

[0151] R i (m i -m offset ) = R i+1 (m i+1 -m offset ) (Formula 3)

[0152] Where, m offset = (a, b, c), m offset Indicates hard magnetic bias, where a, b, and c represent the hard magnetic bias of the three axes, respectively; m i This represents the geomagnetic vector at time i, i.e., the first geomagnetic vector at the first moment; m i+1 R represents the geomagnetic vector at time i+1, which is the second geomagnetic vector at the second time; i R represents the rotation matrix at time i, i.e., the first rotation matrix at the first time step; i+1 Let represent the rotation matrix at time i+1, which is the second rotation matrix at the second time.

[0153] In some implementations, the second data includes multiple geomagnetic vectors of the terminal during the second time period, and the third data includes multiple gravity vectors of the terminal during the second time period and multiple rotation matrices of the terminal during the second time period. The terminal can determine the hard magnetic bias based on the multiple geomagnetic vectors of the terminal during the second time period, the multiple gravity vectors of the terminal during the second time period, and the multiple rotation matrices of the terminal during the second time period.

[0154] In some implementations, the terminal may also perform calculations on the second and third data in other ways to obtain the hard magnetic bias.

[0155] In some implementations, the terminal can turn off the magnetometer after determining the hard magnetic bias, thereby further reducing the power consumption of the terminal.

[0156] In this embodiment, while the terminal collects the second data through the magnetometer, it also collects the third data through the inertial measurement unit. This allows the magnetometer to be calibrated based on the second and third data, reducing the impact of magnetic field changes during the terminal's movement on the magnetometer calibration. This further improves the anti-interference capability of the magnetometer calibration function and enhances the accuracy of the magnetometer.

[0157] Please refer to Figure 6 This is a flowchart illustrating another method for calibrating a magnetometer provided in an embodiment of this application. The method can be... Figure 5 One implementation of the method shown involves determining whether to calibrate the magnetometer using data collected by the accelerometer while both the magnetometer and gyroscope are off. Then, the magnetometer and gyroscope are activated to collect data for calibration. This effectively reduces the power consumption of magnetometer calibration and improves its accuracy. It should be noted that this method does not rely on... Figure 6 The specific order described below is a limitation. It should be understood that in some embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0158] S601, with the magnetometer and gyroscope in the off state, the terminal collects multiple gravity vectors within a first time period through the accelerometer.

[0159] In some implementations, the terminal executes S601 by collecting multiple gravity vectors of the terminal within a first time period using an accelerometer, as detailed in the aforementioned S401.

[0160] S602, the terminal responds to the fact that multiple gravity vectors of the terminal within a first time period meet preset conditions, and activates the magnetometer and gyroscope in the background.

[0161] The power consumption of the accelerometer is less than that of the gyroscope and magnetometer. Therefore, the accelerometer first collects multiple gravity vectors of the terminal within a first time period. When the multiple gravity vectors within the first time period meet the preset conditions, the magnetometer and gyroscope are turned on in the background, which further reduces the power consumption required to calibrate the magnetometer.

[0162] In some implementations, the way the terminal executes S602 to determine that multiple gravity vectors of the terminal within a first time period meet preset conditions can be found in the detailed description of S402 above.

[0163] S603, the terminal acquires multiple geomagnetic vectors within a second time period through a magnetometer, and acquires multiple rotation matrices within a second time period through a gyroscope.

[0164] In some implementations, the terminal can simultaneously acquire multiple geomagnetic vectors of the terminal within a second time period via a magnetometer and multiple rotation matrices of the terminal within a second time period via a gyroscope.

[0165] In some implementations, a rotation matrix and a geomagnetic vector correspond to the same moment within the second time period. For example, the multiple geomagnetic vectors within the second time period include a first geomagnetic vector corresponding to the first moment and a second geomagnetic vector corresponding to the second moment, and the multiple rotation matrices within the second time period include a first rotation matrix corresponding to the first moment and a second rotation matrix corresponding to the second moment.

[0166] In some implementations, the terminal performs S603 by acquiring multiple geomagnetic vectors of the terminal within a second time period through a magnetometer, and also acquires multiple rotation matrices of the terminal within a second time period through a gyroscope, as described in detail in the aforementioned S503.

[0167] S604, the terminal determines the hard magnetic bias based on multiple geomagnetic vectors of the terminal during the second time period and multiple rotation matrices of the terminal during the second time period.

[0168] By using the geomagnetic vector collected by the magnetometer and the rotation matrix collected by the gyroscope to determine the hard magnetic bias, the influence of magnetic field changes during terminal movement on the magnetometer calibration can be reduced, thereby further improving the anti-interference capability of the magnetometer calibration function and improving the accuracy of the magnetometer.

[0169] In some implementations, the terminal executes S604 to determine the hard magnetic bias method based on multiple geomagnetic vectors of the terminal during the second time period and multiple rotation matrices of the terminal during the second time period, as detailed in the aforementioned S504.

[0170] In some implementations, the terminal can turn off the magnetometer and gyroscope after determining the hard magnetic bias, thereby further reducing the terminal's power consumption.

[0171] In this embodiment, the terminal can first collect multiple gravity vectors within a first time period using an accelerometer. Then, when it is determined that the multiple gravity vectors within the first time period meet preset conditions, the magnetometer and gyroscope are activated in the background. The power consumption of the accelerometer is less than that of the gyroscope and magnetometer. Therefore, by first collecting multiple gravity vectors within the first time period using the accelerometer and then activating the magnetometer and gyroscope in the background when it is determined that the multiple gravity vectors within the first time period meet preset conditions, the power consumption required for magnetometer calibration is further reduced. When the terminal collects multiple geomagnetic vectors within a second time period using the magnetometer, it also collects multiple rotation matrices within the second time period using the gyroscope. Based on the multiple geomagnetic vectors and rotation matrices within the second time period, the hard magnetic bias is determined. This also reduces the impact of magnetic field changes during the terminal's movement on the magnetometer calibration, thereby further improving the anti-interference capability of the magnetometer calibration function and improving the accuracy of the magnetometer.

[0172] Please refer to Figure 7 This is a flowchart illustrating another method for calibrating a magnetometer provided in an embodiment of this application. This method can be derived from the aforementioned... Figure 4- Figure 6 The method shown is combined to obtain the result. It should be noted that this method does not rely on... Figure 7 The specific order described below is a limitation. It should be understood that in some embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0173] S701, the terminal identifies its current posture or state.

[0174] S702, the terminal determines whether its posture or state has changed. If so, it executes S703 or S704; otherwise, it returns to S701.

[0175] In some implementations, the terminal executes S701 at the moment when the acquisition of the first data in the aforementioned executions of S401, S501, or S601 ends, or at another moment after completion (e.g., at the end of the first duration or after the end of the first duration). The terminal then executes S702 to determine that the terminal's posture or state has changed, which is equivalent to the terminal determining that the first data meets a preset condition by executing S402, S502, or S602. Alternatively, it can be understood that the terminal executes S701-S702 between the aforementioned S401 and S402, or executes S701-S702 between the aforementioned S501 and S502, and executes S701-S702 between the aforementioned S601 and S602.

[0176] In some implementations, the terminal executes S702 to determine whether its posture or state has changed. This can refer to whether the terminal's posture or state at the time of executing S701 has changed relative to any time before executing S701. In some implementations, the terminal collects first data for a first duration, wherein the first data includes the terminal's gravity vector at the beginning of the first duration and the terminal's gravity vector at the end of the first duration. At the end of the first duration, the terminal first executes S701 to identify the terminal's state at the end of the first duration, and then executes S702 to determine whether the terminal's posture or state at the time of executing S701 has changed relative to the terminal's state or state at the beginning of the first duration.

[0177] In some implementations, the first data includes multiple gravity vectors of the terminal within a first time period. Based on these multiple gravity vectors, the terminal can determine a first change in its gravitational acceleration within the first time period. If the first change is greater than or equal to a preset second change, it is determined that the terminal's attitude or state has changed; otherwise, it is determined that the terminal's attitude or state has not changed.

[0178] In some implementations, the first data includes multiple gravity vectors of the terminal within a first time period. The terminal can determine a first motion state within the first time period based on these multiple gravity vectors. If the first motion state is the same as a preset second motion state, it is determined that the terminal's attitude or state has changed; otherwise, it is determined that the terminal's attitude or state has not changed.

[0179] In some implementations, the first data includes multiple rotation matrices of the terminal within a first time period. The terminal can determine a third change in its attitude based on these multiple rotation matrices within the first time period. If the third change is greater than or equal to a preset fourth change, it is determined that the terminal's attitude or state has changed; otherwise, it is determined that the terminal's attitude or state has not changed.

[0180] S703, the terminal determines whether the third time interval between the current time and the last time the magnetometer was calibrated is greater than or equal to the fourth time interval. If so, proceed to S704; otherwise, return to S701.

[0181] In some implementations, S703 may be omitted.

[0182] S704, the terminal background starts the magnetometer to collect the second data.

[0183] In some implementations, the method by which the terminal executes S704 to start the magnetometer in the background to collect second data can be found in the detailed descriptions of S403, S503 or S603 above.

[0184] S705, the terminal determines the hard magnetic bias based on the second data.

[0185] In some implementations, the terminal performs S705 to determine the hard magnetic bias based on the second data, as detailed in the aforementioned S404, S504, or S604.

[0186] S706, the terminal verifies the hard magnetic bias. If the verification passes, proceed to S707; otherwise, return to S701.

[0187] The terminal performs verification using a hard magnetic bias to determine whether the hard magnetic bias is accurate.

[0188] In some implementations, the terminal may determine another hard magnetic bias at least once in the same or similar manner as determining the hard magnetic bias in S701-S706, based on the difference between the other hard magnetic bias and the hard magnetic bias determined by S706. If the difference is less than a preset error threshold, the hard magnetic bias verification is determined to have passed; otherwise, the hard magnetic bias verification is determined to have failed.

[0189] In some implementations, the terminal can perform orientation services based on the hard magnetic bias determined by S706. If the orientation service can be performed accurately, the hard magnetic bias verification is determined to have passed. If the orientation service cannot be performed accurately, the hard magnetic bias verification is determined to have failed.

[0190] In some implementations, when the terminal fails the hard magnetic bias verification, the buffer can be reset, thereby deleting at least some of the data obtained in this calibration process stored in the buffer, such as the first data, the second data, the hard magnetic bias, etc. mentioned above.

[0191] In some implementations, S706 may be omitted.

[0192] S707, terminal update hard magnetic bias.

[0193] In some implementations, the terminal can replace the previously stored hard magnetic bias from the previous calibration with the hard magnetic bias determined in the current calibration.

[0194] In some implementations, the terminal may execute at least one of the steps in S706 and S707 after S404, S504 or S604.

[0195] In the above embodiments, the terminal can determine whether to calibrate the magnetometer based on data collected by the inertial measurement unit. In other embodiments, the user can actively trigger the calibration of the magnetometer. In some embodiments, the preset operation can be pre-set by the user or relevant technical personnel. For example, if the terminal is a smartwatch, the preset operation may include the user waving their arm wearing the smartwatch up and down; or, if the smartwatch includes a button, the preset operation may include double-clicking the button; or, if the smartwatch displays an interface to the user including a user interface control for triggering the calibration of the magnetometer, the preset operation may include the user clicking the user interface control.

[0196] In some implementations, when the terminal detects a preset operation by the user to trigger the calibration of the magnetometer, it activates the magnetometer in the background, acquires fourth data using the magnetometer, and calibrates the magnetometer based on the fourth data. In some implementations, while acquiring the fourth data, the terminal also acquires fifth data through an inertial measurement unit, and calibrates the magnetometer based on both the fourth and fifth data. In some implementations, the terminal can determine the hard magnetic bias based on the fourth (and fifth) data.

[0197] In some implementations, the fourth data may be the same as or similar to the second data described above, and the fifth data may be the same as or similar to the third data described above.

[0198] In some implementations, the fourth data may include multiple geomagnetic vectors of the terminal within a sixth time period. In some implementations, each of the multiple geomagnetic vectors corresponds to a specific time point. For example, the fourth data may include a third geomagnetic vector corresponding to a third time point and a fourth geomagnetic vector corresponding to a fourth time point, both of which fall within the sixth time period.

[0199] In some implementations, the fifth data includes multiple gravity vectors of the terminal within a sixth time period. In other implementations, the same moment within the sixth time period corresponds to a weight vector and a geomagnetic vector. For example, the fifth data includes a third gravity vector corresponding to a third moment and a fourth gravity vector corresponding to a fourth moment.

[0200] In some implementations, the fifth data includes multiple rotation matrices of the terminal within a sixth time period. In some implementations, a rotation matrix and a geomagnetic vector correspond to the same moment within the sixth time period. For example, the fifth data includes a third rotation matrix corresponding to the third moment and a fourth rotation matrix corresponding to the fourth moment.

[0201] In some implementations, the fifth data includes multiple gravity vectors of the terminal within a sixth time period and multiple rotation matrices of the terminal within a sixth time period. In some implementations, a rotation matrix, a geomagnetic vector, and a gravity vector correspond to the same moment within the sixth time period.

[0202] In the above embodiments, the method of calibrating the magnetometer by the terminal has been explained in detail. Next, the interface changes of the terminal during the calibration process of the magnetometer will be explained in detail, taking the orientation service as a compass as an example, in conjunction with the above method of calibrating the magnetometer.

[0203] Please refer to Figure 8 This is a schematic diagram of a display interface provided in an embodiment of this application. Figure 8 The dotted line portion can be omitted. After the terminal starts the orientation service, it can perform automatic calibration without user intervention, and manual calibration with user intervention.

[0204] In state one, the terminal displays the third interface 710, which includes a directional service (e.g., a compass) control. Users can trigger the directional service to start by clicking the directional service control.

[0205] When the terminal receives a user's click operation based on the compass control, it will jump to state two if the magnetometer calibration has been completed.

[0206] When the terminal receives a user's click operation based on the orientation service control, it will jump to state three if the magnetometer calibration has not been completed.

[0207] In some implementations, since the magnetometer can be automatically triggered and calibrated in the background in this application, the time the magnetometer is in an accurate state can be greater than the time the magnetometer is in an inaccurate state. Therefore, when the terminal jumps from the third interface 710 multiple times, the frequency of jumping to state two is significantly greater than the frequency of jumping to state three.

[0208] State 2: The terminal displays the second interface 720, which includes directional information such as an arrow indicating the due north direction of the geomagnetic field and the angle at which the terminal deviates from the due north direction of the geomagnetic field.

[0209] State 3: The terminal displays a first interface 730, which includes a first indication message indicating that the calibration of the magnetometer has not yet been completed. For example, the first indication message is "Magnetic field interference nearby, click to calibrate".

[0210] In some implementations, the first interface 730 may include another orientation information, which may be information displayed before the orientation service was last closed, or information displayed by the terminal based on the previous calibration result of the magnetometer.

[0211] In some implementations, if the terminal does not receive a user's click operation on the first instruction information within a fifth time period starting from the display of the first interface 730, the magnetometer is turned on in the background and automatically calibrated through the aforementioned S403-S404, S503-S504, S603-S604 or S705-S707. After the automatic calibration is completed, the process jumps to state two.

[0212] In this embodiment, if the magnetometer calibration is not completed when the location service is enabled, the terminal can first display a first interface and then automatically calibrate the magnetometer using the calibration method provided in this application. Upon completion of calibration, a second interface including location information is displayed. This enables the magnetometer to be automatically calibrated without user intervention when the user enables the location service but has not completed the calibration. This reduces the difficulty of calibrating the magnetometer and improves the user experience when using the location service.

[0213] In some implementations, if the terminal receives a user's click operation on the first instruction information within a fifth time period starting from the display of the first interface 730, it will jump to state four.

[0214] State 4: The terminal displays a fourth interface 740, which includes second instruction information to guide the user to perform manual calibration. For example, the second instruction information is "Please tilt the watch significantly to complete the calibration circle and move it away from interference sources." Based on this second instruction information, the user can manually operate the terminal to calibrate the magnetometer.

[0215] In some implementations, while the user rotates the terminal based on the second instruction information, the terminal can acquire sixth data via a magnetometer and calibrate the magnetometer based on the sixth data. In some implementations, while the user rotates the terminal based on the second instruction information, the terminal acquires seventh data via an inertial measurement unit while acquiring the sixth data via the magnetometer, and calibrates the magnetometer based on the sixth and seventh data. In some implementations, the terminal can determine the geomagnetic vector based on the sixth (and seventh) data.

[0216] In some implementations, the sixth data may include multiple geomagnetic vectors of the terminal within a seventh time period. In some implementations, each of the multiple geomagnetic vectors corresponds to a specific time point. For example, the sixth data may include a fifth geomagnetic vector corresponding to a fifth time point and a sixth geomagnetic vector corresponding to a sixth time point, both of which fall within the seventh time period.

[0217] In some implementations, the seventh data includes multiple gravity vectors of the terminal within a seventh time period. In other implementations, a weight vector and a geomagnetic vector correspond to the same moment. For example, the seventh data includes a fifth gravity vector corresponding to the fifth moment and a sixth gravity vector corresponding to the sixth moment.

[0218] In some implementations, the seventh data includes multiple rotation matrices of the terminal within a seventh time period. In other implementations, a rotation matrix and a geomagnetic vector correspond to the same time point. For example, the seventh data includes a fifth rotation matrix corresponding to the fifth time point and a sixth rotation matrix corresponding to the sixth time point.

[0219] In some implementations, the sixth data includes multiple gravity vectors of the terminal within a seventh time period and multiple rotation matrices of the terminal within a seventh time period. In some implementations, a rotation matrix, a geomagnetic vector, and a gravity vector correspond to the same moment within the seventh time period.

[0220] In some implementations, the durations of the second, sixth, and seventh durations can be the same.

[0221] When manual calibration is successful, the terminal jumps to state two.

[0222] When manual calibration fails, the terminal jumps to state five. Alternatively, in some implementations, the terminal can perform manual calibration multiple times, and jumps to state five when the number of manual calibration failures exceeds a preset number (e.g., three).

[0223] State 5: The terminal displays a fifth interface 750, which includes a third indication message indicating calibration failure. For example, the third indication message might be "If there are magnets around the watch, it may affect the accuracy of the compass sensor," indicating the reason for the calibration failure.

[0224] In some implementations, when the terminal receives a user's click operation based on the third instruction information or the user interface control corresponding to the third instruction information (such as the "OK" control below the fifth interface 750), it returns to state two.

[0225] Please refer to Figure 9 This is a schematic diagram of another display interface provided in an embodiment of this application. Figure 9 The dotted line portion can be omitted. Figure 9 The interface changes of the terminal shown during the magnetometer calibration process are related to... Figure 8 The difference between the interface changes shown in the terminal during the magnetometer calibration process lies in the transition from state three to state two or four. Specifically, after the terminal starts the orientation service, it first performs automatic calibration regardless of user intervention; manual calibration is only performed if automatic calibration fails.

[0226] State 3: The terminal displays a first interface 730, which includes a first indication message indicating that the calibration of the magnetometer has not yet been completed. For example, the first indication message is "Magnetic field interference nearby, click to calibrate".

[0227] If the terminal does not receive a user click on the first instruction information within the fifth time period starting from the display of the first interface 730, the magnetometer will be started in the background and automatically calibrated upon reaching the fifth time period. After the automatic calibration is completed, the terminal will proceed to state two. Alternatively, if the terminal receives a user click on the first instruction information within the fifth time period starting from the display of the first interface 730, the magnetometer will be started in the background and automatically calibrated upon receiving the click. After the automatic calibration is completed, the terminal will proceed to state two.

[0228] In other words, when the terminal displays the first interface 730, it will automatically perform calibration regardless of whether the user actively clicks on calibration.

[0229] When the terminal fails to calibrate automatically, it may be due to strong magnetic field interference around the terminal. You can switch to state four to enter manual calibration mode, or you can switch directly to state five to indicate calibration failure.

[0230] Please refer to Figure 10 This is a schematic diagram of another display interface provided in an embodiment of this application. Figure 10 The dotted line portion can be omitted. Figure 10 The interface changes of the terminal shown during the magnetometer calibration process are related to... Figure 8 and Figure 9 The differences in the interface changes during the magnetometer calibration process on the terminal shown are in the transitions between states one and two, and between states three, as well as the transition from state three to state two. Specifically, when the orientation service is enabled, the terminal performs automatic calibration if the magnetic field interference is low; otherwise, it prompts the user to move away from the interference and perform manual calibration if the magnetic field interference is high.

[0231] In state one, the terminal displays the third interface 710, which includes a directional service (e.g., a compass) control. Users can trigger the directional service to start by clicking the directional service control.

[0232] When the orientation service is activated, the magnetometer and inertial measurement unit are also activated, so the terminal can first determine the magnitude of magnetic field interference.

[0233] If the magnetic field interference is small, the magnetometer is automatically calibrated by collecting the fourth (and fifth) data, and then jumps to state two after successful calibration.

[0234] If the magnetic field interference is significant, then proceed to state three.

[0235] State 3: The terminal displays the first interface 730, which includes first indication information for indicating that the calibration of the magnetometer has not yet been completed.

[0236] Since the terminal displays the first interface 730 after automatic calibration fails, if the terminal receives a click operation from the user on the first instruction information from the first interface 730, it will jump to state four to manually calibrate the magnetometer. If the terminal receives a click operation from the user on the first instruction information from the first interface 730, it can return to the desktop or the main screen, i.e., exit the orientation service.

[0237] In other words, the terminal does not directly transition from state three to state two.

[0238] It should be noted that the hard magnetic bias determined based on the second (and third) data, the hard magnetic bias determined based on the fourth (and fifth) data, and the hard magnetic bias determined based on the sixth (and seventh) data can be the same or different.

[0239] Based on the same inventive concept, as an implementation of the above method, this application provides a device for calibrating a magnetometer. This device embodiment corresponds to the aforementioned method embodiment. For ease of reading, this device embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the device in this embodiment can correspondingly implement all the contents of the aforementioned method embodiment.

[0240] In one possible implementation, the device may correspond to the terminal in the above method embodiments; for example, it may be a terminal or a chip configured in a terminal. The device is used to execute the various steps or processes corresponding to the terminal in the above method.

[0241] Based on the same inventive concept, this application also provides a terminal. The terminal includes a memory and a processor, wherein the memory stores a computer program; and the processor executes the method described in the above-described method embodiments when the computer program is invoked.

[0242] The terminal provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so they will not be described again here.

[0243] Based on the same inventive concept, this application also provides a chip system. The chip system includes a processor coupled to a memory, which executes a computer program stored in the memory to implement the methods described in the above-described method embodiments.

[0244] The chip system can be a single chip or a chip module composed of multiple chips.

[0245] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the methods described in the above-described method embodiments.

[0246] This application also provides a computer program product that, when run on a terminal, enables the terminal to implement the method described in the above-described method embodiments.

[0247] If the integrated units described above are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable storage medium can include at least: any entity or device capable of carrying computer program code to a terminal, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks.

[0248] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of some embodiments.

[0249] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0250] In the embodiments provided in this application, it should be understood that the disclosed apparatus / devices and methods can be implemented in other ways. For example, the apparatus / device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0251] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.

[0252] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0253] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."

[0254] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0255] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0256] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A method of calibrating a magnetometer, characterized by, Applied to a terminal, the terminal comprising an inertial measurement unit and a magnetometer, the magnetometer being in a closed state, the method comprising: collecting first data by the inertial measurement unit; in response to the first data satisfying a preset condition, starting the magnetometer in the background; collecting second data by the magnetometer; calibrating the magnetometer based on the second data.

2. The method of claim 1, wherein, The collecting first data by the inertial measurement unit comprises: collecting the first data by the inertial measurement unit when a bearing service is not started, the bearing service being a service performed based on a bearing of the terminal in a geographic magnetic field.

3. The method of claim 2, wherein, The bearing service comprises a map, navigation or compass.

4. The method according to any of claims 1 to 3, characterized in that, After the calibrating the magnetometer based on the second data, the method further comprises: closing the magnetometer.

5. The method according to any of claims 1 to 4, characterized in that, The first data comprises a plurality of gravity vectors of the terminal within a first time length, and before the starting the magnetometer in the background in response to the first data satisfying a preset condition, the method further comprises: determining a first variation of gravitational acceleration of the terminal within the first time length based on the plurality of gravity vectors of the terminal within the first time length; The starting the magnetometer in the background in response to the first data satisfying a preset condition comprises: in response to the first variation being greater than or equal to a preset second variation, starting the magnetometer in the background.

6. The method according to any one of claims 1 to 4, characterized in that, The first data comprises a plurality of gravity vectors of the terminal within a first time length, and before the starting the magnetometer in the background in response to the first data satisfying a preset condition, the method further comprises: determining a first motion state of the terminal within the first time length based on the plurality of gravity vectors of the terminal within the first time length; The starting the magnetometer in the background in response to the first data satisfying a preset condition comprises: in response to the first motion state being the same as a preset second motion state, starting the magnetometer in the background.

7. The method according to any one of claims 1 to 4, characterized in that, The first data comprises a plurality of rotation matrices of the terminal within a first time length, and before the starting the magnetometer in the background in response to the first data satisfying a preset condition, the method further comprises: determining a third variation of an attitude of the terminal based on the plurality of rotation matrices of the terminal within the first time length; The starting the magnetometer in the background in response to the first data satisfying a preset condition comprises: in response to the third variation being greater than or equal to a preset fourth variation, starting the magnetometer in the background.

8. The method according to any one of claims 1 to 7, characterized in that, The second data comprises a plurality of geomagnetic vectors of the terminal within a second time length, and the calibrating the magnetometer based on the second data comprises: determining a hard magnetic bias based on the plurality of geomagnetic vectors of the terminal within the second time length, the hard magnetic bias being used for calibrating the magnetometer.

9. The method according to any one of claims 1 to 7, characterized in that, The second data comprises a plurality of geomagnetic vectors of the terminal within a second time length, and the method further comprises: when collecting the plurality of geomagnetic vectors of the terminal within the second time length by the magnetometer, also collecting a plurality of gravity vectors of the terminal within the second time length by the inertial measurement unit; The calibration of the magnetometer based on the second data comprises: determining a hard magnetic bias based on the plurality of geomagnetic vectors of the terminal within the second time length and the plurality of gravity vectors of the terminal within the second time length, the hard magnetic bias being used for the calibration of the magnetometer.

10. The method according to any one of claims 1 to 7, characterized in that, The second data comprises a plurality of geomagnetic vectors of the terminal within a second time length, and the method further comprises: when the plurality of geomagnetic vectors of the terminal within the second time length are collected by the magnetometer, the plurality of rotation matrices of the terminal within the second time length are also collected by the inertial measurement unit; The calibration of the magnetometer based on the second data comprises: determining a hard magnetic bias based on the plurality of geomagnetic vectors of the terminal within the second time length and the plurality of rotation matrices of the terminal within the second time length, the hard magnetic bias being used for the calibration of the magnetometer.

11. The method according to any one of claims 1 to 7, characterized in that, The second data comprises a plurality of geomagnetic vectors of the terminal within a second time length, and the method further comprises: when the plurality of geomagnetic vectors of the terminal within the second time length are collected by the magnetometer, the plurality of gravity vectors of the terminal within the second time length and the plurality of rotation matrices of the terminal within the second time length are also collected by the inertial measurement unit; The calibration of the magnetometer based on the second data comprises: determining a hard magnetic bias based on the plurality of geomagnetic vectors of the terminal within the second time length, the plurality of gravity vectors of the terminal within the second time length and the plurality of rotation matrices of the terminal within the second time length, the hard magnetic bias being used for the calibration of the magnetometer.

12. The method of any one of claims 1-11, wherein, Before the calibration of the magnetometer based on the second data, the method further comprises: in response to the orientation service being turned on, if the calibration of the magnetometer is not completed, a first interface is displayed, the first interface comprising first indication information for indicating that the calibration of the magnetometer is not completed at present, the orientation service being a service executed based on the orientation of the terminal in a geographical magnetic field; after the calibration of the magnetometer based on the second data, the method further comprises: a second interface is displayed, the second interface comprising orientation information.

13. The method of any one of claims 1-12, wherein, The starting of the magnetometer in the background in response to the first data satisfying the preset condition comprises: in response to the first data satisfying the preset condition and a third time length between a current time and a time when the magnetometer is calibrated last time being greater than or equal to a preset fourth time length, the magnetometer is started in the background.

14. A terminal, characterized by comprise: a memory and a processor, the memory being used for storing a computer program; the processor being used for executing the method as claimed in any one of claims 1-13 when the computer program is invoked.

15. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the method as claimed in any one of claims 1-13.

16. A computer program product, characterised in that, When the computer program product runs on the terminal, the terminal is caused to execute the method as claimed in any one of claims 1-13.