Active Compensation Method for Strong Magnetic Interference of MEMS Electronic Compass

In practical applications, an electronic compass composed of a three-axis magnetometer and a three-axis accelerometer is often due to the strong magnetic field interference of the carrier, which makes the magnetometer unable to accurately calculate the heading, and even causes the electronic compass to fail. This problem puts forward more stringent requirements on the installation and use of the electronic compass on the carrier. Generally, traditional magnetic field compensation methods such as ellipse/ellipsoid fitting method can effectively compensate electronic compasses. However, these methods cannot be used when the output of the magnetometer is saturated. In order to overcome the above influence, this paper proposes a three-axis external coil active compensation method. By analyzing the error characteristics of the magnetometer, a coil compensation model was established, and a neural network-based control algorithm was designed to realize the adaptive compensation of current. The use of genetic algorithm can improve the global search ability, while controlling the convergence of the BP neural network, which has better real-time performance and higher reliability. The simulation experiment results show that the method has better optimization ability and higher compensation accuracy, the strong magnetic interference of the carrier is effectively compensated, and the working environment adaptability of the MEMS electronic compass is significantly improved.


I. INTRODUCTION
Geomagnetic navigation technology is widely used in the fields of survey and search and rescue, mineral exploration, vehicle detection, unmanned equipment orientation, and integrated navigation. The high-precision MEMS electronic compass is one of the main components of geomagnetic navigation technology application [1], which uses a threeaxis magnetometer to measure the geomagnetic component to calculate the heading angle. Among the many magnetic field measurement techniques, the narrow linewidth magnetic resonance spectroscopy technique using outer electrons can make the sensitivity of the atomic magnetometer reach the level of the superconducting magnetometer [2]. Although many current magnetic sensors have high sensitivity, their spatial resolution is low due to their small size [3]. The article [4] proposed a full cesium (Cs) atomic magnetometer based on Bell-Bloom structure and polarization ellipse long axis detection. At the same time, the spatial resolution and The associate editor coordinating the review of this manuscript and approving it for publication was Kathiravan Srinivasan . response time of the magnetometer with changes in the magnetic field were also analyzed.
In practical applications, due to the structural error of the sensor and the interference magnetic field of the carrier, there is a large error between the measured value of the magnetometer and the true value. When the magnetic interference is severe, it even exceeds the range of the magnetic measurement range, which causes the electronic compass to be inaccurate. Therefore, it is very necessary to compensate the strong magnetic interference of the MEMS electronic compass. Magnetic field compensation is mainly divided into two methods: hardware compensation and software compensation. Hardware compensation is to generate a compensating magnetic field by adding electromagnetic coils and hardware circuits to offset the interference magnetic field; software compensation is to use computer modeling and various compensation algorithms to eliminate magnetic field interference.
Foreign research on the problem of magnetic interference compensation is relatively early, which originated in the aviation field. In aerial surveys, the magnetometer is usually installed in a pod or close to the wing tip. In 2005, the German Institute of High-Tech Physics used a helicopter to fly for 150 hours in order to test the aviation full tensor superconducting magnetic gradient system [5]. In terms of compensation algorithm, in 1944, American scholars W. E. Tolles and Q. B. Lawson and others reported the problem of interference magnetic field related to aircraft maneuvering, and they established a mathematical model-T-L equation [6]. Gebre Egziabher D et al. proposed the Two-Step algorithm, this algorithm does not require initial value estimation. First, the measurement equation is changed to a linear equation, the intermediate variable value is estimated by the least square method, and the model is solved according to this value [7]. In terms of compensation hardware, Canada's RMS company developed the DAARC500 system in 2006, which can provide accurate magnetic field information with strong stability. In terms of compensation software, the Canadian Scott Hogg & Associates Geophysical Software Company has developed a set of aeronautical magnetic measurement compensation software CMAG4, which can realize multichannel magnetic field data synchronization processing, and has been successfully applied to different types of fixed-wing aircraft [8].
Domestic research on magnetic field compensation began in the 1960s. In 1965, Zhuo S N used Poisson's equation to resolve the mathematical expression of aircraft interference magnetic field. In 1977, a certain department successfully developed the DBQ-1 electronic compensator, which realized the steady-state compensation of the magnetic field [9]. In 1999, Zhu Yun and others at Northwestern Polytechnical University used the adaptive least square method to correct the steering error of the magnetometer [10]. Regarding the carrier interference magnetic field, researchers mainly start with electromagnetic compensation and try to eliminate the magnetic interference inside the carrier. Li Ji of the National University of Defense Technology and others applied the finite element analysis method to the magnetic field characteristics of the carrier and analyzed the influence of the magnetic field of the carrier [11]. In 2016, Cheng D F and others of Jilin University proposed a compensation coefficient solution method based on the correction of the EIV model based on the principle of total field compensation in aeromagnetic surveys, aiming at the problem of complex collinearity when the least squares method is used to estimate the compensation coefficient [12].
At present, researchers often solve the magnetic field compensation coefficients by parameter fitting [13], [14], commonly used methods such as ellipse/ellipsoid compensation. Although this method can obtain higher compensation accuracy, it fails when the interfering magnetic field exceeds the magnetic measurement range. In order to solve the strong magnetic interference problem of MEMS electronic compass, this paper proposes a hardware compensation method of three-axis external compensation coil. By setting three sets of compensation coils in the three directions of X, Y, and Z, the strong magnetic components in the three directions of the MEMS electronic compass are compensated respectively. Finally, different MEMS electronic compasses should meet the requirements of normal use in the compensated magnetic field environment. With 3 sets of coil sets, it can generate compensation magnetic fields in three directions: longitudinal X, transverse Y, and vertical Z, so that magnetic field compensation can be realized quickly and flexibly.
Electromagnetic coils are widely used in the engineering field. The article [15] proposes a method to achieve rapid and high-quality demagnetization of ships using toroidal coils. The article [16] controls the Helmholtz coil with a high-precision current source to offset low-frequency interference magnetic fields. The coil is the generating part of the magnetic field. During the design process, it should not only meet the requirements of magnetic induction intensity, but also have an appropriate size to save production costs. Therefore, it is necessary to determine the position and radius of the coil group. The article [17] analyzed the uniformity of the magnetic field of the coil, and derived the relationship between the uniformity of the magnetic field and the size of the coil structure. The article [18] optimized the coil through finite element analysis and related optimization algorithms. Although the electromagnetic coil compensation method is simple to operate, it is difficult to solve the problem of magnetic field compensation in a dynamic environment, and the real-time performance is poor.
Due to its good robustness and nonlinear mapping capabilities, BP (Back Propagation, BP) neural network is suitable for establishing fault detection and error compensation models [19]. In order to solve the strong magnetic interference problem of MEMS electronic compass, this paper proposes a hardware compensation method of three-axis external compensation coil. Aiming at the shortcomings of poor real-time performance of hardware compensation, the BP neural network is used as the compensation current control algorithm to establish the non-linear network mapping relationship between the reference attitude angle, the uncompensated attitude angle and the compensation current. However, in the actual application process, the construction of neural networks often depends on the user's empirical formula, and no strict theory has been formed. Therefore, it takes a lot of time to select the appropriate parameters to build the network model [20], and it is easy to fall into the local optimum. In order to solve this problem, this paper combines genetic algorithm (Genetic Algorithm, GA) to improve the performance of BP neural network, so that the neural network has excellent local search and global search capabilities at the same time, thereby improving the compensation efficiency.
The remaining part of the paper is as follows: The second part analyzes the error and proposes a compensation scheme, and simulates and analyzes the magnetic field characteristics of different types of compensation coils. In the third part, the design ideas of the compensation algorithm are emphatically introduced. The fourth part compares and verifies the performance of the compensation algorithm through simulation experiments. Finally, we analyzed and discussed the results.

