Improving The Subdivision Accuracy of Photoelectric Encoder Using Particle Swarm Optimization Algorithm

: To improve the subdivision accuracy of a photoelectric encoder and reduce the effects of sinusoidal errors in the signals on the measurement accuracy of the system, we designed an optoelectronic chip to receive grating moiré fringe signals. An amplifier circuit with a hierarchical pipelined architecture was designed, and the photodetector array was matched with the code disk before processing the received signals. Thereafter, a quantitative analysis was performed on the sinusoidal errors in the signals. From the analysis results, a sinusoidal error compensation method based on the particle swarm optimization (PSO) algorithm was developed, and a subdivision error compensation model was established to correct the errors in the signals. Finally, a fast solution for the PSO algorithm was implemented on a field-programmable gate array, and a grating test platform was built for experimental verifications. The results showed that the peak-to-peak subdivision error of the encoder’s photoelectric signal decreased by approximately 60% from 2.98ʺ to 1.13ʺ. Therefore, the scheme proposed in this paper is expected to significantly improve the measurement accuracies of photoelectric encoders.


Introduction
Photoelectric encoders are high-precision sensors used for angle measurements; these devices allow digital angular displacement measurements with opticalmechanical-electrical integration, are widely used in engineering practice, and serve as important components in intelligent processing, satellite communication, servo, and aerospace systems, among others (Yu et al. 2020;Wang 2012;Yang 2012). In certain important applications, such as aerospace technology, the system requirements are demanding not only for encoder angle measurement accuracy and resolution but also size of the system (Ahmadi Tameh et al. 2016;Das and Chakraborty 2018). Traditional photoelectric encoders exhibit several obvious shortcomings. On the one hand, because of limitations imposed by the optical and electrical principles, the encoder requires a complex grating inscription for the code disk; moreover, the photoelectric receiving device design prevents a high degree of integration (Chen et al. 2015;Poulton et al. 2017). On the other hand, factors such as ambient temperature, device aging, and mechanical errors directly affect the quality of the moiré fringe photoelectric signal.
The angle measurement accuracy of the photoelectric encoder is mainly limited by the accuracy of the subdivision of the moiré fringe photoelectric signal, which is determined by the signal quality (Das et al. 2016;Su et al. 2015;Yang and Ting 2014;Bajic et al. 2014). Therefore, it is of great significance to develop a miniaturized, highprecision, and high-resolution photoelectric encoder.
In recent years, various research teams from around the world have studied the optical-mechanical structures of photoelectric encoders, extraction of moiré fringe photoelectric signals, electronic processing circuits, and subdivision error compensation for moiré fringe signals. The incremental photoelectric encoder developed by Heidenhain (Germany) for the Galileo Telescope in Italy achieved an angle measurement accuracy of 0.036ʺ after adjustment using multiple reading heads and correction of the system's full-circle error (Mancini et al. 2008). NASA has applied optical image recognition technology and developed a 27-bit ultrahigh-resolution Cartesian absolute optical encoder that achieved a high resolution of 0.01ʺ (Leviton et al. 2003). Based on the principles of the CMOS sensor and optical mouse, Tresanchez et al. (2010) acquired image information and developed a low-cost, high-resolution angle absolute rotary encoder. Qiao (2015) developed an absolute grating ruler using integrated circuit technology, where the image sensor and photovoltaic array were integrated in a single detector; this scheme realized the receiving position code and moiré fringe signal simultaneously with a single chip and reduced the size of the photoelectric sensing component. Heydemann first proposed a compensation scheme for moiré fringe signals based on least-squares fitting; thereafter, several researchers have continuously improved and optimized this algorithm. Warner et al. (2008) at the US National Optical Astronomy Observatory proposed the periodic error compensation and grating subdivision error correction methods. Hong and Xu (2008) from the Changchun Institute of Optics, Fine Mechanics and Physics at the Chinese Academy of Sciences proposed an error compensation method based on the radial basis function (RBF) and constructed a neural network with good learning and generalization abilities to improve the measurement accuracy of the encoder. Tan et al. (2002) employed the Lissajous figure mapping method to indirectly reduce the effects of sinusoidal deviations on the subdivision errors; however, this method cannot accurately reflect the quality of the signal in the presence of harmonic components. Kaul et al. (2008) performed discrete calibrations on the angle measurement errors and described the error curve using Fourier series expansion; they proposed a harmonic analysis method based on the Fourier transform theory and achieved error compensation for harmonics within the 10th order. The sinusoidal characteristics constitute one of the important indicators of the quality of the moiré fringe photoelectric signal that greatly affect the resolution and accuracy of an encoder. From the optical and mechanical perspectives in practical applications, it would be costly and challenging to reduce the impact of the sinusoidal deviations of signals on subdivision errors. Therefore, this study considers the electrical perspective and address the processing and compensation of photoelectric signals in the presence of sinusoidal deviations, thereby improving the subdivision accuracy of the encoder.
The electrical part of the sensor system is composed of optoelectronic devices and signal processing circuits. Presently, there are relatively few studies that have reported the integration of optoelectronic devices with signal processing circuits. With the development of integrated circuit technology, greater integration of circuits with optoelectronic devices has become the mainstream trend (Mu et al. 2019). Further, the existing error compensation schemes for grating moiré fringe photoelectric signals can only be implemented under specific conditions owing to the complexity of the algorithm and low operation speed, with most methods relying on postprocessing of the encoder signals. Thus, automatic compensation cannot be realized when there are changes in the environmental variables. In this regard, the present work is divided into two parts: (1) An optoelectronic integrated chip that can be applied to high-precision photoelectric encoders was developed; an adjustable gain amplifier was also designed to compensate for the signals in real time and eliminate the influence of the even harmonics on signals, with reduction in the size of the photoelectric sensing component.
(2) An automatic compensation method for the sinusoidal deviations of the moiré fringe photoelectric signals was proposed. A compensation model was established for the subdivision errors caused by the sinusoidal deviations, and the particle swarm optimization (PSO) algorithm was adopted to solve the waveform parameters. The automatic compensation method thus helped improve the angle measurement accuracy of the system. During the actual measurement process, sinusoidal deviations of the moiré fringe signals from the encoders could be induced by factors such as uniformity of the grating code disk, optomechanical assembly, and service environment. The principle by which the signals are read is illustrated in Fig. 2. An LED light source is used to illuminate the main grating, and the optical signal is received by the photodetector array after passing through the indicating grating. Thereafter, the signal is converted to an analog output by a fully differential amplifier (FDA) with adjustable gain such that a signal without the even harmonics and DC level drift can be obtained. The optoelectronic chip designed for the encoder in this work adopts an arrangement where a group of bright/dark codes correspond to four photodetectors. The symbol has a width of 100.9 μm, and the width of its corresponding detector is 25 μm. The detector array in Fig. 2 contains 120 optoelectronic devices, and each photodetector is of size 25×600 μm 2 . A total of 1024 incremental codes were inscribed uniformly along the circumference of the code disk such that the angular separation between two adjacent codes is 0.35°.  the photodetector and processing circuits are integrated to realize accurate processing of the acquired optical signals. Further, symmetry and stability were ensured in the chip circuit for maximal restoration of the measured optical signals (Silva-Martinez et al. 2003;Chen and Hong 2005). The detector array was arranged as noted above: four incremental photoelectric signals with phase differences of 90° were obtained and converted to analog sinusoidal signals before being output by the amplification and readout circuit. The amplifier circuit has a hierarchical pipelined structure, as shown in Fig. 3(b). In the first stage, a low-noise, high-gain transimpedance amplifier (TIA) was used to convert the nanoampere photocurrent signals into millivolt voltage signals. At the same time, to eliminate the even harmonics and increase the amplitude of the signal, two sets of signals with a phase difference of 180° were output from the chip after passing through the differential amplifier. Given possible differences in the actual light intensities, multiple trim ranges were reserved such that the amplifier gain could be varied by adjusting the resistance. The specific adjustment resistance values are listed in Table 1.  In this work, a traditional two-stage FDA structure was adopted as the main amplifier, as shown in Fig. 4. To meet the design requirements of low power consumption and low noise, a differential pair tube was selected as the input stage, and a load tube and Miller compensation capacitor were incorporated. The current bias was introduced by the gates of the mirror current sources M5, M6, and M9 to supply current to each branch. are equal to those of M1 and M3, respectively. Thus, a 2-time expression was given in the corresponding formula. Since the noise of the output stage is not amplified, it can be ignored. The expression for the first-stage amplifier gain Av1 is as follows:

VOP
(1) The formula for the total output noise is The formula for the overall gain of the amplifier is ( ) The formula for the equivalent noise at the input is According to the structure shown in Fig. 4(b), the input characteristics of the amplifying circuit can be expressed as follows: where I0 is the common-mode value, and I1 is the amplitude.
The expressions for the TIAs are as follows: ( ) ( ) By further deriving the output of the SIN pin in Fig. 3(b), the s-domain expression of the system can be obtained as follows: If the system is expressed as and input signal is expressed as the SIN output voltage can be expressed as 10 2 sin( ) By establishing a simulation model according to the above formulas, the gain of the system is obtained as = 93.48 ( / ); at the dominant pole (-3 dB), −3 =

425
; the input signal is the peak-to-peak value of = 1 of the SIN output signal at a low frequency of 50 Hz; the input signal is the peak-to-peak value = 937.55 > 1 √2 = 707 of the SIN output at 300 kHz. consistency between the two amplifier circuits, the amplifiers were matched, and an array design was adopted for the feedback resistance. In addition, the capacitors and resistors were isolated from each other using dummy components. The index parameters of the incremental signal chain are summarized in Table 2.

Grating measurement principle and signal error source analysis
It can be seen from Fig. 1 that the grating measurement system is composed of the main grating, an indicating grating, a light source, and a photoelectric receiving device.
The relative movements of the main and indicating gratings during measurement generate the moiré fringes, which are then converted to moiré fringe photoelectric signals by the photoelectric receiving device. Finally, the signals carrying the angular position information are converted to weak electrical signals. As described in Section 2, the indicating grating is generally designed as a window form where a one-bit code corresponds to four photodetectors. The initial moiré fringe signal is converted into four photocurrent signals with phase differences of 90°, passed through the signal processing circuit, converted and amplified into a voltage signal, and finally passed through an analog to digital converter (ADC).
During the measurement process, factors such as light source, grating design, optomechanical assembly, signal processing, and service environment may result in sinusoidal errors in the moiré fringe signals, thereby affecting the system's subdivision accuracy. Therefore, it is necessary to correct and compensate for the sinusoidal errors in the signal to achieve high-precision measurement.

