A Distributed Method for Self-Calibration of Magnetoresistive Angular Position Sensor within a Servo System

Magnetoresistive angle position sensors are, beside Hall effect sensors, especially suitable for usage within servo systems due to their reliability, longevity, and resilience to unfavorable environmental conditions. The proposed distributed method for self-calibration of magnetoresistive angular position sensor uses the data collected during the highest allowed speed shaft movement for the identification of the measurement process model parameters. Data acquisition and initial data processing have been realized as a part of the control process of the servo system, whereas the identification of the model parameters is a service of an application server. The method of minimizing of the sum of algebraic distances of the sensor readings and the parametrized model is employed for the identification of parameters of linear compensation, whereas the average shaft rotation speed has been used as a high precision reference for the identification of parameters of harmonic compensation. The proposed method, in addition to a fast convergence, provides for the increase in measurement accuracy for an order of magnitude. Experimentally obtained measurement uncertainty was better than 0.5°, with the residual variance less than 0.02°, comparable to the sensor resolution.


Introduction
Precise servo systems have a wide range of applications in the automotive industry, being used for vehicle steering, the flow control of the air-fuel mixture in an internal combustion engine, and for the control of control surfaces for air routing in ventilation systems. They are expected to function reliably [1] in an extremely unfavorable operating environment, within a wide range of environment temperatures and in the presence of vibrations, dirt, and moisture. The selection of an appropriate mechanical angle sensor is critical for the accomplishment of these requirements.
A high-temperature stability and mechanical robustness [2] have contributed to the popularity of magnetoresistive (MR) angular position sensors based on the utilization of anisotropic magnetoresistive (AMR), giant magnetoresistive (GMR), or tunnel magnetoresistive (TMR) effects. For these sensors, a permanent magnet attached to the shaft creates a magnetic field, whose orientation is measured by means of MR elements. The key aspect of the application of MR sensors is the correct alignment of the magnet and the sensor, since even small deviations cause unacceptably high measurement errors. Therefore, in the presence of inevitable mechanical tolerances, the utilization of end-of-line (EOL) calibration [3][4][5] is mandatory in order to achieve a desired accuracy.
The utilization of magnetoresistive sensors is particularly demanding for the measurement of the angular position of high-pressure regulation valves. The magnet is housed in a stainless-steel capsule at a relatively long distance from the sensor and with a significant error of alignment of the rotation axis, the magnet, and the sensor. Because of that, the magnetic field intensity is low at the sensor, with particularly noticeable parasitic components; in this case, MR sensors are the transducers of choice due to an order of 50 times the insufficient computational power of the MCUs have limited implementation of complex methods of self-calibration. However, with the emergence of the fourth generation of the electrical/electronic (E/E) automotive platforms [17], with a dedicated domain control unit (DCU) based on the AUTOSAR standard [18], the available computing capacities are significantly increased. Namely, such a platform includes at least one application server (AS) for the execution of computationally demanding services, making it possible to realize a self-calibration method in a distributed form.
However, a disadvantage of (self-)calibration is that a change of compensation parameters causes a momentary change of the measured position, possibly leading to an oscillatory transient process of the servo system. This was overcome in [15] by invoking the procedure for the calculation of the parameters, and their change, only when the system is in its referent position, which is calibration invariant. However, such a method would not be applicable in a distributed scenario.
The aim of this paper was the development of a new method for a distributed selfcalibration of MR angular position sensors in servo systems, wherein the compensation of the measurement error is tuned on the basis of the identified parameters of the sensor model. The tuning is performed at the times when the shaft finishes a revolution while rotating at a maximum speed. The least squares method was used for the identification of the parameters of the model. The method was adapted to a distributed realization within a heterogeneous infrastructure of an automotive communication network. It was shown that the utilization of the proposed self-calibration method increased the accuracy of the measurement for an order of magnitude. Measurement uncertainty less than 0.5 • , comparable to the results of modern EOL calibration procedures, were experimentally confirmed.
The paper is structured as follows. The self-calibration method, including the measurement process and the procedure for the identification of the model parameters, is presented in Section 2. The procedure of distributed processing adapted to a heterogeneous infrastructure of an automotive communication network is presented in Section 3. Experimental verification of the measurement method is presented in Section 4. Finally, Section 5 contains the conclusions of this paper.

