1 Introduction

Precision measurement is a perennial important research direction in high-end manufacturing. It mainly uses two schemes, namely electrical and optical. First, the electrical scheme mainly includes eddy current [1,2,3,4], inductance [5], and capacitance [6] sensors. However, this approach is limited by nonlinearity and electromagnetic interference, particularly for large measurement ranges [7], and is commonly used in applications with small measurement ranges.

Second, the optical scheme mainly consists of laser interferometers and optical encoders. Each scheme has its advantages and disadvantages. Laser interferometers, which rely on the wavelength of light as their measurement reference [8], are susceptible to environmental influences and can achieve high precision in well-controlled laboratory environments [9]. Nevertheless, industrial applications need a stable measurement approach. Optical encoders, which use the physical structure of gratings as their measurement reference, are little affected by environmental factors, and their upper limit of precision can rival that of laser interferometers [10, 11]. Optical encoders are easy to integrate [12] and can be extended to multiple-degree-of-freedom (MDOF) measurements [13,14,15]. Thus, they have found extensive applications in high-precision machine tools and other manufacturing equipment [16]. The lithography machine manufacturer ASML has also adopted these devices in related applications, demonstrating the growing potential of optical encoders in precision manufacturing that surpasses even that of laser interferometers [17].

Absolute measurement has always been a main development direction for optical encoder systems. Related research mainly involves placing an absolute code (zero position mask and reference code) along the linear displacement direction, utilizing zero position pulses for absolute positioning [18, 19], and allowing for the straightforward measurement of absolute positions with a simple optical setup [20]. This binary code can be applied in one dimension (X-axis) first and can be reused in the Y-axis at the same time to enable two-dimensional (2D) positioning. This kind of code is more convenient to process than other codes. It does not require point-by-point processing, only short-line drawing, and its processing cost at the micron level is greatly reduced. Yang et al. [21] and Li et al. [22] initially proposed algorithms based on traditional theories to efficiently reduce computation and design absolute codes. Later, Sáez-Landete et al. [23] utilized artificial intelligence (AI) algorithms using global optimization to design 2D binary codes with 10 × 10 pixels that are primarily applied for alignment in lithography [24]. A genetic algorithm was also used to achieve nanometer-level alignment in the form of a chessboard pattern [25]. Sáez-Landete et al. further designed one-dimensional (1D) codes based on the genetic algorithm called dividing rectangles and optimized designs with 100 elements [26, 27]. However, these aforementioned studies did not consider diffraction effects, which become remarkable in the presence of small unit code widths and large distances. Sáez-Landete et al. used a genetic algorithm to design 1D [28] and chessboard [29] absolute codes while considering diffraction to address the above issue. Chen and Wen proposed the cross-entropy (CE)-based method to further reduce the second maximum value by approximately 15% for chessboard patterns but did not consider diffraction [30]. Subsequently, Su et al. introduced a new algorithm called parametric minimum CE that reduced the second maximum value by 8.33%–22.22% [31]. Moreover, they considered the minimum diffraction effect and maximum amplitude as a combined optimization problem; their algorithm achieved a 16.12%–20.90% increase in the sum of the slope of the central peak and the effective signal amplitude of a 2D optical zero reference signal compared with a recently proposed CE method [32].

The increase in the number of binary zero positioning codes can enhance throughput and pulse positioning accuracy. However, the exponentially increasing complexity of code design poses challenges. For example, for a 150-bit binary code with 17 transparent bits, exhausting all possible code arrangements can take 1.1 × 1022 schemes. Although exhausting all the schemes is unrealistic, researchers have used AI to summarize the laws in precision measurement [33,34,35]. For example, AI helped the other researchers find the relationship between the angle of an object to be measured and the position of a light spot [36]. AI models also exist in signal processing [37,38,39,40,41]. The present work also hopes to use AI to learn rules that traditional methods find difficult to build on the basis of a limited number of coding datasets, generate new codes, and use new codes for subsequent performance analysis.