Principle of moiré fringe photoelectric signal subdivision
The arctangent subdivision (ATS) method is a commonly used digital subdivision approach based on the relationship between the amplitude and phase of the moiré fringe signal. The expression for the ideal grating signal after two-stage differential processing is as follows: The ATS method obtains the phase of the signal by constructing a tangent function as follows: ( ) sin tan sin cos cos cos cot sin cos sin   Table 3.

Error compensation principle and signal waveform construction
The subdivision principle for the grating moiré signal involves solving the angle from two ideal sine and cosine signals. However, the actual output grating moiré signals contain harmonic components. According to Fourier series theory, the grating moiré fringe signal can be expressed as where Ai and Bi (i = 0, 1, 2...n) are the amplitudes of the harmonics of the sine and cosine signals, respectively.
The subdivision accuracy and subdivision error are interdependent, that is, the subdivision accuracy can be reflected by the subdivision error and vice versa.
Subdivision is realized using ideal sine and cosine signals; however, the actual outputs are not ideal sine or cosine signals. Therefore, there will be a difference between the subdivision value of the actual and theoretical angles, which is the subdivision error.
The moiré fringe signal is compensated on the basis of the above analysis. In this work, the angle errors caused by the signal harmonics were quantized, and a lookup table was used to directly compensate for the sinusoidal errors of the angle subdivisions. The specific process is illustrated in Fig. 7. The subdivision error Δθ is given by It can be seen that the sinusoidal error compensation of the grating moiré fringe signal can only be realized by establishing a complete signal waveform equation and solving its position parameters. To construct a lookup table between the actual angles and the corresponding errors, waveform equations must be obtained for the two signals that are to be compensated. Five sets of signals were collected from the measurement platform and were Fourier transformed, as shown in Fig. 8. According to the spectrum in Fig. 8, the 0th, 3rd, 5th, and 7th-order harmonics in the signal account for the largest proportion (approximately 10%) of the fundamental wave, whereas the 2nd, 4th, 6th, 8th, and remaining-order harmonics only account for a small proportion (2%). This result shows that the developed optoelectronic chip can effectively suppress the even harmonic components of the signal. Therefore, the waveform equation is given by formula (18) According to the above analysis, it is necessary to solve the five unknown parameters in the two signal waveform equations to eliminate their harmonic components.

Waveform parameter solution based on the PSO algorithm
Based on the signal waveform equation obtained above, five positional parameters are determined. Considering a sine signal as an example, the PSO algorithm is used for fitting and can be expressed as follows: where A0