The Self-Calibration Method
The structure of a servo system with the angular position measurement system is shown in Figure 1. A permanent magnet is attached to a motor shaft; so, the magnetic field and the shaft rotate synchronously. There is an MR angular sensor mounted below the magnet, detecting the magnetic field H in the plane of the sensor. The result of the detection, after amplification and A/D conversion, is a two-dimensional input signal u that is used for further processing by the application of the inverse sensor model in order to calculate the result of the angular position measurement θ * . At the same time, the input signal u is used for the self-calibration process in which the parameters of the sensor model are identified. The sensor inverse model consists of four sequential processes. Firstly, by linear compensation, the systematic errors are eliminated and the result of the magnetic field vector H * measurement is calculated. Then, by utilization of the CORDIC (coordinate rotation digital computer) algorithm for the calculation of a vector argument, the result of the magnetic field angle θ * H measurement is obtained. In the next step, by the application of harmonic compensation, the deviation between the angular position and the magnetic field angle is corrected and the compensated measured angular position θ * C is calculated. Finally, by filtering in the position observer, the result of the measurement of the angular position θ * is obtained.
The control subsystem of the servo system consists of a cascade connection of the position regulator and the speed regulator. The speed regulator is based on the observer of the rotation speed ω * ; therefore, it does not use the result of the measurement of the angular position at high speeds, whereas the possible use of the result at low rotation speeds does not affect the application of the proposed method. At the same time, the set speed ω r is continuously changed in accordance with the control law implemented in the position regulator, depending on the difference between the set angular position θ r and the result of the measurement of the angular position θ * . When the difference becomes large enough, the position regulator enters the saturation mode, where the regulator output is constant, equal to the maximum allowed speed. Thus, the measurement of the angular position does not affect the set rotation speed, breaking the feedback loop in effect. Consequently, the rotation speed, the angular position, and the input signal u are all independent from the process of measurement of the angular position, making it possible to use them for the identification of the parameters of the sensor model without disturbing the control loop. The control subsystem of the servo system consists of a cascade connection of the position regulator and the speed regulator. The speed regulator is based on the observer of the rotation speed * ω ; therefore, it does not use the result of the measurement of the angular position at high speeds, whereas the possible use of the result at low rotation speeds does not affect the application of the proposed method. At the same time, the set speed r ω is continuously changed in accordance with the control law implemented in the position regulator, depending on the difference between the set angular position r θ and the result of the measurement of the angular position * θ . When the difference becomes large enough, the position regulator enters the saturation mode, where the regulator output is constant, equal to the maximum allowed speed. Thus, the measurement of the angular position does not affect the set rotation speed, breaking the feedback loop in effect. Consequently, the rotation speed, the angular position, and the input signal u are all independent from the process of measurement of the angular position, making it possible to use them for the identification of the parameters of the sensor model without disturbing the control loop.
The steady state in the saturation mode of the position regulator, while the shaft of the motor rotates at a constant speed, is of a special interest. Namely, it is possible to measure the average shaft speed with a high accuracy by measuring the rotation period, and the average speed can be used as an internal, high-precision reference. Thus, the selfcalibration procedure is executed in the steady state, during the saturation mode of the position regulator only, when the shaft of the motor rotates at a maximum allowed speed. The steady state in the saturation mode of the position regulator, while the shaft of the motor rotates at a constant speed, is of a special interest. Namely, it is possible to measure the average shaft speed with a high accuracy by measuring the rotation period, and the average speed can be used as an internal, high-precision reference. Thus, the self-calibration procedure is executed in the steady state, during the saturation mode of the position regulator only, when the shaft of the motor rotates at a maximum allowed speed. If the estimated or the set speed decreases for any reason, the procedure is aborted. The estimation of the model parameters is performed at the times when the shaft finishes a revolution. This procedure ensures a representativeness of the sample and the stability of the estimated model parameters.

The Process of the Magnetic Field Angle Measurement
A magnetoresistive angular position sensor, whose structure is shown in Figure 2, measures the projection of the magnetic field vector in the plane of the sensor. The sensor consists of eight MR elements, connected within two measurement bridges. The reference vectors of the four MR elements connected in the first bridge (u x ) are aligned to the x S axis of the sensor, whereas the reference vectors of the four MR elements in the second bridge (u y ) are aligned to y S -axis of the sensor.
Due to the limitations of the photolithographic process, the x S axis and y S axis of a real sensor are only approximately orthogonal. Without the loss of generality, it is assumed that the sensor's y S axis is the reference axis, whereas the sensor's x S axis differs from the ideal x-axis for an angle φ clockwise. Then, the linear model of an MR angle sensor is described as The parameter o models the residual offset of the analog interface, the inherent offset of the measurement bridges [2,3,12], and the external magnetic field [7], whereas parameters k x and k y model different sensitivities of the bridges X and Y [2,11]. Since the matrix G is a regular matrix, the transfer function of the linear compensation of the input signal u is obtained by the inversion of the linear model Equation (1) Finally, the result of the measurement of the magnetic field angle θ * H is the argument of the measured magnetic field vector Equation (2) The integer geometric constant m depends on the type of the MR sensor and the number of poles p of the employed permanent magnet, equaling 2p if it is an AMR sensor and p if it is a TMR or GMR. It should be noted that the multiplication by this constant must be performed within the argument calculation because the resulting angle should be unwrapped m times.  Due to the limitations of the photolithographic process, the S x axis and S y axis of a real sensor are only approximately orthogonal. Without the loss of generality, it is assumed that the sensor's S y axis is the reference axis, whereas the sensor's S x axis differs from the ideal x-axis for an angle φ clockwise. Then, the linear model of an MR angle sensor is described as The parameter o models the residual offset of the analog interface, the inherent offset of the measurement bridges [2,3,12], and the external magnetic field [7], whereas parameters x k and y k model different sensitivities of the bridges X and Y [2,11]. Since the matrix G is a regular matrix, the transfer function of the linear compensation of the input signal u is obtained by the inversion of the linear model Equation (1) Finally, the result of the measurement of the magnetic field angle The integer geometric constant depends on the type of the MR sensor and the m Figure 2. The structure of the measurement bridges within an MR angular sensor.