II. ANALYSIS AND MODELING
In order to better describe the compensation modeling method, first, we simply analyze the source of error suffered by the magnetometer. The MEMS electronic compass measures the geomagnetic component through a three-axis magnetometer to achieve heading calculation. In an ideal state, the electronic compass is rotated in any posture in space, and the magnetic field data output by the magnetometer is constrained on the surface of the sphere; in practical applications, the magnetometer has more interference and the output magnetic field data is constrained on the surface of the ellipsoid, as shown in figure 1. The main error of the magnetometer is shown in figure 2.
As shown in figure 2, the carrier magnetic field interference is the main magnetic field error interference. The carrier magnetic field error is the error caused by various magnetic materials and currents around the magnetic sensor mounted on the carrier. The installation error is caused by the non-parallelism of the three measuring axes of the magnetic sensor and the three coordinate axes of the carrier coordinate system. Among the manufacturing errors, the three-axis nonorthogonal error is caused by the inability to ensure that the three measuring axes are orthogonal to each other during the manufacturing process. The scale factor error is the measurement error caused by the inconsistency of the sensitivity of the magnetic sensors of the three measurement axes and the characteristics of the amplifying circuit of the measurement signal. For carrier navigation, the carrier magnetic field will greatly reduce the measurement accuracy of the MEMS electronic compass, which is the main research goal of this article.