Generative adversarial networks (GANs) are generative models that learn through two neural networks competing with each other. A GAN consists of a generator and discriminator. The generator builds filtered database codes and labels as input, and its output needs to imitate the real samples in the training set as much as possible. The input of the discriminator is the real code and label or the output of the generator, and its purpose is to distinguish the output of the generator from the real sample. The generator and discriminator compete with each other and learn continuously. The ultimate goal is to enable the generator to form a certain rule model, generate new codes and labels, and then input them into the traditional diffraction propagation model to verify and analyze its performance. Therefore, this study chooses a GAN network model to generate code that meets the index. Compared with other traditional algorithms, such as references [19, 20], this method can provide richer and faster code types and is not just limited to one code scheme. Compared with a previously existing machine learning method based on the genetic algorithm [28, 29], this method has a faster training speed and does not need to design the genetic algorithm manually.

Furthermore, previous related studies typically assumed ideal working conditions with fixed distances and thus did not analyze the performances of zero position codes in spatially varying working postures. Therefore, a set of posture intervals is urgently needed as a theoretical guide for code installation and an integrated absolute MDOF measurement scheme design. This work provides a method for code design and working parameter optimization. After the code is generated with the help of AI, specific working parameters are optimized and analyzed while still relying on the traditional diffraction propagation model. The use of AI allows this study to avoid the large amount of time and computing power required for code design and generation.

In summary, current traditional mathematical methods find optimizing designs for binary absolute zero position codes beyond 100 bits challenging. Additionally, the lack of performance analysis for spatially varying working postures leads to limitations in code installation and the design of MDOF measurement schemes. With the aim of addressing these issues, this study proposes a design scheme based on GANs for binary zero position codes considering diffraction (the first letters of “zero” and “diffraction” were selected to form the abbreviation ZD-GAN with GAN). For the first time, coordinated optimization analysis is conducted on the generated schemes for working parameters. The tolerance of the working range is analyzed, and the optimal working state is determined. This study provides valuable guidance for the design, installation, and integration of absolute MDOF measurement schemes by using absolute zero positioning binary codes.

2 Principle of the Zero Position Code Design

The principle of this study is mainly based on those of deep learning GAN and diffraction propagation. The diffraction propagation principle allows for the simulation and generation of a sufficient number of performance labels for corresponding codes, thereby serving as a foundational database for GAN. This approach enables rapid learning and the establishment of its own model.

2.1 Zero Positioning Code and Parameter Introduction

In previous binary code designs, diffraction is generally believed to have no effect on the evaluation of generated codes despite its influence on pulse positioning. Simple correlation algorithms were used to achieve the variation in light intensity during the displacement between the mask and reference code. However, continuous simulation and experimental studies have shown that diffraction effects cannot be ignored for applications requiring high precision. Therefore, diffraction effects must be considered during code generation and evaluation. When designing binary codes, the main parameters to consider are the unit code width (b), working distance (d), and the yaw angle (α).

As shown in Fig. 1a, two reference codes exist on scale grating. Figure 1a shows the ideal pose state of the reference code and mask. Figure 1b depicts the changes in position state between the mask and reference code. Figure 1c illustrates the photodetector (PD) light intensity signal that changes with the position state between the mask and reference code. By taking 1D motion as an example, the laser emitted by LD can be decomposed into sub-beams. Analyzing the propagation categories of sub-beams reveals that sub-beam types 1, 2, and 3 exist. Among these sub-beam types, 1 and 2 pass through the mask, whereas 3 does not pass through the mask, and its proportion to the overall beam remains unchanged. Among these parameters, z is the distance corresponding to the different x coordinates (shown in Fig. 1b) between the reference code and mask; d is the distance from the rotation center of the reference code to the mask. As shown in Fig. 1b, the movement of the scale grating in the positive X direction can be equivalent to the movement of the mask in the negative X direction. State S1 is the state wherein the reference code and mask do not overlap, and only the type 1 sub-beam is present. In the S2 state, a coincident light transmission unit exists between the reference code and mask. At this point, type 1 sub-beams transition to type 2 sub-beams, transmitting out. The energy detected by PD decreases when the light transmission units overlap. In the S3 state, the reference codes on the mask and grating completely overlap, with the number of type 2 sub-beams being the highest. At this time, the light intensity information detected by PD is the smallest and is, therefore, in a negative pulse state. The minimum pulse appears when and only when the reference code and mask completely overlap. At this time, the minimum negative pulse peak is defined as the pulse peak, and the minimum value is the pulse peak. The states of S4 and S5 are the same as those of S2 and S1, respectively. After using the sub-beams for the light beam describtion, this paper uses the diffraction propagation model to analysis the pulse, which is shown in Fig. 1c.