Determination of the Linear Compensation Parameters
The trace of the signal u from the model Equation (1) outlines an ellipse, which could be presented in an implicit form, using the algebraic distance function f (u; q) with parameters vector q: x u x u y u 2 y u x u y 1 · q = 0, q = a 2b c 2d 2 f g T , One can observe that the intensity of the parameters vector q does not affect Equation (4); therefore, it could be arbitrarily chosen so the expression ac − b 2 has a positive set value. By the adoption of the constant set value 0.25, suitably chosen so the resulting method has the smallest number of calculations, there arises an additional condition that changes the inequality from Equation (4): The optimal parameters vector q minimizes the sum of the squares of the algebraic distances f (u; q) for a known sequence of input signal measurements u[i], i = 1 . . . N. In order to determine its value, a modification of the direct method for the determination of an ellipse equation [19,20] could be employed. To accomplish this, an auxiliary vector x[i], defined as a function of the input signal u[i], is introduced: x u x u y u 2 y u x u y 1 T .
Let the samples' matrix D contain all the vectors x[i] for a known measurements' sequence: The sum of the squares of algebraic distances f (u; q) for a known sequence of input signal measurements u[i] can be represented in a matrix form using the measurements' matrix D: where S is the covariance matrix of vector x, of size 6 x 6, which could be expressed as: The condition Equation (5) can be presented in the vector form: where condition matrix C is a constant square block matrix of size 6 × 6, given by: The Langrage multiplier corresponding, given the condition Equation (10), to the criterion Equation (8) is, according to [21], expressed as: After equaling the derivative of the Lagrange multiplier with zero, the condition for the minimization of the criterion Equation (8) given the condition Equation (10) is obtained: The solution Equation (13) is the generalized eigenvector of the matrix pair (S, C), corresponding to a maximum generalized eigenvalue. However, since the matrix C is a singular matrix and the matrix S is an almost singular matrix, a direct solving of Equation (13) is numerically unstable. Instead, the principle presented in [19] will be used. Thus, the matrix S can be represented as a block matrix of square matrices S 1 , S 2 , and S 3 of size 3 × 3, and the parameters vector q can be represented as a block vector built of vectors q 1 and q 2 of length 3: The expression Equation (13) can now be presented in a block form: that is in the form of a system of two matrix equations: One could note that the matrix S 3 is singular only if there is a linear dependence between the coordinates of input points, not being the case here. Therefore, Equation (17) can be transformed: After substitution of Equation (18) in Equation (16), there is and after solving and extracting the auxiliary matrix M: The optimal value of the vector q 1 is obtained as the eigenvector of matrix M with the maximum eigenvalue; the value of q 2 is then obtained from Equation (18). The optimal value of vector q is finally obtained by combining the two vectors.
On the other hand, the ellipse Equation (4) can be presented in canonical form using a linear transformation of coordinates: where R(α) is the rotation matrix: After the substitution of Equation (21) in Equation (4) and solving, the parameters of a canonical ellipse form in the function of the known ellipse parameters q are obtained: Finally, after the comparison of Equation (23) and the linear model Equation (2), the parameters of the linear compensation are obtained: The precision of the parameters in Equation (24) does not depend on the precision of the rotation speed, that is, the precision of the speed regulator and the speed observer, a consequence of the usage of the implicit ellipse model in Equation (4). Therefore, for the correct identification, it is sufficient that the matrix D contains representative sample data enclosing the full angle.

The Process of Measurement of the Angular Position
The results presented in [6][7][8] show that a nonlinear measurement error, arising as a consequence of the characteristics of permanent magnets and mechanical tolerances of the system, is a slowly changing periodical function of the angular position. Therefore, a harmonic model of the angular position θ dependent on the magnetic field angle θ H is selected: where h 0 is a constant offset and h(θ H ) is a harmonic corrector given as: In the corrector Equation (26), a k and b k are the model parameters and n is the order of the harmonic corrector. This corrector is a consequence of magnet polarization and the misalignments of the axes of rotation, the magnet, the sensor, and the inclination of the sensor in reference to the magnet. The amplitudes of the harmonics decrease fast; so, a satisfactory precision of the model was accomplished with the first two harmonics already.
The measured compensated angular position θ * C is obtained by the application of the models' Equation (25) and Equation (26) to the measured magnetic field angle θ * H from Equation (3): The result of the harmonic compensation Equation (27) is filtered in the angular position observer, described in z-domain as: where θ * is the measured angular position, K is the gain of the observer error, ω * is the estimation of the current rotation speed, and T S is the sampling period. The angular position observer is necessary for the implementation of the distributed measurement calibration when there is a possibility of an asynchronous change of the system parameters. Namely, a change in parameters of either linear or harmonic calibration causes an instant change of the compensated angular position θ * C , and, without the filtering provided by the observer, the position regulation loop could be negatively affected.

Determination of the Harmonic Compensation Parameters
The parameters of the harmonic model are identified by the comparison of the reference angle with the sequence of the measured values of the magnetic field angle θ * H [i]. At the same time, when the rotation speed is constant, the reference angle is: where θ 1 is the linear component of the reference angle given as: and θ 0 is the initial value of the reference angle, which is not a priori known. Since it is adopted that the y S axis of the sensor is the reference axis, the initial value of the reference angle is determined on the basis of the passage of the measured value of the magnetic field angle θ * H [i] through zero. The error of the reference angle Equation (29) is the direct consequence of the deviation of the current speed from the average speed. As both the speed regulator and the observer are designed to suppress the error of speed in the low-frequency part of spectrum, the error of reference in the stationary state contains high-frequency components only.
After Equation (25) is applied to the reference angles Equation (29) and solved for the harmonic corrector, the following is obtained: The optimal coefficients of the harmonic corrector h 0 , a k and b k , can be determined from Equation (31) by the means of linear regression for a known sequence of measured values of the magnetic field angle θ * H [i]. Unfortunately, such a method demands operations with relatively large matrices, whose order increases with the order of the corrector Equation (26). Because of that, an approximate method is developed as well, based on the observation that the maximum amplitude of the harmonic corrector Equation (26) is relatively small, less than 1.5 • in practical applications, and could be neglected in the first approximation: Since the harmonic corrector Equation (26) is a smooth function slowly changing with the argument, the application of the approximation Equation (32) to the argument of the harmonic corrector α(i) in Equation (31) will not bring up a significant error. Therefore: The optimal coefficients of harmonic compensation are obtained by the utilization of linear regression in Equation (33) for a known sequence of measurements of magnetic field angle θ * H [i], which comes to the modified discrete Fourier transformation of difference between the reference angle Equation (29) and the measured values of magnetic field angle θ * H [i]: Unfortunately, a direct application of Equations (34)-(36) would demand knowledge of the entire sequence of the measured values of the magnetic field angle θ * H [i], mostly because it is needed to determine the value of the coefficient h 0 first but also because the starting reference angle θ 0 is initially not known. Therefore, Equation (34) is transformed in order to separate the value that could be calculated independently from the reference angle θ 0 : where F 0 is the partial sum: After the substitution of Equations (29) and (37) in Equation (33), the argument α(i) could be expressed independently from the starting reference angle: Next, after the substitution of Equation (39) in Equation (35) and rearrangement, there is: Similarly, after the substitution of Equation (39) in Equation (36) and the rearrangement, there is: The partial sums F C,k and F S,k are identified from Equations (40) and (41) next: It should be noted that the partial sums from Equations (38) and (42) can be calculated incrementally, without the knowledge of the entire sequence of the measured values of the magnetic field angle θ * H [i]. At the same time, the parameters of the model, a k and b k , can be determined solely from these sums by the substitution of Equation (42) in Equations (40) and (41): For the determination of the coefficient h 0 , it is sufficient to note that a well-tuned harmonic corrector has no influence when the measured direction of the magnetic field vector matches the reference axis. Since it is assumed that the y S axis of the sensor is the reference axis, the necessary condition is: Therefore, by solving Equation (44), the expression for the coefficient h 0 , which does not include the starting value of the reference angle anymore, is obtained: The developed tuning procedure is performed in two steps when the motor shaft rotates at the maximum constant speed. Firstly, the sums in Equations (38) and (42) are iteratively calculated for each measured value of the magnetic field angle. The coefficients of the harmonic compensation in Equations (43) and (45) are calculated only when the motor shaft finishes a revolution. The procedure is prematurely interrupted if the motor speed decreases for whatever reason or if the parameters of the linear compensation Equation (2) are changed.
The application of the low-order harmonic model is essentially significant for the suppression of the internal reference error, since only the low-frequency part of the spectrum is used for the identification. The reference error, therefore, behaves as an independent random noise; so, the error of the identified parameters is inversely proportional to the square root of the input sequence length N.