A. COMPREHENSIVE COMPENSATION MODEL
During the manufacturing process of the carrier, the ferromagnetic material is magnetized by the earth's magnetic field due to electric welding and other reasons, which causes interference. Hard iron interference is mainly produced by the remanence of ferromagnetic materials on the navigation carrier. For example, on the near surface of the steel carrier, the hard iron interference magnetic field is about 10 4 nT. Even after degaussing, the fixed magnetic field is still 10 3 nT [11]. Once the hard magnetic material is magnetized, even if the magnetic field is removed, the residual magnetism will not disappear. Therefore, the hard iron interference of the carrier is relatively stable, which can be regarded as a uniform magnetic field, and the compensation is relatively simple.
There are often multiple hard-iron interference sources in the same carrier. Although the magnetic induction intensity and magnetic field direction of the hard-iron interference generated by these interference sources are different, compared with the carrier, the MEMS electronic compass is small in size. Therefore, the composite magnetic field generated by the interference of multiple hard irons at the magnetic sensor can be regarded as uniform. At the same time, because the hard magnetic material is firmly connected to the carrier, when the attitude of the carrier changes, the component of the composite magnetic field in the three axes of the carrier coordinate system is also fixed, which is equivalent to adding to the output of the three-axis magnetometer. The component is written as a matrix relation as follows: In formula (1), B t represents the ideal output value of the three-axis magnetometer, B m represents the actual measured value, and H represents the hard iron interference magnetic field. Under the action of environmental magnetic fields such as the geomagnetic field, the soft magnetic material inside the carrier is magnetized. Soft iron interference is the induced magnetic field generated by the interaction between the environmental magnetic field and the soft magnetic material. Unlike hard iron interference, the soft iron interference will disappear when there is no external magnetic field interference. Studies have shown that under the action of an external magnetic field in a certain direction, the induced magnetic field generated in that direction is the strongest, while the magnetic fields in the other two directions are weaker [21]. Soft iron interference is not only related to the characteristics of soft magnetic materials, but also It is related to the size and direction of the environmental magnetic field. Therefore, the influence of soft iron interference on the MEMS electronic compass is complicated, and compensation is more difficult. In the carrier coordinate system, the induced magnetic field will change as the carrier's attitude changes.
If it is assumed that the soft iron interference is linearly related to the geomagnetic field measured by the rotated magnetometer, and the interference magnetic field coefficient matrix is a 3rd order square matrix called A soft , it can be written as the following matrix form: Based on the above nonlinear error analysis, combined with the linear errors such as manufacturing error and installation error in the article [22], the integrated magnetometer error formula is expressed as follows: In formula (3), k represents the scale factor matrix of the magnetometer, A Nonorth represents the non-orthogonal error, and b represents the zero-bias error vector of the magnetometer. The analysis shows that the zero-bias error and the hard iron interference error can be regarded as a fixed value added to the original output of the magnetometer, and the remaining errors are all proportional to the output of the magnetometer. To facilitate the discussion, we further integrate the formula (3), and divide the magnetometer interference error into two categories: hard iron interference error U and soft iron interference error A. Written in the following matrix form: At this time, the error model of the magnetometer is expressed as follows: Therefore, the magnetometer error compensation satisfies the following relationship: By formula (6) and formula (7), the interference magnetic field B e can be expressed as: where E represents an identity matrix with the same order as matrix A.
Carry out simulation analysis on carrier magnetic field characteristics. The essence of the electromagnetic field analysis of a moving carrier under a changing background magnetic field is to solve Maxwell's equations [23]. The external magnetic field can be regarded as the superposition of sinusoidal electromagnetic fields of different frequencies, taking into account the influence of carrier speed. Use the model data in the article [24] to complete the modeling in COMSOL. In order to be comprehensive, conductors, soft magnets and permanent magnets are added inside the carrier and an air bag is added during the modeling. The metal object in the carrier will generate a secondary magnetic field, which will change the uniform distribution of the magnetic field. In the magnetic field-movement model, the distribution of the internal magnetic field over time is analyzed by changing the moving speed of the carrier, as shown in figure 3.
It should be noted here that the simulation experiment is only a qualitative analysis. The real actual situation needs to consider the actual situation inside the real different carriers, and define it according to the specific structure of the carrier and the actual size and materials of the various components inside the carrier. The selected magnetic field frequency and carrier speed are all hypothetical indications. In the actual process, the carrier movement speed is greater, and the movement form will be more complicated. At the same time, the terrestrial magnetic field is not a standard sinusoidal change. The sine magnetic field of different frequencies is superimposed to simulate the terrestrial magnetic field, and different movement speeds are selected to better reflect the influence of speed changes on the internal magnetic field of the carrier. As shown in figure 3, the magnetic induction intensity distribution inside the carrier is constantly changing with the change of the movement speed, and the magnetic induction intensity value of the fixed point inside the carrier is also constantly changing. As the speed of the carrier increases, at a certain moment, the magnetic induction intensity will produce a larger peak, and the trend of change will be more intense.