Fig. 1
figure 1

Principle and working parameters of the zero positioning code. a ideal pose state of the reference code and mask, b position state between the mask and reference code, c PD light intensity signal that changes with position

Combining the reference code with the grating is a suitable approach in the design of the integrated absolute six-degree-of-freedom (6-DOF) measurement scheme. The combination method is shown in Fig. 1a. The scale grating of the whole structure is a 1D grating with a period of 1 µm, and the reference code is directly written on the grating surface. The unit code width exceeds 10 µm, and the diameter of the light spot is generally 2 mm such that the light spot can cover numerous grating structures, and the description of the reference code does not have a considerable influence on the diffraction effect of the grating. The ratio of the light-transmitting unit should not be excessively large; otherwise, in the S3 state, a large amount of light is transmitted and effectively reflected and diffracted light will not form for subsequent 6-DOF detection. First, a sufficient interference signal intensity is necessary to achieve MDOF and absolute measurements simultaneously. Therefore, the transmittance ratio needs to be controlled to be less than 20% (when the binary code number is 150, the light transmission slit number is less than 30) to avoid reducing the resolution of the interference signal. Under the same code working condition and without considering diffraction, a small unit code width (b) leads to high positioning accuracy. However, under practical conditions, a small unit code width results in strong diffraction effects, increasing uncertainties during actual operation. Hence, an appropriate unit code width ensures positioning accuracy while enhancing system stability and resistance to interference. Second, six spatial posture changes occur between the zero position mask and reference code on the scale grating. In-plane motion has no effect on encoding performance, whereas out-of-plane motion alters the working distance (d). In theory, a large working range of d is preferred. Lastly, the rotation angles include those of yaw (α), pitch (γ), and roll (β). In Fig. 2, the yellow axis is the axis of rotation; the yellow dot is the origin, which is the spot energy center; and any other axes and origins are non-center rotations. Figure 2a presents the state when the mask tilts. Figure 2a shows the pose parameters that exist during tilting with sub-beam types 4, 5, and 6. α is the tilt angle and is positive in the counterclockwise direction. Figure 2a shows a negative angle. Figure 2b shows that the α rotation axis is the Y-axis direction. Figure 2c illustrates that the β rotation axis is the Z-axis direction. Figure 2d depicts that the γ rotation axis is the X-axis direction.

Fig. 2
figure 2

Schematic of the reference code rotary axis and rotary axis origin. a state when the reference code tilts, b α rotation axis, c β rotation axis, d γ rotation axis

Changes in α are complex (as shown in Fig. 2a) and affect the reflection direction of the reference code, resulting in different propagation distances for the leftmost and rightmost light rays. For light rays from the zero position mask, the unit code width (b) of the reference code area decreases in size due to inclination, leading to the reduced transmission width of the area and length of the reference code. The intensity distribution of the light reflected back to the mask is no longer one-to-one, causing the slippage of the theoretically aligned position. Light passes through this mask by (1) being reflected back and received by the PD, (2) being reflected back by the reference code area and then blocked by the mask, and (3) passing through the reference code. When γ changes, the rotation axis in the center of the light spot has almost no effect on the pulse signal. However, if the axis revolves around others, then the change in γ can be seen as a change in the working distance (d). As for roll angle β, a rotation axis in the center of the light spot, the zero position mask gradually loses the transmission area, leading to the distortion of the pulse signal, the reduced intensity of the pulse peak, and even the loss of the pulse signal. Otherwise, the rotation can be converted into two in-plane motions. Given that β and γ have convertible effects on the pulse signal, this study mainly analyzes the influence of b, d, and α, which are collectively referred to as working parameters.