The Distributed Self-Calibration Method
The method for the self-calibration of the MR angular position sensors in servo systems is presented in the Section 2, consisting of independent determinations of the parameters of linear and harmonic compensations. Unfortunately, the implementation of the method for the determination of the compensation parameters requires an application of the floatingpoint linear algebra library, which is, in the best case, a nontrivial task, considering limited resources of an 8-bit MCU. In order to overcome this issue, without utilizing a bigger MCU, which would negatively influence the reliability and the cost of a system, the implementation of a distributed method for the determination of the compensation parameters was proposed. The time diagram of the proposed method is presented in Figure 3. The distributed calibration method is a sequence of four independent asynchronous procedures. The execution of each successive procedure in the sequence starts only when the required computing and communication resources are freed. A sequential request number provides for following the method flow through the distributed system, even in the case when the communication infrastructure contains additional nodes, and the rejection of outdated requests. Namely, since the calibration requests are independent, it is sufficient to execute each next step in response to the request with the highest sequential request number only. All the other requests can be rejected without influencing the correctness of the result. Therefore, all the communication buffers have the capacity of one message only and the reception buffers are set to accept only messages with a higher sequential calibration number.
The execution of the distributed method begins within the device, by the procedure acquire, during which the needed data are collected and the calibration request is being prepared. Once a big enough data set has been processed, the calibration request is assigned a sequential number and the procedure finishes. The procedure acquire is realized as a part of the interrupt routine of the control algorithm, during which the data are pro- The distributed calibration method is a sequence of four independent asynchronous procedures. The execution of each successive procedure in the sequence starts only when the required computing and communication resources are freed. A sequential request number provides for following the method flow through the distributed system, even in the case when the communication infrastructure contains additional nodes, and the rejection of outdated requests. Namely, since the calibration requests are independent, it is sufficient to execute each next step in response to the request with the highest sequential request number only. All the other requests can be rejected without influencing the correctness of the result. Therefore, all the communication buffers have the capacity of one message only and the reception buffers are set to accept only messages with a higher sequential calibration number.
The execution of the distributed method begins within the device, by the procedure acquire, during which the needed data are collected and the calibration request is being prepared. Once a big enough data set has been processed, the calibration request is assigned a sequential number and the procedure finishes. The procedure acquire is realized as a part of the interrupt routine of the control algorithm, during which the data are processed incrementally for each sample of the sensor signal. The limitation of the computing time needed for the increment calculation is critical for the feasibility of the realization; thus, it is desirable to exclusively use integer operations without scaling. This is of utmost importance when 8-bit MCUs are used for the realization, since shifting of multibyte registers is a computationally expensive operation. Because of that, it is necessary that the algorithms and the data structures are adapted for such a realization.
During the procedure update, the calibration request is being transferred from the device to the client. It is desirable that the transmission is performed over a reliable channel since the data collection depends on external factors and the time to the next request cannot be guaranteed. However, it is sufficient to guarantee a transmission with "at least once" semantics, since the sequential request number can be used for the rejection of a repeated request.
The procedure evaluate is entirely executed in the background process of the application server as servicing of the Remote Procedure Call (RPC) client request. The actual calibration parameters are calculated during this procedure based on the received request. In the end, the result is converted to the integer representation and the result message, the result of RPC, is formed.
Finally, the procedure tune transfers the calibration result from the client to the device. As with the request in the procedure update, it is needed to conduct the transmission over a reliable channel with "at least once" semantics as well.

The Distributed Self-Calibration of the Linear Compensation
The incremental calculation of the covariance matrix S commences by the calculation of the value of the auxiliary vector x from Equation (6), utilizing the procedure given in Table 1, where ADC_x is the result of the A/D conversion of the signal u x in the first measurement bridge of the MR sensor, ADC_y is the result of the A/D conversion of the signal u y in the second measurement bridge of the MR sensor, and ADC0 is the constant corresponding to the half range of the A/D conversion.
The integer representation of the auxiliary vector x obtained in the described way is now used for the calculation of the increment of the covariance matrix S. Since the matrix has only 15 different values, one of them being constant 1, it is sufficient to incrementally calculate values of 14 fields, as shown in Table 2.
The procedure acquire can be cancelled before its end, if the set speed becomes less than the highest allowed or if the motor speed observer points out that a significant change of the load happened. In that case, the procedure acquire can be restarted once the conditions are fulfilled but not before the predefined timeout period, needed for the transient processes to finish, elapses.

