# Research on Data Transmission of Laser Sensors for Reading Ruler
## 3 Research on Coding Ruler Data
### Absolute Coding
Even if the displacement of the code reader changes slightly, the Gray code only changes by one digit, making it more stable than other coding methods in which two or more digits may simultaneously change in the same situation. This feature significantly reduces the possibility of errors, thus improving the performance and reliability of the whole coding system. Assuming that the original value starts from 0, the law of Gray code generation is as follows:  
Step 1. Change the rightmost bit value. Step 2. Change the left bit of the first 1 from the right: 011. Steps 3 and 4. Repeat steps 1 and 2 until all Gray codes have been generated (in other words, step (2\({}^{n}-1\)) has been taken). Take the following as an illustrative example: suppose a 3-bit Gray code is generated, and the original value bit is 000. \begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline  & & 00 & 00 & 01 & 01 & 11 & 11 & 10 \\ \cline{2-10} \multirow{-2}{*}{
\begin{tabular}{c} 0 \\ 0 \end{tabular} } & 00 & 1 & 1 & 00 & 01 & 10 & 11 & 11 \\ \hline Sensing element 1 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\ Sensing element 2 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ Sensing element 3 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Application of Binary Code in Positioning System. \begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline  & & 00 & 00 & 01 & 01 & 11 & 11 & 10 \\ Gray code & 0 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 1 \\ \hline Sensing element 1 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 \\ Sensing element 2 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 0 \\ Sensing element 3 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Application of Gray Code in Positioning System. Step 1. Change the rightmost bit value: 001. Step 2. Change the left bit of the first 1 from the right: 011. Step 3. Repeat step 1: 010. Step 4. Repeat step 2: 110. This process is performed until all the steps are completed. The three-digit Gray code sequence is as follows: 000, 001, 011, 010, 110, 111, 101, 100. (3) The conversion between binary code and Gray code  
According to the comparison in Table 3, there are significant differences between Gray code and other coding methods. Specifically, whenever the data are refreshed, the digital signal read by the code reader only changes by one bit, and this change has no sequence, thus completely eliminating the possibility of code error and code mixing. This feature significantly reduces the possibility of logical confusion when transitioning from one state to the next. For example, when changing from position 7 (0100) to position 8 (1100), only the most significant bit changes from 0 to 1, and only one bit in the code group changes state [10]. In addition, Gray code is usually called cyclic binary code or reflective binary code because the difference between the maximum number and the minimum number is only limited to the difference of a one-bit state. The output signal of an absolute encoder with Gray code is a specific number sequence, not a weight code. In this coding, each bit has no fixed size, so it cannot be directly used for size comparison or arithmetic operation. At the same time, Gray code cannot directly convert signals into other types of signals. In practical application, it is necessary to convert Gray code into natural binary code once and then read it using the upper computer to enable the corresponding control function. In the process of conversion between Gray code and natural binary code, an exclusive OR operation (the same is represented by 0, and a difference is denoted by 1) is used to replace the traditional addition and subtraction operation for binary vertical multiplication and division. This carry-less conversion method is called exclusive OR multiplication and division, and the specific algorithm is not described here. (4) Shift continuous encoding  
So-called \"continuous code shift\" encoding is an encoding form composed of 0 and 1 bits, which are always kept constant. In this encoding rule, any subsequent encoding can be