At different working parameters, the full width at half maximum (FWHM) of the pulse peak is denoted as W (in µm). The ratio of the secondary peak to the main pulse peak is the contrast K. In theory, a small W is desired to confine the zero position interval finely. A high K is preferred to locate the main pulse peak in the presence of disturbances clearly, thereby avoiding the incorrect selection of other pulse peak positions. In this study, K/W is used as a performance label to analyze and compare schemes. When the contrast K does not remarkably differ between two sets of codes and both sets of codes can distinctly and correctly determine the pulse peak position, the scheme with a small W is prioritized for absolute positioning, resulting in the high upper limits of positioning accuracy. The constraints on K and W represent the tolerance of the binary absolute zero position code to the working parameters, theoretically limiting its ultimate precision during practical operation. Therefore, thorough analysis and investigation are required to guide practical absolute measurement schemes.

2.2 Principle of Pulse Signals Considering Diffraction

The ZD-GAN network architecture can be built, and the original dataset must be generated. In this study, a random generation approach is adopted to create 150-bit codes with less than 20% transparent elements. The labels of these codes need to be analyzed and determined on the basis of diffraction propagation principles.

The structure of the mask and reference code can be represented by using the matrix a = [a1, a2,…, an], where n represents the number of code bits, ai = 1 denotes a transparent element in the code, and ai = 0 represents an opaque element. Each code bit has a unit code width of b. D is the total width of the code. On the basis of the optical path principle illustrated in Fig. 1a and under the assumption that α is 0 and the laser beam passes through the mask for the first time after the energy beam splitter, the optical field distribution (without considering diffraction effects) can be described as follows:

$$t(x) = \sum\limits_{i = 1}^{n} {a_{i} \times {\text{rect}}\left( {\frac{x - i \times b}{b}} \right)} ,\quad 0 \le x \le 3D,$$
(1)

where rect is the rectangular window function and x represents the horizontal coordinate of the grating in Fig. 1b.

In this study, the angular spectrum theory of light is used to simulate the diffraction effects of light rays. Therefore, the optical field distribution when the beam passes through the mask and reaches the scale grating can be described as follows:

$$I\left( {x,z} \right) = \left| {F^{ - 1} \left\{ {F\left\{ {t\left( x \right)} \right\} \cdot \exp \left( {{\text{i}}2\uppi z\sqrt {1/\lambda^{2} - v^{2} } } \right)} \right\}} \right|^{2} ,$$
(2)

where F{t(x)} represents the Fourier transform of the light intensity after passing through the mask, λ is the wavelength of the laser, v is the spatial frequency, and z is the distance between the mask and the reference code and varies with changes in the yaw angle.

When illuminated by the laser beam, the reference code region on the grating modulates and reflects back the optical field. This reflection characteristic function can be written as