Field Data Type Increment Description
The procedure ends when the shaft finishes a revolution; knowing that the shaft rotates at a constant speed, this corresponds to a constant number of samples. Then, in the procedure update, the request for the calibration message is formed, in accordance with Table 3, by combining the unique identifying number of the device, the sequential request number, and the fields of Table 2 describing the covariance matrix S. Since the optimality criterion Equation (8) depends on the sequence of measurements of the input signal u[i] through the covariance matrix S only, the message formed in this way contains all the needed data.  Table 2 The procedure evaluate is executed as a part of the background process on the application server; so, the computational complexity is not critical. It is activated by the received request in the procedure update, but the execution is postponed until the processor time is available. The calibration parameters are calculated in this step by solving the matrix system Equation (20) and by the application of Equations (23) and (24) to the obtained result. Finally, the result is converted to integer representation, as in Table 4. In the end, the request for tuning a message is formed in the procedure tune, according to Table 5, by combining a unique identifying number of the device, sequential request number, and the fields from Table 4 describing the calibration result.  Table 4 For a practical application, it is desirable, not necessary though, to serialize the binary fields in the messages from Tables 3 and 5 in the network order, that is, in the order they are listed in Tables 2 and 4, respectively, and in MSB (most significant byte) format.

Application of the LIN Protocol
The LIN (local interconnect network) is a simple communication system and it is widely used for connecting intelligent sensors and actuators with the ECU (electronic control unit) in the automotive industry, due to its low cost and simplicity [22].
Unfortunately, the LIN transport protocol is primarily intended for the realization of the diagnostics' services and is unsuitable for a general case application. At the same time, the distinctly limited physical address space of the LIN protocol (64 addresses) leaves no possibility for the allocation of an additional pair of physical addresses necessary for the realization of an independent transport communication channel. Additionally, the master/slave transfer model cannot be directly applied to the distributed calibration method shown in Figure 3. In order to overcome this, a data concentrator, a service within the LIN master node, with the role of an agent between the device and the client, was introduced in the realization of the method. The communication between the concentrator and the device is realized by the utilization of the standard UDS (unified diagnostic services) diagnostics' protocol at the session layer, with the monitoring of sequential request number through the data structures described in Tables 3 and 5. The OSI model of the interconnection of the device and the concentrator by means of the LIN protocol is shown in Table 6. Table 6. OSI model of interconnection of the device and the concentrator by means of the LIN protocol.

Layer Protocol
Application Section 2, Figure 3 Presentation Section 3.1 Session UDS, Tables 3 and 5  Transport  ISO 17987-2  Network  ISO 17987-2  Data Link  ISO 17987-3  Physical  ISO 17987-4 The two different UDS diagnostic identifiers (DID) are employed for communication between the device and the concentrator. The transfer of the calibration request message is realized by means of the standard UDS service 0x22 (read data by identifier), with the first diagnostic identifier (DID_update), and the diagnostic data structure described in Table 3. Similarly, the transfer of the tuning request message is realized by means of the standard UDS service 0x2E (write data by identifier) but with another diagnostic identifier (DID_tune) and the diagnostic data structure described in Table 5. The time diagram of the distributed calibration method adapted to the LIN protocol is shown in Figure 4.
Regarding the distributed self-calibration method shown in Figure 3, the method adapted to the LIN protocol contains an additional procedure collect as well as the additional steps in the procedure tune. The procedure collect is executed periodically on the LIN Master node and it is responsible for the collection of the calibration requests from the LIN slave node by reading the DID_update diagnostic data. If the sequential number of the collected request increases comparing to the sequential number of the last processed request, the new request is being processed by the call of the procedure update. Regarding the distributed self-calibration method shown in Figure 3, the method adapted to the LIN protocol contains an additional procedure collect as well as the additional steps in the procedure tune. The procedure collect is executed periodically on the LIN Master node and it is responsible for the collection of the calibration requests from the LIN slave node by reading the DID_update diagnostic data. If the sequential number of the collected request increases comparing to the sequential number of the last processed request, the new request is being processed by the call of the procedure update.
During the procedure tune, the received calibration result is additionally transferred to the LIN slave node by writing DID_tune diagnostic data. Again, for the sake of the savings of the bandwidth, this step can be skipped if the sequential number of the last received calibration request in the procedure tune is less than or equal to the sequential number of the last transferred calibration result.

Application of the CAN Protocol
The CAN (controller area network) bus is a reliable network system, suited for automotive applications [23]. Its network and transport layer are described in the CAN TP standard ISO 15765 [24]. The reference OSI model of the interconnection of the device and the client by means of CAN protocol is shown in Table 7. Table 7. OSI model of interconnection of the device and the client by means of the CAN protocol.

Layer
Protocol Application Section 2, Figure 3 Presentation Section 3.1 Session Tables 3 and 5  Transport  ISO 15675-2  Network  ISO 15675-2  Data Link  ISO 11898  Physical  ISO 11898 In this application, the transport protocol utilizes two physical addresses from 29-bit address space, which identify a message. The first physical address is used when update During the procedure tune, the received calibration result is additionally transferred to the LIN slave node by writing DID_tune diagnostic data. Again, for the sake of the savings of the bandwidth, this step can be skipped if the sequential number of the last received calibration request in the procedure tune is less than or equal to the sequential number of the last transferred calibration result.

