Improving the subdivision accuracy of photoelectric encoder using particle swarm optimization algorithm

The aim of this study is to improve the subdivision accuracy of a photoelectric encoder and reduce the effects of sinusoidal errors in signals on the measurement accuracy of the system. To this end, an optoelectronic chip that can receive grating moiré fringe signals was designed, along with an amplifier circuit with a hierarchical pipelined architecture. The photodetector array was matched with the code disk before processing the received signals. The sinusoidal errors in the signals were quantitatively analyzed. The results were used to develop a sinusoidal error-compensation method based on a particle swarm optimization (PSO) algorithm. A subdivisional error-compensation model was established to correct the errors in those signals. A rapid solution to the PSO algorithm was implemented on a field-programmable gate array, and a grating test platform was constructed for experimental verification. The peak-to-peak subdivision error of the encoder’s photoelectric signal decreased by approximately 60% from 2.98ʺ to 1.13ʺ. Therefore, the proposed scheme not only significantly improves the measurement accuracy of the photoelectric shaft angle encoder, but also contributes to its miniaturization.


Introduction
Photoelectric encoders are high-precision sensors used for angle measurements. These devices perform digital angular displacement measurements with optical-mechanical-electrical integration. They are widely used in intelligent processing, satellite communication, servo motors, aerospace systems, and so on (Yu et al. 2020;Wang 2012;Yang and Wang 2012). Critical applications, such as aerospace, have demanding requirements for encoder angle measurement accuracy, resolution, and system size (Ahmadi Tameh et al. 2016;Das and Chakraborty 2018). Traditional photoelectric encoders exhibit several significant disadvantages. On the one hand, because of the limitations imposed by the optical and electrical principles, the encoder requires 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 signals. The angle measurement accuracy of the encoder is mainly limited by the subdivision accuracy 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, high-precision, and highresolution photoelectric encoder.
In recent years, various research groups worldwide 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. For example, Qiao (2015) developed an absolute grating ruler using integrated circuit (IC) technology, where the image sensor and photovoltaic array were integrated into a single detector. With this scheme, Qiao simultaneously realized the receiving position code and moiré fringe signal with a single chip and reduced the size of the photoelectric sensing component. However, the complex structure affected the signal quality and reduced the measurement accuracy. Heydemann first proposed a compensation scheme for moiré fringe signals based on least-squares fitting; thereafter, several researchers have continuously improved and optimized the algorithm. Yu et al. (2019) proposed a method based on posterior error fitting (PEF) to solve the signal parameters and simultaneously established the error parameter model in the signal to compensate to improve the accuracy. However, the algorithm requires a large amount of angular position data within a few cycles, which results in slow computation speed and difficulty in real-time compensation. Hong and Xu (2008) proposed an error-compensation method based on the radial basis function (RBF) and constructed a neural network with good learning and generalizability, to improve the measurement accuracy of the encoder. The disadvantage of their method is that the parameters must be locked in advance to construct the model; therefore, it lacks universality and incurs higher costs. 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 signal quality in the presence of harmonic components. Zhu et al. (2021) proposed a digital subdivision direct-compensation method to compensate for the orthogonality problem in the moiré fringe photoelectric signal, which is based on the dualiterative CORDIC algorithm. However, owing to the limitations of the coordinate rotation digital computer (CORDIC) algorithm, the method renders the compensation inaccurate. Zuo et al. (2015) used the discrete Fourier transform method to reconstruct the signal through discrete calibration of the angle measurement error and obtained a 20 bit anglemeasurement accuracy on a 24 bit absolute photoelectric encoder. However, the method has low parameter applicability and provides inaccurate calculations. Moreover, the angle measurement accuracy could be improved further.
In addition, in terms of parameter solution, researchers have applied genetic algorithms to the solution of waveform parameters. However, the method has a high bit error rate and disadvantages of difficult local convergence and slow global convergence (Avdeev and Osipov 2019;Zheng et al. 2019). This study adopts the particle swarm optimization (PSO) algorithm, based on the principle of the arctangent method and swarm intelligence global optimization technology, to model and solve the moiré fringe photoelectric signal. The relationship between the amplitude of each harmonic and the angle error introduced by it was quantified according to the signal spectrum. The cost function of the PSO algorithm was established to solve the parameters. Compared with other error-compensation methods, the PSO algorithm has distinct advantages in terms of universality, computation speed, and convergence. Meanwhile, because the PSO algorithm does not require a large amount of equally spaced angular position data (Gao et al. 2020), applying the PSO algorithm to the compensation processing of the encoder signal has important practical value for realizing automatic compensation.
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, 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. Consequently, automatic compensation cannot be realized when there are environmental variables. In this regard, the contributions of the study to the field of optics are: (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 even harmonics on signals, with a smaller 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 a PSO algorithm was adopted to solve the waveform parameters. Thus, the automatic compensation method helped improve the angle measurement accuracy of the system (Fig. 1).

System architecture
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°. Figure 3a shows the overall architecture of the designed optoelectronic chip, where 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. 3b. 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.

Operational amplifier design
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. P-type metal-oxide semiconductor (PMOS) transistors were used for the input differential pair tube for the amplifier. As the carrier mobility of a PMOS transistor is approximately 2-5 times greater than that of an N-type metal-oxide semiconductor (NMOS) transistor, the 1/f noise of the PMOS transistor is 2-5 times lower than that of the NMOS transistor (Fieque et al. 2011;Tsai et al. 2012). The noise from other PMOS transistors that serve as current sources can be ignored. The noise of the input stages M1 and M3 increase the gain of the second-stage amplifier. The noises of M2 and M4 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 A v1 is as follows:  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. 4b, the input characteristics of the amplifying circuit can be expressed as follows: where I 0 is the common-mode value, and I 1 is the amplitude.
(4) By further deriving the output of the SIN pin in Fig. 3b, the s-domain expression of the system can be obtained as follows: If the system is expressed as H(j ) = H 0 ⋅ e j and input signal is expressed as i in = i 3 − i 1 = −2I 1 sin t , the SIN output voltage can be expressed aswhere According to the abovementioned formula, the following results can be calculated: the gain of the system is obtained as A = 93.48 dB(v∕i) ; at the dominant pole (− 3 dB), f −3 dB = 425 kHz ; the input signal is the peak-to-peak value of v PP = 1V of the SIN output signal at a low frequency of 50 Hz; the input signal is the peak-to-peak value v PP = 937.55 mV > 1 √ 2 = 707 mV of the SIN output at 300 kHz.
This analysis is simulated and verified using a Bode plot (Fig. 5a). Figure 5b, c demonstrate the SIN output waveform when f = 50 Hz and f = 300 kHz, respectively.  Table 2.

Chip implementation
The chip was fabricated using a standard 1-poly 3-metal XFAB 0.35 μm commercial CMOS process and had a total area of 3.5 × 1.8 mm. The layout and photograph of the chip are shown in Fig. 6. The detectors for receiving the incremental signals are arranged in a sector pattern, with an angle of 7.03°. This detector arrangement corresponding to the code disk could avoid errors caused by code-disk contamination and uneven light sources, thereby ensuring adequate quality of the incremental signals. Each photodetector had a size of 25 × 600 μm. To ensure consistency between the two amplifier circuits, the amplifiers were matched, and an array design was adopted for feedback resistance. In addition, the capacitors and resistors were isolated from each other using decoy components. The index parameters of the incremental signal chain are summarized in Table 3.

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 Sect. 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: Let u � 1 ( ) = |A sin | and u � 2 ( ) = |A cos | ; according to formula (13), the differences between u � 1 ( ) , u � 2 ( ) , and u(θ) are shown in Fig. 7. The function u(θ) divides a grating period into eight intervals. By calculating the arctangent of u(θ) and the corresponding subdivision values according to the interval number, the relationship between the interval numbers and subdivision values are obtained, as shown in Table 4.

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 A i and B i (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. 8.
The figure shows that the angle value containing the error can be obtained from the arctangents of the two sampled sine and cosine signals with errors. Then, the angle error  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. 9.
According to the spectrum in Fig. 9, the 0th, 3rd, 5th, and 7th-order harmonics in the signal account for the largest proportion (~ 10%) of the fundamental wave, whereas the 2nd, 4th, (17) Δ = m − .  Fig. 9 Spectrum of the grating moiré fringe signal 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.
Further, the expression of the two signals when the grating moiré signal contains only single harmonic components is expressed as follows: where A represents fundamental amplitude; A i represents the ith harmonic amplitude. We define the ratio of the amplitude of the ith harmonic to the amplitude of the fundamental wave as According to the principle of arctangent subdivision, the expression of the angle error introduced by a single harmonic can be expressed as follows: Equation (19) was derived and simplified to calculate the maximum value of f (θ) as follows: According to the analysis, the value of f (θ) is at its maximum when = arccos (− i ) i−1 . Let M = arccos − i and substitute it into Eq. (20), the expression can be expressed as follows: According to this equation, for the grating moiré fringe signal containing only the ith harmonic, the maximum angle error introduced by it is only related to η i and independent of the order of harmonics. According to Sect. 4.2, considering the accuracy of the data results, only 10 bit of valid data were retained. Therefore, when f max ( ) ≥ 2 1024 , i ≥ 0.61% . In this case, if i ≥ 0.61% , the maximum angle error introduced by the ith harmonic component will affect the interpolation result. Thus, combining the results of Fig. 9, this study not only considers the 3rd-order harmonics, but also the 5th-and 7th-order components. The higher-order harmonics with lower residual influence were not considered, and their influence was dismissed. Therefore, the waveform equation is given by formula (22): . (21) +A 5 sin (5 ) + A 7 sin (7 ) u � cos ( ) = B 0 + B 1 cos + B 3 cos (3 ) +B 5 cos (5 ) + B 7 cos (7 ) . 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 A 0 , A 1 , A 3 , A 5 , and A 7 represent the five unknown parameters in the waveform equation. During each signal period, 128 data points are collected on average. The minimum sum of squared errors of the collected signals are then used as the cost function of the estimated parameters as 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 (p best ) and the global best position (g best ). The iteration formula is as follows: where k is the number of iterations; d is the dimensionality and represents the number of independent variables; r 1 and r 2 are two independent and uniformly distributed random numbers; x id (k) is the dth dimensional component of particle i in the kth iteration; p id (k) is the dth dimensional component of particle i's best position vector p best in the previous k iterations; g d (k) is the dth dimensional component of the swarm's best position vector g best in the previous k iterations; v id (k) is the dth dimensional component of particle i's current velocity vector in the kth iteration; w is the inertial weight; c 1 and c 2 are acceleration constants, with values commonly in the range of 0-2.
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. 10.
Field programmable gate arrays (FPGA) offer advantages such as multithreaded operations and strong algorithm implementation capacity. Thus, an FPGA was used herein to implement x id (k + 1) = x id (k) + v id (k + 1), 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 w max is the maximum inertial weight, w min is the minimum inertial weight, iter max 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-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, w max = 0.9, and w min = 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 5.
In the table above, Addr is the lookup table address, θ' is the angle interval of the lookup table, and M is the maximum address of the lookup table. Finally, according to formula (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. 11. 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 6.
A 22-bit absolute photoelectric encoder prototype with a code disk structure, as described in Sect. 2.1, is used in the test platform. The code disk contains two code channels: a pseudorandom code channel along the outer circle and an incremental code channel along the inner circle. The optoelectronic integrated chip developed in this 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

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 two-channel output results from the photoelectric encoder, as shown in Fig. 12. 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   Fig. 13. 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-to-peak 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. 13a, the results shown in Fig. 14 are obtained.
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. Furthermore, the results obtained in this study were compared with those obtained by other researchers (Table 7).
The PSO error-compensation algorithm employed in this study exhibits significantly better measurement accuracy than those used by Yu et al. (2019) and Zhu et al. (2021). The angle measurement accuracy exceeded 20 bit after compensation, and the measurement error was less than 2 resolution. Meanwhile, compared with the method used in previous studies, the resolution is improved by increasing the size of the code disc, thereby obtaining higher precision measurements. In this study, a special integrated chip was designed to receive and process the photoelectric signals, which improved the integration of the photoelectric sensing components. More precise measurement results were obtained for a smaller code disk size, which contributes toward the miniaturization of photoelectric axis angular displacement sensor systems. Based on this analysis, the proposed compensation scheme for the positive linearity error of the grating moiré fringe signal is effective, and the subdivision accuracy of the signal is significantly better.

Conclusions
The sinusoidal error-compensation method of a grating moiré fringe signal is studied to improve the angle measurement accuracy of a photoelectric shaft encoder. First, an optoelectronic integrated chip for receiving and processing moiré fringe signals was developed. The designed gain-adjustable differential amplifier can eliminate even-harmonic components in a signal, improving the signal quality and reducing the volume of the photoelectric sensor component. Subsequently, a signal subdivision error-compensation model and an angle compensation scheme were established, the PSO algorithm was used on an FPGA platform to solve the parameters of a waveform equation, and an angle error compensation lookup table was designed to further compensate the sinusoidal error. Finally, a test platform for the grating system was constructed to verify the feasibility and effectiveness of the proposed scheme. The results showed that the peak interpolation error of the encoder's photoelectric signal was reduced from 2.98ʺ to 1.13ʺ, the interpolation error was reduced by 60%, and the measurement accuracy was significantly improved after compensation. The proposed error compensation scheme not only improves the angle measurement accuracy of the grating system, but also contributes toward the miniaturization of the highprecision photoelectric shaft encoder. Future studies must explore the integration of the ADC module with the encoder's optoelectronic chip. Moreover, the algorithm should be implemented on a DSP chip to develop a complete, highly integrated error-compensation system for encoder errors. 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.