f A A A A A
where the fitness is defined as When using the PSO algorithm to solve the waveform parameters, the spatial position of each particle is composed of five variables. In the iteration process, updates are performed according to the best position of each particle (pbest) and the global best position (gbest). The iteration formula is as follows: where k is the number of iterations; d is the dimensionality and represents the number of independent variables; r1 and r2 are two independent and uniformly distributed random numbers; xid (k) is the dth dimensional According to the iteration formula of the PSO algorithm, particles in a given space will gradually approach the position with the smallest fitness value, and the final particle positions with the smallest fitness is the solution to the waveform equation parameters. The specific process of realizing parameter identification using the PSO algorithm is illustrated in Fig. 9.   Fig. 9 Solving the waveform parameters by particle swarm optimization Field programmable gate arrays (FPGA) offer advantages such as multithreaded operations and strong algorithm implementation capacity. Thus, an FPGA was used herein to implement signal error compensation. In addition, to obtain a more intuitive sinusoidal error compensation, a 10-bit subdivision was performed on the collected moiré fringe signals. The results before and after processing are also compared to verify the effectiveness of the subdivision error compensation algorithm. The key to angle error compensation is to obtain the signal waveform equation and establish the angle compensation lookup table, as noted above. The accuracy of the waveform parameters directly affect the compensation outcome. When solving the signal waveform parameters using the PSO algorithm on an FPGA-given the complexity, fitting accuracy, and time cost of the PSO approach-the algorithm was reasonably simplified while ensuring fitting accuracy by mainly considering the impact of the inertial weight on the result.
The inertial weight w coordinates the local and global optima. A relatively small value of w is conducive to the convergence of the algorithm, where the particle search tends to favor the local region; on the contrary, a relatively large value of w is conducive to escaping the local region, thereby improving the global search ability of the particles.
The commonly used linear inertial weight change formula is given as follows: where wmax is the maximum inertial weight, wmin is the minimum inertial weight, itermax is the maximum number of iterations, and k is the current number of iterations.
Generally speaking, if the number of particles N in the particle swarm is too small, the algorithm is likely to be trapped in a local optimum; on the contrary, if N is too large, the algorithm cannot converge easily. Normally, N∈ [10,50], and for most problems, 10 to 20 particles provide ideal convergence results (Gao et al. 2013). In this study, the number of particles N was set to 20, maximum number of iterations was set to 300, wmax = 0.9, and wmin = 0.1 were used in the calculations. The lookup table for the actual calculated angles θm and errors Δθ can be constructed from the obtained waveform parameters and waveform equations, thereby realizing compensation for the sinusoidal errors. When constructing the angle error lookup table, the first step is to identify the angle errors accurately through the lookup table address (Zhu et al. 2019). The lookup table constructed in this study is shown in Table 4.  (17), the sinusoidal errors in the signals could be compensated using the FPGA.

Establishment of the experimental platform
To verify the effectiveness of the proposed sinusoidal error compensation scheme, we built a high-precision angular displacement sensor test platform based on the optical continuous closed loop, as shown in Fig. 10. The test system mainly includes the angle standard, autocollimator, photoelectric encoder, ADC module, FPGA module, logic analyzer, and turntable. Among these, the angle standard is a high-precision 23-plane optical polyhedron. The measurement encoder and polyhedron are connected coaxially to ensure that there are no angle transmission errors between the reference and measured objects. The crossline of the autocollimator is maintained consistent with the rotation direction of the photoelectric encoder, and the aiming error of the autocollimator is ±0.05" within a 300" range. The reflecting surface of the polyhedron is parallel to the axis of rotation of the photoelectric encoder. An air-bearing turntable is used to rotate the encoder at small angles, with a minimum step size of 0.1". The turntable has a vertical shaft structure, where the two shaft systems can move independently. The specific parameters of the test platform are listed in Table 5. work is used in the encoder to receive and process the incremental code signals. The ADC module contains a 12-bit AD9238 chip with a maximum sampling frequency of 65 MHz and an effective precision of 11.2 bits. The FPGA used in the platform is a XC7Z020-2CLG400I from XILINX. The ADC chip converts the analog signal outputs from the encoder optoelectronic chip to digital signals, which are then collected by the logic analyzer and transmitted to the FPGA to implement the compensation algorithm.