Application of the CAN Protocol
The CAN (controller area network) bus is a reliable network system, suited for automotive applications [23]. Its network and transport layer are described in the CAN TP standard ISO 15765 [24]. The reference OSI model of the interconnection of the device and the client by means of CAN protocol is shown in Table 7. Table 7. OSI model of interconnection of the device and the client by means of the CAN protocol.

Layer Protocol
Application Section 2, Figure 3 Presentation Section 3.1 Session Tables 3 and 5  Transport  ISO 15675-2  Network  ISO 15675-2  Data Link  ISO 11898  Physical  ISO 11898 In this application, the transport protocol utilizes two physical addresses from 29-bit address space, which identify a message. The first physical address is used when update message from Table 3 is transferred, whereas the second physical address is used for the transfer of tune message from Table 5.
The application of the ISO standard protocols in the second group of the OSI layers provides for the utilization of the standard communication equipment and comes down to the configuration of two standard transport channels. This is of utmost importance for usage in an automotive communication network where there are usually several physical and logical buses connected by standard network gateways.

Application of the SOME/IP Protocol
The SOME/IP (service-oriented middleware over IP) is a client-server communication protocol, developed for the realization of advanced systems in the automotive industry. The protocol describes the first group of OSI layers only; the standard TCP/IP or UDP/IP protocol stacks are usually used for the second group of OSI layers [25]. The SOME/IP protocol itself specifies a method for remote procedure calling (remote procedure call, RPC).
The reference OSI model of the interconnection of the client and the application server by means of SOME/IP protocol is shown in Table 8. Table 8. OSI model of interconnection of the client and the server by means of SOME/IP protocol.

Layer Protocol
Application Section 2, Figure  The communication between the client and the server is realized by means of a single RPC call, evaluate, whose argument is the calibration request message from Table 3; the  returned value contains the calibration result from Table 4. Since the needed communication capacity is negligible compared to the physical layer capacity, error recovery is obtained by a simple call repetition.