B. HELMHOLTZ COIL MODEL
The Helmholtz coil consists of two parallel coils, as shown in Figure 4. The coil radius is R, the thickness is b, and the height is h. A Helmholtz coil induction coil is separated into two parallel identification coils and wound together, so the current flows in the same direction [25], and the direction of the magnetic field is the axis of the two coils.
According to Biot-Saffar [26] theorem and superposition principle, when the same current flows in the same direction, the magnetic induction intensity at a point on the axis is:  In formula (9), µ 0 = 4π × 10 −7 H/m, which means vacuum permeability, and R means coil radius. d represents the distance between the two coils, and z represents the distance between the point and the middle point of the two coils. When z = 0, the magnetic induction intensity at the middle point of the coil can be calculated as: We use COMSOL to perform quantitative simulation analysis on Helmholtz coils. As shown in figure 4, a Helmholtz coil model in the z-axis direction is established. In order to simply and intuitively analyze the magnetic field characteristics of the Helmholtz coil, the various parameters of the coil are initially set by the actual size of the MEMS electronic compass in the laboratory. Here we choose the coil radius R = 32mm, thickness b = 6mm, and height h = 9mm. We use the steady-state mode solver for simulation calculations. First, we analyze the magnetic induction intensity distribution in the x-axis direction, as shown in figure 5.
Along the x-axis direction, the magnetic induction intensity value is between 0.18mT and 0.62mT, the magnetic induction intensity increases obviously in the interval of −35mm to −8mm, and the magnetic induction intensity remains basically constant in the interval of −8mm to 0mm. At the same time, the magnetic induction intensity is symmetrically distributed, so the range of −8mm to 8mm can be regarded as a uniform magnetic field. Figure 6 shows the magnetic induction intensity distribution in the xy (z = 0) plane. It can be seen that the magnetic induction intensity value in the central area of the coil is the largest and the color distribution is relatively uniform. Figure 7 shows the magnetic induction intensity change in the z-axis direction from −8mm to 8mm, the magnetic induction intensity range is about 0.6186mT-0.6228mT, and the change trend is symmetrical. Although the fluctuation range of the magnetic field is small, a higher current stability is required for a weak magnetic field to achieve accurate compensation. It can be seen that the Helmholtz coil model can form a spherical uniform magnetic field area with a radius of about 8 mm in the center area.