$$f(x) = \left\{ {\begin{array}{*{20}l} {1,} \hfill & {0 \le x < D} \hfill \\ {1 - t(x),} \hfill & {D \le x < 2D} \hfill \\ {1,} \hfill & {2D \le x < 3D} \hfill \\ \end{array} } \right..$$
(3)

When the reference code undergoes displacement along the length direction of the measurement grating, the intensity distribution of the reflected beam can be expressed as follows:

$$I_{f1} \left( {x_{0} ,z} \right) = I\left( {x,z} \right) \cdot f\left( {x + x_{0} } \right),\quad 0 \le x \le D,\quad 0 \le x_{0} \le 2D,$$
(4)

where x0 represents the value of the relative displacement between the mask and the reference code.

Given a reference code area on the scale grating, the reflected light also shows diffraction effects. In this study, the diffraction effects are also analyzed by using angular spectrum theory. Thus, the optical field distribution illuminating the mask can be expressed as

$$I_{{f2}} (x_{0} ,z) = \left| {F^{ - 1} \left\{ {F\left\{ {I_{f1} (x_{0} ,z)} \right\} \cdot \exp \left( {{\text{i}}2\uppi z\sqrt {1/\lambda^{2} - v^{2} } } \right)} \right\}} \right|^{2} .$$
(5)

The final beam passes through the mask again and is then detected by the PD. The optical field is remodulated by the narrow slit of the mask, and its intensity distribution function can be expressed as

$$I_{m} (x_{0} ,z) = I_{f2} (x_{0} ,z) \cdot t(x).$$
(6)

2.3 Structure of GANs

The dataset is obtained by using professional simulation software (MATLAB and the diffraction propagation principles) and by constructing a GAN network structure to generate 150-bit codes. As shown in Fig. 3, the GAN model process begins with defining the generator, discriminator, and training functions. A diffraction propagation model is used to establish a dataset that includes several randomly generated codes as inputs. The input content consists of the zero position code and corresponding label (K/W).

Fig. 3
figure 3

Design method for ZD-GAN

The dataset is divided into training and testing sets. The generator’s role is to produce new codes that resemble those in training, whereas the discriminator attempts to differentiate between the generated and real training codes. The GAN combines the generator and discriminator as parameters, coordinating their training and sharing their parameters. During this process, the effectiveness of the discriminator is evaluated by using the binary CE loss functions, and the training functions are used for the GAN model through multiple rounds.

The GAN network used in this study has a simple network structure. Its logic is shown in Fig. 3. First, the generator and discriminator, as well as training, are defined. Second, the label and code provided by the dataset are entered into the generator and discriminator, respectively. The network structure of the generator wherein the label enters is fully connected, and the final output is a fake code (150 bits). The discriminator makes a distinction between the real and fake codes generated by the generator. The network structure adopts a series of full connection blocks (consisting of a fully connected layer and a nonlinear activation layer) and calculates the loss that mainly consists of discriminator and generator judgments on true or fake codes, as shown in Fig. 3. Given that the code has 150 bits, the discriminator learns faster than the generator. Therefore, the initial learning rates adopted by the generator and discriminator here are 0.005 and 0.0001, respectively. This approach can ensure that the two can learn against each other and avoid the situation, wherein generator loss keeps increasing, and discriminator loss is almost 0. The finally trained generator receives a set of labels with high values and generates a set of new codes that are then input into the diffraction propagation model to obtain their corresponding real labels. The model calculates K and W and applies non-maximum suppression to select the optimal set of codes.

At this point, the waveform data of the pulse signal can be obtained, and K and W can be analyzed. The standard working parameters are set as d = 500 μm, b = 10 μm, and α = 0 μrad. The GAN model is completed with 16000 sets of training data and 4000 sets of test data, and binary codes are generated by ZD-GAN. For each generation, 10 binary codes are obtained, and the diffraction propagation model performs non-maximum suppression. This process ultimately produces absolute binary code schemes with improved robustness and accuracy. In the original training dataset, the best label is K (1.7920)/W (17.8839) = 0.1002, whereas the best-generated data have K (8.1156)/W (35.3961) = 0.2293 and K (6.5739)/W (28.5469) = 0.2303. This result represents a maximum improvement of 129.84%, demonstrating the effectiveness of the proposed ZD-GAN.

3 Code Performance Simulation and Theoretical Analysis

The use of ZD-GAN provides two absolute codes: A (16 transmissive units) with a contrast of 8.12 and B (25 transmissive units) with a contrast of 6.57 (Table 1).

Table 1 Two codes generated by ZD-GAN

Figure 4a shows the shape distribution of codes A and B (colored regions represent transmissive elements) and their performance with varying b values. Figure 4b, c shows the coordinated effects of d and α on the positioning performance of code A, whereas Fig. 4e, f shows the same effects but on the positioning performance of code B. Figure 4d presents the optimal positions of K/W given by the global optimization algorithm for code B.

Fig. 4
figure 4

Relationship between the positioning performance and working parameters of codes A and B. a Code A/B and performance with b, b contrast with d and α of code A, c FWHM with d and α of code A, d global optimization for code B, e contrast with d and α of code B, f FWHM with d and α of code B

Figure 4a demonstrates that when b is less than 10 μm, codes A and B exhibit contrasts close to 1 and a sharp change in the FWHM (W). An observation of the waveforms reveals that the main reason for the sudden increase in W is the secondary pulse peak closely following the main one, resulting in the calculation of W to include both pulses and not only the half-width of the main pulse peak. The considerable change in W indicates a clear decline in the performance of the pulse signal. This decline can considerably affect the search for the main pulse peak given experimental noise and thereby indicates the deterioration of pulse signal performance. For unit code widths beyond 10 μm, only code B shows a bimodal phenomenon, leading to a decrease in contrast to approximately 1. However, W does not change considerably, indicating that the bimodal phenomenon occurs only within a small interval near the valley bottom (i.e., pulse peak) and has no remarkable effect on fitting and positioning performance. Additionally, in general, code B is preferred, given its smaller W than code A.

Figure 4b, e indicates that code A has a larger range than code B for contrasts greater than 1. For both codes, the area of contrast greater than 8 is similar. For both codes, the tolerance to changes in the negative angle rotation for distance is also higher than that to changes in the positive angle rotation. However, Fig. 4c, f shows that the area of large W in code B is smaller and is less affected by negative rotation angles for distances less than 1000 μm than that in code A. Therefore, considering the tolerance to working distance and rotation angles, the overall performance of code B is superior to that of code A.

After the analysis of the three parameters, code B is finally selected as the experimental subject, and the positioning performance is evaluated. The result of the global optimization algorithm for code B is shown in Fig. 4d. The main global optimization algorithm here aims to provide an optimal working position with increased accuracy. The main parameters are limited to the working distance from 500 µm to 1500 μm and α from 1 × 10−3 μrad to 40 mμrad; by using a Bayesian optimizer, the maximum number of calculations and time are 200 times and 60000 s, respectively, and the acquisition function of the next point shows the expected improvement. Given that the global optimization algorithm is looking for the minimum value, this work adds a negative sign to K. The objective of optimization is to maximize the label (contrast) with b fixed at 10 μm and the minimum working distance d at 500 μm. The final results are d = 500.23 μm and α =  − 39.86 mrad, which fall within the optimal range obtained from traditional theories. The proposed algorithm can serve as a guide for optimal orientation with increased accuracy.

In summary, based on the analysis in Fig. 4, the findings suggest avoiding sharp changes in W by designing zero position code with a width b greater than 10 μm and within the working distance d and yaw angle α of 1000 μm and 20.9 mrad, respectively. Additionally, a working position with a small W as the central parameter is suggested for practical purposes.

4 Zero Position Code Experiment and Result Analysis

In accordance with the principles illustrated in Fig. 1, this study constructed the zero positioning experimental system shown in Fig. 5a, b. Additionally, the mask and reference of code B, as depicted in Fig. 5c, were designed and fabricated. The precision of both components was measured and verified by using a high-magnification microscope, as shown in Fig. 5d, and was found to meet the error requirement of less than 1 μm.

Fig. 5
figure 5

Zero positioning experimental system and zero position mask and reference code. a Panorama of the experimental system, b specific details of the zero positioning system, c object pictures of code B and PD, d code amplification

The displacement device used was Z825B of THORLABS, which has a repeat positioning accuracy of 0.2 μm and a resolution of 0.05 μm. The rotation device TD-170-50 has a rotation accuracy of 145.4 μrad and a repeat accuracy of 12.1 μrad. The PD model was the Hamamatsu S5106. The principle of light intensity detection is as follows: A Si PIN photodiode array converts optical signals into electrical signals through the absorption of light and generation of electron–hole pairs. Given that the intensity of this electrical signal is proportional to that of the incident light, it can be used to measure the intensity of light or the change in the intensity of light. This study used an amplifier to amplify signals and then obtained the corresponding waveform signals.

As shown in Figs. 1a and 5b, the beam starts from the light source and enters the polarizing beam splitter and quarter wave plate. Part of the beam is reflected by the mask, enters the PD, passes through the mask, and irradiates the reference code. Subsequently, as shown in Fig. 1b, c, with the movement of the reference code, the energy of the light beam reflected by the reference code changes continuously, thereby causing the energy change in the PD and finally forming a pulse peak.

During the experiment, the zero position of the rotation served as the zero angle reference, and the distance d and yaw angle α were varied. The yaw angle changed by 3490 μrad in each step, and the waveform and positioning performance of the pulse peaks were recorded.

The spot energy used in the experiment is a laser that follows a Gaussian distribution and exhibits good temporal stability. The light is initially projected onto the mask, and with the reference code movement, the PD starts generating signals that are received by the computer. Figure 6 shows the comparison between the simulation and experimental waveforms when d = 880 μm. The excellent matching confirms the reliability of the simulation.

Fig. 6
figure 6

Intensity of the light spot and pulse waveforms. a Light intensity, b waveform

In the experiments, pulse energy was normalized in consideration of a total reflectance of 6% from the reference code (chromium plate) to the PD. Thus, different waveform graphs were produced at distances of 1780, 1530, and 1280 μm. The reference code was rotated in steps of 3490 μrad around the zero position within a range of ± 10.47 mrad, as shown in Fig. 7.

The analysis reveals that the positive angle rotation causes distortion in the pulse signal, resulting in a decrease in contrast and an increase in the FWHM (W). In turn, this phenomenon reduces the positioning performance. This finding is consistent with the simulation results. Conversely, negative angle rotation enhances the pulse signal but also induces changes in the zero position. Thus, actual calculations require adjustments based on angle measurements (Fig. 7).

Fig. 7
figure 7

Pulse waveform with different d values at a 1780, b 1530, and c 1280 μm

The decrease in distance enhances the pulse signal, indicating that reducing the distance indeed weakens the diffraction effect. This finding is aligned with the simulation results. However, an excessive reduction in distance may lead to collisions between the reference code and mask during rotation, making a small d for the experiment unfeasible. In actual practical use, the length of the structure (the grating or the mask) can be shortened such that the reference code can have a large rotation angle.

If the given angle varies, the contrast K and W will change, as shown in Fig. 8a. Although generally similar to the simulation values, the experimental contrast K does not maintain a constant level and then decrease; rather, K starts to decrease early with the change in angle, indicating that in practical use, the pulse waveform is highly sensitive to the rotation angle due to factors, such as the energy distribution of the light spot and electric noise. Similarly, the experimental W increases with angle as in the simulation but at a fast rate. The main reason for this deviation is the design of code B. When the amplitude of the main pulse decreases, the immediate occurrence of the secondary peak causes the calculation of W to include both pulses rather than only the half-width of the main pulse peak. As a result, W increases dramatically in the experiment, appearing as early as 3490 μrad. Therefore, in practical applications, large rotations after this angle must be avoided.

Fig. 8
figure 8

Experimental performance of the zero positioning code: a variations in K and W at different α values, b variations in zero positioning repeatability

Figure 8b shows the final evaluation of the positioning performance at 880 and 1780 μm with 0 degrees of rotation. The absolute sum of the positioning variation during the forward and reverse movements of the displacement stage is at the sub-micrometer level, demonstrating that the generated code can achieve precise positioning. The sub-micrometer positioning accuracy provides support for future high-precision hybrid-positioning applications.

5 Summary

This study addresses the limitations in the design and performance of zero position codes for precision absolute measurement. A novel approach using deep learning, namely ZD-GAN, is introduced to generate a high-quality 150-bit zero position code. Various working parameters affecting the practical performance of the zero position code, including unit code width (b), working distance (d), and yaw angle (α), are analyzed through simulations and experiments. The results demonstrate that the codes generated by ZD-GAN are effective and outperform those generated by the training datasets. The analysis of two typical codes shows that the contrast (K) is generally positively correlated with b and negatively correlated with d and α. The FWHM (W) mainly has positive correlations with d and b, and its relationship with α increases in complexity at large distances. The findings suggest that for code design, b must be greater than 10 μm, and the values of d and α should ideally be within the ranges of 1000 μm and 20.94 mrad, respectively, to avoid abrupt changes in W. However, in consideration of noise in practice, the angular range is limited to below 3490 μrad, and the selection of parameters with a small W as the central working parameter is advised. The other corresponding rule model requirements, such as a long work distance and large yaw angle, can be quickly established with the help of ZD-GAN, and finally, the new code can be verified, analyzed, and optimized with the help of the diffraction propagation model. The proposed code design and parameter optimization provide valuable guidance for the development and design of absolute positioning measurements.