Experimental Results
The proposed method was realized and experimentally verified in an experimental setup, whose principal mechanical diagram is presented in Figure 5. A low-power (12 V, 250 mA) reluctance motor with an 18/149 transmission system and angular position AMR sensor (APS00B [26]) was used. The magnet (radially magnetized, 1 mm thick SmCo washer, with inner and outer diameters of 5 mm and 11 mm, respectively, and nominal magnetic induction of 200 mT) was placed at a relatively large distance (d ≈ 2 mm) from the MR sensor; so, the intensity of the magnetic field was near the lower boundary of the used sensor range, corresponding to realistic circumstances, that, is the situation when the MR sensor and the magnet are placed in hermetically separated spaces. The sensor was mounted on a PCB comprising the electronic subsystem; the PCB could be inclined for an angle α in order to misalign the magnet and the sensor.
The measurement device, which drives the motor and reads out the sensor, was purposely built for the needs of the research of the advanced methods of the signal processing within the servo systems in the automotive industry; its block diagram is shown in Figure 6. An 8-bit MCU with the integrated CAN and LIN interfaces, suitable for automotive use, was employed (ATMEGA64M1 [16]). The motor is driven through an integrated vector control torque regulator (DVR8825 [27]) controlled by the analog reference inputs, whereas the position and speed regulators are realized within the MCU program. The analog measurement interface consists of an analog multiplexer (MUX) for the selection of the measurement input and an instrumentation amplifier (IA) for the amplification of the input before A/D conversion. This way, both MR measurement bridges use the same IA, so its gain error does not affect the measured angle. In the third MUX position, when a bias voltage equal to one-half of the reference voltage is selected, the analog interface offset is measured in order to compensate for it independently from the self-calibration procedure. The system also utilizes a system basis chip (SBC, ATA6622C [28]) containing a power supply controller, a watchdog, and a communication interface for the connection with an automotive platform over the LIN interface. In order to prove the concept, the measurement device was connected to a commercial AUTOSAR-AP server running the self-calibration service. Finally, there was a CAN transceiver in the system, used for sending data to a remote computer for off-line analysis. The measurement device, which drives the motor and reads out the sensor, was purposely built for the needs of the research of the advanced methods of the signal processing within the servo systems in the automotive industry; its block diagram is shown in Figure  6. An 8-bit MCU with the integrated CAN and LIN interfaces, suitable for automotive use, was employed (ATMEGA64M1 [16]). The motor is driven through an integrated vector control torque regulator (DVR8825 [27]) controlled by the analog reference inputs, whereas the position and speed regulators are realized within the MCU program. The analog measurement interface consists of an analog multiplexer (MUX) for the selection of the measurement input and an instrumentation amplifier (IA) for the amplification of the input before A/D conversion. This way, both MR measurement bridges use the same IA, so its gain error does not affect the measured angle. In the third MUX position, when a bias voltage equal to one-half of the reference voltage is selected, the analog interface offset is measured in order to compensate for it independently from the self-calibration procedure. The system also utilizes a system basis chip (SBC, ATA6622C [28]) containing a power supply controller, a watchdog, and a communication interface for the connection with an automotive platform over the LIN interface. In order to prove the concept, the measurement device was connected to a commercial AUTOSAR-AP server running the self-calibration service. Finally, there was a CAN transceiver in the system, used for sending data to a remote computer for off-line analysis.  The measurement device, which drives the motor and reads out the sensor, was purposely built for the needs of the research of the advanced methods of the signal processing within the servo systems in the automotive industry; its block diagram is shown in Figure  6. An 8-bit MCU with the integrated CAN and LIN interfaces, suitable for automotive use, was employed (ATMEGA64M1 [16]). The motor is driven through an integrated vector control torque regulator (DVR8825 [27]) controlled by the analog reference inputs, whereas the position and speed regulators are realized within the MCU program. The analog measurement interface consists of an analog multiplexer (MUX) for the selection of the measurement input and an instrumentation amplifier (IA) for the amplification of the input before A/D conversion. This way, both MR measurement bridges use the same IA, so its gain error does not affect the measured angle. In the third MUX position, when a bias voltage equal to one-half of the reference voltage is selected, the analog interface offset is measured in order to compensate for it independently from the self-calibration procedure. The system also utilizes a system basis chip (SBC, ATA6622C [28]) containing a power supply controller, a watchdog, and a communication interface for the connection with an automotive platform over the LIN interface. In order to prove the concept, the measurement device was connected to a commercial AUTOSAR-AP server running the self-calibration service. Finally, there was a CAN transceiver in the system, used for sending data to a remote computer for off-line analysis.  It should be noted that the described mechanical construction allowed for the qualitative determination of the relative position of the sensor and the magnet only. Thus, the experiment was repeated in three basic configurations. The axes of the magnet and the sensor "almost" matched, so there was approximately no (just an offset) inclination of the sensor in the first configuration. A permanent field of magnetic interference was added in the second configuration. In the end, in the third configuration, the angle between the axes of the magnet and the sensor, that is, the sensor inclination, was chosen to be the largest possible so the magnetic field intensity in the sensor plane remained within the nominal operational range of the sensor regardless of the angular position (approximately 15 • ). The purpose-built diagnostic interface within the measurement device was used for direct collection of A/D conversion results from within an interrupt routine, thus providing for direct comparison of various methods. Figure 7 presents the speed profile of the servo system in the function of the angular movement relative to the initial position when the set point was abruptly changed. The speedup ramp was completed and the maximal rotational speed was reached when the shaft rotated 30 • from the initial position. From then on, the shaft continued the rotation with the constant rotational speed until reaching 30 • from the set target, where the slowdown ramp started. Consequently, the data for the self-calibration were available once the shaft rotated 390 • from the initial position, provided that the set-point difference was at least 420 • . possible so the magnetic field intensity in the sensor plane remained within the nominal operational range of the sensor regardless of the angular position (approximately 15°). The purpose-built diagnostic interface within the measurement device was used for direct collection of A/D conversion results from within an interrupt routine, thus providing for direct comparison of various methods. Figure 7 presents the speed profile of the servo system in the function of the angular movement relative to the initial position when the set point was abruptly changed. The speedup ramp was completed and the maximal rotational speed was reached when the shaft rotated 30° from the initial position. From then on, the shaft continued the rotation with the constant rotational speed until reaching 30° from the set target, where the slowdown ramp started. Consequently, the data for the self-calibration were available once the shaft rotated 390° from the initial position, provided that the set-point difference was at least 420°. The sensor sampling period of 10 ms represented the base sampling time for the whole system. When rotating at a maximal rotational speed, the shaft rotation period of 3.97 s was equivalent to 397 sample points. The duration of the client/server communication was 210 ms (LIN scheduler table configured duration); so, the total calibration procedure duration, including the speedup ramp, was 5.38 s.
The trace of the input signal u in the experiment with the third configuration is shown in Figure 8. Despite extremely unfavorable experiment conditions, the trace showed exceptional matching to the model. The misalignment of the axis and the permanent interference field caused the subtle translational movement of the ellipse only, whereas the remaining model parameters were practically identical in all the experiments. Such a result clearly confirmed the validity of the introduction of independent compensation of the magnetic field vector measurement. The sensor sampling period of 10 ms represented the base sampling time for the whole system. When rotating at a maximal rotational speed, the shaft rotation period of 3.97 s was equivalent to 397 sample points. The duration of the client/server communication was 210 ms (LIN scheduler table configured duration); so, the total calibration procedure duration, including the speedup ramp, was 5.38 s.
The trace of the input signal u in the experiment with the third configuration is shown in Figure 8 Figure 9 presents the deviation of the magnetic angle from the reference angle in the third configuration experiment, without the calibration (blue), after the calibration using the method from [15] (red) and after the calibration using the proposed method (black). The largest error occurred when the distance between the magnet and the sensor was the largest, when the intensity of the magnetic field was at the sensor sensitivity boundary. Without the compensation, the error boundary reached 7°, unacceptable for a majority of the applications. However, the error boundary was lowered to only 0.5° by the utilization of the proposed method.  Figure 9 presents the deviation of the magnetic angle from the reference angle in the third configuration experiment, without the calibration (blue), after the calibration using the method from [15] (red) and after the calibration using the proposed method (black). The largest error occurred when the distance between the magnet and the sensor was the largest, when the intensity of the magnetic field was at the sensor sensitivity boundary. Without the compensation, the error boundary reached 7 • , unacceptable for a majority of the applications. However, the error boundary was lowered to only 0.5 • by the utilization of the proposed method. Figure 8. The input signal trace and the identified MR sensor model. Figure 9 presents the deviation of the magnetic angle from the reference angle in the third configuration experiment, without the calibration (blue), after the calibration using the method from [15] (red) and after the calibration using the proposed method (black). The largest error occurred when the distance between the magnet and the sensor was the largest, when the intensity of the magnetic field was at the sensor sensitivity boundary. Without the compensation, the error boundary reached 7°, unacceptable for a majority of the applications. However, the error boundary was lowered to only 0.5° by the utilization of the proposed method. Figure 9. The deviation of the angle from the reference before and after the correction, with the inclined sensor.
As a comparison, when the experiment was repeated in an identical manner, except that the sensor was approximately not inclined, the result was significantly different only in the direction of the offset inclination, as shown in Figure 10. As a comparison, when the experiment was repeated in an identical manner, except that the sensor was approximately not inclined, the result was significantly different only in the direction of the offset inclination, as shown in Figure 10. Three additional calibration methods were selected for comparison, the offset compensation method based on [12], the linear compensation method based on models from [9] and [11], and the method from [15]. The methods from [10] and [13] were not considered, as they require a specific sensor, while the method from [14] requires magnetic barriers. Similarly, methods employing multilayered neural networks were not considered as the experimental apparatus lacked the mechanical long-term stability required to produce the relevant training set. Only the proposed method was suitable for real-time execution, while all the remaining methods were run off-line using the collected raw sensor data. Input data had to be additionally filtered for the offset calibration method application in order to reduce the noise sensitivity to an acceptable level. The measurement results are presented in Tables 9-11 for the first, second, and third experimental configurations, respectively. Three additional calibration methods were selected for comparison, the offset compensation method based on [12], the linear compensation method based on models from [9] and [11], and the method from [15]. The methods from [10] and [13] were not considered, as they require a specific sensor, while the method from [14] requires magnetic barriers. Similarly, methods employing multilayered neural networks were not considered as the experimental apparatus lacked the mechanical long-term stability required to produce the relevant training set. Only the proposed method was suitable for real-time execution, while all the remaining methods were run off-line using the collected raw sensor data. Input data had to be additionally filtered for the offset calibration method application in order to reduce the noise sensitivity to an acceptable level. The measurement results are presented in Tables 9-11 for the first, second, and third experimental configurations, respectively. It was noticeable that mechanical tolerances substantially influenced the measurement error variance prior to the compensation, which was significant in the case of good mechanical alignment as well. However, the application of the proposed method reduced the mean squared error for two orders of magnitude, bringing it down to the level of the sensor resolution. No significant influence of the mechanical configuration to the error variance was noted after the correction, apart for extreme cases, pointing out a good suppression of the apparatus' mechanical tolerances.
The estimated absolute of the measurement error was reduced by an order of magnitude, comparable to the modern EOL calibration procedures.