C. SOLENOID COIL MODEL
In practical applications, a single coil cannot meet the uniformity of the magnetic field compensation, and due to the influence of the wire diameter during the coil winding process, the length and thickness of the coil cannot be ignored, so the use of a coaxial solenoid coil is more in line with actual needs. The solenoid coil compensation model is shown in figure 8.
If the length of the energized solenoid is 2L, the coil current I and the number of the coil turns N are known. According to the literature [27], [28], the magnetic induction intensity of a single-turn ring current at any point in space can be integrated to obtain the magnetic induction intensity at any point in the solenoid space. The expression when the point is on the axis is:  In Equation (11), the average radius of the solenoid is represented by r, and z represents the distance from the point to the center of the solenoid.
Taking the x-axis as an example, when two coaxial solenoids are symmetrically distributed, according to the principle of superposition, the magnetic induction intensity at any point x on the axis is (12), as shown at the bottom of the next page.
In Equation (12), as shown at the bottom of the next page, the distance between the center points of the two solenoids is represented by x, and the distance between the two solenoids is represented by d.
Assuming that the magnetic field generated by the three-axis coaxial solenoid in the ideal state can just compensate for the three-axis projection component of the interference magnetic field, we can combine equation (8) to obtain the following relationship as (13), shown at the bottom of the next page.
Therefore, the compensation current of the three sets of solenoid coils can be obtained as (14), shown at the bottom of the next page.
The length of the solenoid coil is the main factor affecting its magnetic field distribution. In order to explore the influence of solenoid coil length change on the coil magnetic field distribution, the axial and radial magnetic induction intensity changes of solenoid coils with lengths of 2L = 40mm, 2L = 60mm and 2L = 80mm were calculated using COMSOL. The solenoid radius, current, number of turns and other parameters under different lengths remain unchanged. The results are shown in figure 9 and figure 10.
The uniformity of the magnetic field generated by the solenoid coil is better than that of the toroidal coil, and the 48866 VOLUME 9, 2021 axial magnetic field and the radial magnetic field are symmetrically distributed. It can be seen from figure 9 that from the solenoid port to the center of the solenoid, the magnetic flux density keeps increasing, and the magnetic flux density near the solenoid port is about half of the magnetic flux density in the central area. The longer the length, the smaller the magnetic induction intensity at the center of the solenoid and the more uniform the distribution. It can be seen from figure 10 that the magnetic induction intensity of the solenoid increases significantly from the outer wall to the inner wall.
As the length of the solenoid increases, the change of the internal radial magnetic induction changes from saddle shape to straight line. Comparing figure 9 with figure 10, it can be seen that the radial magnetic induction intensity distribution of the solenoid is more uniform than the axial direction. Although increasing the magnetic induction intensity can improve the uniformity of the compensation magnetic field, it will also reduce the compensation magnetic field intensity and sacrifice the compensation efficiency. Therefore, the design of the solenoid length needs to be optimized in conjunction with related optimization algorithms.