Subdivision error correction
In the actual test process, the 23-plane polyhedron and angular displacement encoder are installed coaxially, and the photoelectric autocollimator is used to calibrate the 23-plane polyhedron. When the sight axis of the autocollimator is perpendicular to the working surface of the 23-plane polyhedron, the readings from the angular displacement encoder are recorded and compared with the angles of the autocollimator.
The difference between these two values is the error of the encoder. To obtain the corrected results in a more intuitive manner, an oscilloscope is used to display the twochannel output results from the photoelectric encoder, as shown in Fig. 11. It is seen from the figure that the sinusoidal characteristics of the signal are severely affected by the presence of harmonic components. The frequencies of the two output signals are both equal to 100 kHz, with amplitudes of 850 mV and phase difference of 90°. To subdivide the acquired signals, the 90° and 180° phases of the signal are considered as the starting positions, and an arbitrarily cycle is selected for processing.
As noted above, the effective precision of the 12-bit ADC chip used in this work is 11.2 bits. Given the accuracy of the data results, only 10-bit effective data are retained herein.
According to the analysis in Section 3, the signal can be divided into eight intervals evenly within one period; thus, 128 points are collected in each interval for processing, and the results are shown in Fig. 12. For the signal with the 90° starting position, the maximum dynamic subdivision error of the grating moiré signal was +1.79ʺ, minimum was -1.19ʺ, and peak-to-peak error value was +2.98ʺ before correction. After compensation, the maximum dynamic subdivision error was +0.61ʺ, minimum was -0.56ʺ, and peak-to-peak error value was +1.17ʺ. For the signal with the 180° starting position, the maximum dynamic subdivision error of the grating moiré signal was +1.64ʺ, minimum was -1.18ʺ, and peak-to-peak error value was +2.82ʺ before correction. After compensation, the maximum dynamic subdivision error was +0.62ʺ, minimum was -0.51ʺ, and peak-topeak error value was +1.13ʺ. The subdivision error was thus reduced by 60%, and the subdivision accuracy improved significantly. By performing Fourier transform on a complete cycle of signals starting at 90° as shown in Fig. 12(a), the results shown in Fig. 13 are obtained. Fig. 13 Spectrum results of grating moiré signals before and after sinusoidal error compensation It is seen from the figure that before compensating for the sinusoidal errors, the grating signal contained obvious 0th, 3rd, 5th, and 7th-order harmonic components.
After compensation, the influences of the odd harmonics and DC components in the signal were suppressed effectively, and the overall subdivision error of the signal was reduced significantly. From the above analysis, the compensation scheme proposed in this work for the positive linearity error of the signal is effective, and the subdivision accuracy of the grating moiré fringe signal is improved significantly.

Conclusions
To reduce the effects of sinusoidal errors in grating moiré fringe signals on the subdivision accuracy and to improve the subdivision accuracy of the photoelectric encoder, an optoelectronic chip was developed in this study for receiving and processing incremental code signals. The advantage of the proposed method is that a photodetector array matching the incremental code disk is employed, which effectively reduces the errors caused by light diffraction and uneven light sources. A differential amplifier designed with adjustable gain can eliminate the even harmonic components of the signal, thereby improving the signal quality. Further, a subdivision error compensation model and an angle compensation scheme were established for the signal.
Then, the PSO algorithm was implemented on an FPGA to solve for the parameters of the sinusoidal waveform equations, which were combined with the subdivision error compensation model. An angle error compensation lookup table was designed to further compensate for the sinusoidal errors in the signal. Finally, the effectiveness of the compensation model was verified through experiments. The experimental results show that the subdivision errors of the encoder's photoelectric signals were reduced by about 60% and that the peak-to-peak values of the subdivision errors decreased from 2.98ʺ to 1.13ʺ. The subdivision accuracy was also significantly improved. Therefore, the system scheme proposed in this paper can effectively compensate for sinusoidal errors in grating moiré signals, reduce the size of the photoelectric sensor, and improve the angle measurement accuracy of the grating measurement system. In the next study, we intend to explore integration of the ADC module with the encoder's optoelectronic chip.
Moreover, we expect to implement the algorithm on a DSP chip to develop a complete and highly integrated error compensation system for encoder errors.

Conflicts of interest:
The authors have no conflicts of interest to declare that are relevant to the content of this article.

Availability of data and material:
The datasets generated during and/or analysed during the current study are available from the corresponding author on reasonable request.
Code availability: The datasets generated during and/or analysed during the current study are available from the corresponding author on reasonable request.

Authors' contributions:
All authors contributed equally to this work.