Discussion
The presented results confirm the applicability of the proposed method for the selfcalibration of the magnetoresistive angular position sensor within a servo system. Since the servo system itself behaves as a low-pass filter, the stochastic measurement errors are being additionally suppressed, and the expected boundary of the positioning error was better than the estimated boundary of the measurement error.
The comparison with the method from [15] points out that the proposed method achieves significantly better measurement accuracy, with the error being 30% to 60% lower. Partially, this improvement is due to the more complex linear self-calibration algorithm which is, because of the distributed realization on the application server, not limited by the processing power of the measurement device. Such an algorithm also enabled the application of the improved harmonic calibration algorithm. Finally, it was shown that the introduction of the speed observer significantly reduced the influence of the measurement noise and the electromagnetic interference to the measurement error, which was especially noticeable in the experiment with the uninclined sensor ( Figure 10) where the best improvement was noted at the same time.
The proposed method required only a modest input data set, collected during one full cycle of the shaft rotation at maximal speed. In comparison, the gradient descent algorithms, as in [9] and [11], require considerably more input data, typically collected during 50 to 100 full shaft rotations. It should be noted that there are typically only five cycles of shaft rotation per driving session for a general vehicle. This makes the proposed method uniquely suitable for automotive applications, where the set-point changes are relatively infrequent compared to the parameter drifts caused by extreme mechanical and temperature stresses.

Conclusions
In this paper, a method for the distributed self-calibration of a magnetoresistive angular position sensor within a servo system was presented. The accuracy of the angular position measurement by means of the MR sensors was unfavorably influenced by mechanical tolerances of the measurement system, especially the alignment deviations of the sensor axis, the magnet axis, and the rotation axis. For that reason, the system for the compensation of the measurement error was integrated within the control structure of the servo system. The system consisted of the linear compensation of the magnetic field vector measurement error, followed by the application of the harmonic compensation of angular position measurement error.
The proposed self-calibration method for the system for the determination of angular position utilized the data collected during the movement at the highest allowed speed for the identification of the measurement process model parameters. The identification was performed at the times when the shaft finished a revolution. The method of minimizing the sum of algebraic distances of the sensor readings and the parametrized model was employed for the identification of parameters of the linear compensation, whereas the average rotation speed was used as a high-accuracy reference for the identification of the harmonic compensation parameters.
The proposed distributed calibration method utilized the spare capacity of the existing communication infrastructure exclusively, with no significant influence over the speed and the delay of pre-existing services. It was accomplished by the splitting of the method into four asynchronous procedures, each step being executed only when the required resources were available. An appropriate application protocol was developed, and the possibility of an application with the existing transport protocols was pointed out. Finally, a reliable, UDS-based, and LIN-applicable transport protocol was shown, as well as a corresponding concentrator for the AUTOSAR-CP system.
The proposed method was practically realized on an embedded device, constructed in accordance with the needs of the automotive industry. Both occasional parameters' identification and the distributed realization simplified the realization, despite considerable computing complexity of the proposed method. It was shown that the application of the proposed self-calibration method increased measurement accuracy for an order of magnitude. The achieved measurement uncertainty was less than 0.5 • and is comparable to the results of the modern EOL calibration procedures. In addition, a fast convergence was achieved, lasting only 5.38 s, making it the only self-calibration procedures that could be completed during a typical driving session.
A markedly good match between the experimental results and the theoretical model opens several potential directions for further research. The results suggest that the selfcalibration of the linear compensation could be executed independently from the rotation speed, instead of when the motor shaft rotates at the highest speed. Additionally, the application of a gradient algorithm for the tuning of harmonic compensation could be considered, in order to further reduce the needed computing capacity.
The results from this paper could be extended to the self-calibration of the Hall effect angular position sensors as well, in the applications where the magnetic field intensity is not a limiting factor. Since the Hall sensors possess a better linearity than MR sensors, the linear compensation is less important compared to the MR sensors. However, considering that the primary source of nonlinear effects is not the sensor itself but the misalignment of the magnet, the harmonic compensation would be equally efficient. Therefore, it is expected that the procedure would be applicable to the Hall sensors as well.