III. CURRENT COMPENSATION ALGORITHM
We use the electromagnetic coil as the compensation excitation, and the variables that can directly affect the magnetic induction intensity of the compensation magnetic field in equation (13) are the average radius of the solenoid coil (r), the number of the coil turns (N ), and the coil position (x, y, z) And current (I ). If the current is used as the only control variable and the remaining parameters are determined, the current-magnetic induction corresponding relationship shown in equation (14) can be obtained. In fact, the current analytical formula in equation (14) must be established on the premise that the relevant magnetic field information is known. However, when the interfering magnetic field is too large and exceeds the magnetic measurement range, this relationship cannot satisfy the precise compensation of the magnetic field. Therefore, when accurate magnetic field information cannot be obtained, it is a challenge to establish a new current correspondence relationship, and it is also a problem to be solved in this section. We use the BP neural network algorithm as the compensation current algorithm. When the magnetometer is disturbed by the magnetic field, the reference attitude angle (pitch angle, roll angle, heading angle) and the attitude angle under strong magnetic interference are used as the input of the network, and the compensation current is used as the output, and the neural network is used for training and learning. And use genetic algorithm to optimize BP neural network. In practical applications, even if the magnetometer fails completely, we can directly input the collected reference attitude angle and the attitude angle data in the interference state into the trained network, and directly output the compensation current. In this way, the adaptive and fast adjustment of the compensation current can be realized.

A. BP NEURAL NETWORK MODEL
BP neural network has the characteristics of strong creativity and excellent parallel computing ability [29]. Its typical structure is a three-layer network model-including input layer, hidden layer and output layer. As shown in figure 11, the training of the BP neural network is divided into two stages. The first stage is the forward propagation of the input signal. The signal to be processed enters the hidden layer from the input layer, is processed and stored by the activation function in the hidden layer, and then propagates to the output layer. At this time, the sample is compared with the preset target value, and the weight of each neuron is continuously revised through the back propagation process, so that the error is continuously reduced. Finally, the optimal parameters of the network are obtained to determine the neural network structure.
Although the BP neural network has strong autonomous learning ability, the error reduction of the algorithm is carried out in the anti-gradient direction. The setting of the initial weight and the initial threshold is very important. Different initial weights and initial thresholds may lead to complete Different results. Therefore, the BP neural network mainly has the following problems: 1) The selection of different parameters may cause the neural network to train for a long time, fall into the local optimum, or even fail to converge. 2) The predictive ability of the BP neural network highly depends on the training samples. When the samples are expanded, the weights and thresholds of the initial network will change, and the learned information may also be lost.
3) The number of hidden layer neurons is not as large as possible. If the number is too large, over-fitting is prone to occur, and if the number is too small, the convergence time is prolonged.

B. DESIGN OF GA-BP NEURAL NETWORK
Genetic algorithm is an optimization method that simulates biological evolution based on Darwin's theory of evolution. Now, combine the genetic algorithm with the BP neural network for optimization, and then use the optimized BP network for training, so that the network has a better initial value, so as to speed up the convergence of the network. The strategy of optimizing BP neural network based on genetic algorithm is shown in figure 12. It can be seen from figure 12 that the parameters optimized by the genetic algorithm are the initial weights and initial thresholds of the BP neural network, so once the network structure is determined, the number of weights and thresholds is known. Each individual in the initial population contains all the weights and thresholds in the network. The individual uses the fitness function to calculate the fitness value, and the genetic algorithm finds the individual corresponding to the optimal fitness value through selection and crossover. Finally, the prediction of BP neural network is realized.
The specific network design steps are as follows: • The number of neurons in the input and output layers is selected. Due to the large number of training sample points, increasing the number of neurons in the input layer within a certain range is beneficial to optimize the training effect and avoid the convergence of the training results to the local minimum. The reference attitude angle and the attitude angle in the interference state are input to the network as a 6-dimensional vector, so the input layer selects 6 neurons. During the training process, the target output is the current value of the three-axis compensation coil, so the output layer is 3 neurons.
• In this experiment, the hidden layer is set to 1 layer. The number of neurons in the hidden layer can be determined by empirical formula (15).
In formula (15), the number of neurons in the hidden layer is represented by l, the numbers of neurons in the input layer and output layer are represented by m and n respectively, and ''β'' is a constant between 1-10. Comparing the values of equation (15) through simulation experiments, it can be found that when l = 8, the network mean square error is the smallest. Therefore, the neural network topology is selected as 6-8-3.
• The neural network uses a variable learning rate, the moment parameter α = 0.01; the training accuracy goal = 0.0001; the number of training iterations epoch = 4000; the mapping function is tansig. • The design of genetic algorithm. Since the genetic algorithm uses real number encoding, when the number of neurons in the input layer, hidden layer, and output layer of the BP neural network are m, l, and n respectively, the encoding length is: The fitness function can be determined by the true output and target value of the network. The fitness function can be defined as follows: In Equation (17), the target number is represented by M , T i represents the true output value, and X i represents the target expected value.

