# Research on Data Transmission of Laser Sensors for Reading Ruler
## 3 Research on Coding Ruler Data  
### Absolute Coding  
Absolute encoders are sensors that directly output digital quantity and can directly provide accurate absolute position information. They use binary code for photoelectric conversion and can read fixed digital code matching any position of the coding ruler without calibration. This kind of encoder has excellent anti-interference ability and avoids cumulative error. Its position information can be retained even without a power supply. However, its measurement accuracy is limited by the choice of binary digits, which can be flexibly adjusted to meet accuracy requirements according to specific needs. In addition, the absolute encoder has a fixed \"coding zero point\", which ensures that any other absolute position on the coding ruler is calculated based on this zero point. The absolute position data can be obtained accurately by reading the coding information of the current position [7,8]. (1) The encoding method of natural binary code  
In an absolute coding system, the core function of output code is to accurately determine an absolute position. Taking natural binary code as an example, this coding method, as a weight code, has a one-to-one correspondence with binary numbers. It is characterized by each bit having a clear size value, and these values are arranged from the highest bit to the lowest bit in the order of n power of 2, so they can be directly used for size comparison and arithmetic operation. Due to the characteristics of natural binary coding, an absolute encoder with this coding method can be easily processed by the external controller so that the actual position reading can be obtained directly without any special conversion operation. For example, if the read natural binary code is 0111, according to the conversion rule from binary to decimal, its position value can be calculated as  
\[1\times 2^{0}+1\times 2^{1}+1\times 2^{2}+0\times 2^{3}=7\]  
As shown in Table 1, if the natural binary code is used for position reading, it is necessary to select the required number of n bits, that is, n measurement sensing units, according to the required length of the code scale and the required measurement accuracy. The farther the positioning distance, the higher the accuracy, and the more sensing elements are needed, which is not conducive to the miniaturization and integration of the code reader. Moreover, when the binary code of two adjacent readings changes in multiple bits, errors are easily generated if multiple measurement sensing elements identify that the transmission is not synchronous. (2) Gray code method. Gray code is also known as binary Gray code. Although natural binary code has the ability to directly convert digital signals into analog signals through a digital-to-analog converter, in some specific scenarios, such as when converting from decimal 3 (011) to decimal 4 (100), every bit of the binary number changes [9]. Therefore, if the encoding method of natural binary code is adopted, when the values of multiple digits simultaneously change, it is impossible to adjust the status of multiple digits synchronously, resulting in the existence of a sequence in the data refresh process. However, in the transitional stage of state change, the obtained readings may produce errors (such as 010 or 111). See Table 2 for the application of Gray code in a positioning system. Gray code has unique and significant advantages over other coding methods. Its main advantage lies in that only one digit changes during the conversion between adjacent digits. This remarkable feature effectively reduces the logical confusion that may occur when transitioning from one state to the next and ensures the clarity and accuracy of the transition process. Gray code has only a one-bit difference between adjacent code groups, which leads to higher reliability in the process of digital position signal conversion.