IV. SIMULATION
In this section, first use a three-axis rate turntable to collect reference attitude angle data and uncompensated attitude angle data under the interference of an external magnetic field. We use COMSOL simulation calculation to obtain current samples. Then the training samples were imported into the BP neural network and GA-BP neural network for training to verify the effectiveness of the neural network algorithm. At the same time, the prediction results of the BP neural network and the GA-BP neural network were compared. Finally, we analyzed and discussed the results.

A. EXPERIMENTAL PROGRAM
Taking a certain type of high-precision MEMS electronic compass as the experimental object, using a three-axis speed turntable to collect experimental data, the installation of the experimental device is shown in figure 13. After the initial alignment of the MEMS electronic compass is completed, the sampling frequency is set to 100 Hz, and the turntable is driven to start collecting attitude angle data. After completing the data collection, the simulation experiment is carried out, and the experiment environment is COMSOL and MATLAB. Complete the geometric modeling of the compensation coil in the COMSOL MULTIPHYSICS software. Taking coil radius, coil thickness and coil height as the optimization parameters, the objective function is the minimum power of the coil and the minimum number of turns, and the constraints are the effective accommodation space of the three-axis coil and the assembly size requirements. The multi-objective optimization algorithm is used to solve each parameter. This preliminarily determines the structural parameters of the solenoid coil. The parameter design of solenoid coil is shown in table 1.
The AC/DC module of the COMSOL software calculates the compensation current value of the three-cycle coil, and uses the attitude angle data and the compensation current value as the input and output training samples to be imported into the neural network for training, so as to realize the prediction of the compensation current and simulate the magnetic field compensation.

B. ANALYSIS OF SIMULATION RESULTS
As shown in figure 14, at this time, the standard heading curve of the turntable and the course curve of the MEMS electronic compass under the interference of the environmental magnetic field. It can be seen from figure 10 that although the magnetometer has not failed at this time, it can no longer be used normally. The heading calculated by the MEMS electronic compass is seriously misaligned, and the heading angle fluctuates about 50 • . It can be seen from figure  15 that under the interference of external magnetic field, the maximum heading error has reached about 240 • .
Take the relative error as the evaluation index, namely e i = ŷ i − y i /y i (i = 1, 2, . . . , N ), whereŷ i is the predicted value of the i-th sample, y i is the true value of the i-th sample, and N is the number of samples. The partial prediction result error of the BP neural network for the compensation current is shown in figure 16. According to the figure, the prediction value of the BP neural network for the compensation current is in good agreement with the real value, and the maximum error is below 0.2mA. Figure 17 shows the prediction error of the improved GA-BP neural network for the compensation current. It can be seen that the maximum prediction error of the x-axis coil current drops below 0.03mA, and the maximum error of the y-axis coil current drops below 0.07mA.  It can be seen that the prediction effect of GA-BP neural network is more significant. The next step is to simulate and compensate the interference magnetic field according to the current prediction results of the two neural networks, and the result is shown in figure  18. It can be seen from the figure that the heading angle calculated by the magnetometer after simulation compensation is similar to the reference heading angle of the turntable. The heading curves are basically consistent. It can be seen that the neural network antimagnetic interference compensation method is an effective magnetometer interference compensation method, which can significantly improve the accuracy of the magnetometer's heading calculation.
Further compare the magnetic field compensation performance of the two neural network algorithms. Figure 19 shows the comparison of the heading error after using two neural network algorithms to complete the compensation. It can be seen from figure 19 that the maximum heading error after compensation by the BP neural network algorithm is about 2 • , and the maximum heading error calculated by the GA-BP neural network algorithm is about 1 • . The accuracy of the  algorithm is measured by the root mean square error (RMS), the solution is RMS(BP) = 0.8506, RMS(GA-BP) = 0.5768, which shows that the GA-BP network has a higher solution accuracy.
It should be noted that after optimizing the initial weights and thresholds of the BP neural network through the genetic algorithm, the optimization capability of the algorithm is enhanced, and the relevant optimization results are shown in table 2. Under the same network structure, the training regression rate and test regression rate of the GA-BP neural network are improved compared with the BP neural network, the network training time is reduced by about 51%, and the convergence and stability are further improved.

V. DISCUSSION
The setting of parameters directly leads to the pros and cons of the neural network performance. The number of layers of the network and the number of neurons corresponding to each layer are very important. Generally speaking, completing the training of the best network is a time-consuming process. In the process of selecting the initial weights and thresholds of the neural network, genetic algorithm is introduced for evaluation. Due to the fast execution speed of genetic algorithm, the relevant parameters (population size, number of iterations, etc.) can be changed to complete multiple operations to avoid the neural network from falling into local optimality.
When the number of neurons in the input layer and output layer is small, even without introducing genetic algorithms, the training of the network can be completed in a short time, and better prediction results can be obtained. In order to reflect the optimization effect of genetic algorithm, this paper uses the heading angle, pitch angle and roll angle as the input of the neural network to increase the number of input neurons of the network and improve the training accuracy of the neural network. The simulation results better reflect the superiority of genetic algorithm. On the other hand, the increase in the number of neurons increases the complexity of the network and reduces the training speed of the neural network. The total number of samples in this article is within 2000, so consider using gradient descent algorithms, such as Batch Gradient Descent. If the training samples reach tens of thousands or even millions of levels, the number of neurons will be more. At this time, the Mini-batch Gradient Descent algorithm can be used. The gradient descent algorithm divides the total number of samples into several subsets, and by performing network training on each subset, the network training speed can be significantly improved.
However, the training data of the neural network in this article is collected with a laboratory three-axis speed turntable as a carrier, which is collected while rotating at a constant speed in a two-dimensional plane. In fact, in the real movement of the carrier, the interference factors are more complicated, and when the magnetometer fails completely, the output is a straight line. The interference magnetic field artificially applied in the experiment does not exceed the range of the magnetic measurement range. It is impossible to verify the compensation effect of the algorithm when the magnetometer fails completely. On the other hand, the current value obtained by the simulation experiment is calculated by the COMSOL MULTIPHYSICS software, and the Helmholtz coil is used as the generator of the interference magnetic field when modeling, and the magnetic field at a certain moment is regarded as a uniform magnetic field. Due to the heating and self-inductance effects of the coil after the coil is energized, the uniformity of the magnetic field compensation will be affected, and the compensation accuracy will be limited.
Finally, although this article has verified the effectiveness of the GA-BP neural network current compensation algorithm through simulation experiments, considering the actual application background, the next step will be to design actual test experiments to further verify. The current stability can be determined by analyzing the simulation calculation results, thereby further optimizing the coil parameters, and at the same time conducive to the design of the hardware control circuit. Therefore, forward-looking work can explore the design and optimization of hardware circuits.

VI. CONCLUSION
In this paper, in the practical application of MEMS electronic compass, due to the existence of carrier interference magnetic field, the magnetometer cannot be used normally, a threeaxis external coil magnetic field compensation method is proposed. This method uses the BP neural network algorithm based on genetic algorithm as the compensation current control algorithm to realize the self-adaptive compensation of current and overcome the shortcomings of poor real-time performance of hardware compensation methods. The article first analyzes the error characteristics of the magnetometer, constructs a coil compensation model and analyzes the magnetic field characteristics of different coils, and then specifically introduces the design ideas of the GA-BP neural network algorithm, which is verified by simulation experiments. The simulation results show that the use of BP neural network for strong magnetic interference compensation has a VOLUME 9, 2021 significant effect, and the GA-BP neural network algorithm has stronger optimization capabilities and higher resolution accuracy. Finally, we discussed the experimental results and made a preliminary plan for the next step.