## 4 Machine Learning-Based Residual Error Compensator
### REC Based on TCN-LSTM  
In a position tracking system, the instantaneous actual position is influenced not only by the current reference input but also by the preceding inputs and system states over several time instances. Hence, the residual error prediction is typically a sequence modeling problem with time-series data. Let \(Y=\{y_{1},\ldots,y_{t},\ldots y_{T}\}\) be a time series with time span \(T\) where \(y_{t}\) is a vector containing historical reference input and system state information at  
Figure 8: Simplified servo system model. time \(t\). Assuming \(e_{iT}\) is the residual error of the i-th joint from the PDM prediction at time \(T\), the aim of the REC is to find a nonlinear mapping from sequence \(Y\) to \(e_{iT}\), as follows:  
\[e_{iT}=\text{SeqMap}(Y) \tag{17}\]  
Since a TCN can effectively extract and compress the discontinuous features among multi-source variables while LSTM is good at capturing long- and short-term dependencies, the proposed REC adopts the scheme to integrate a TCN and LSTM to leverage both of their merits instead of struggling with which one to choose. The architecture of the suggested REC, which is founded on TCN-LSTM, is presented in Figure 9, where a TCN is used as the input to LSTM. Taking full advantage of a TCN and LSTM, the original data can be processed to extract useful spatial and temporal characteristics. Hence, large-range and deep patterns can be captured to improve prediction accuracy and stability. Hereinafter are the intricate parts of the REC presented in detail. (a) Data pre-processing layer  
Data pre-processing cleans, adjusts, and organizes the original data to facilitate effective feature extraction and shorten training time. Since the input data, such as the reference position, velocity, and acceleration, have different dimensions and a large gap in value ranges, data normalization should be performed to ensure the stability of the numerical calculation. The min-max normalization method is employed and can be illustrated as follows:  
\[y^{*}=\frac{y-y_{\text{min}}}{y_{\text{max}}-y_{\text{min}}} \tag{18}\]  
where \(y\) and \(y^{*}\) are the original and normalized data and \(y_{\text{min}}\) and \(y_{\text{max}}\) are the minimum and maximum values of that type of data. After normalization, the data are limited to a range of [0, 1]. Figure 9: Framework of REC based on TCN-LSTM network. 2. TCN layers  
A TCN is a distinctive class of one-dimensional fully convolutional neural networks characterized by three key components: causal convolutions, dilated convolutions, and residual blocks. Unlike traditional convolutions, the output at time t in a higher layer using causal convolution is solely influenced by the inputs from the same time t and previous time steps in the lower layer. Hence, the extracted features satisfy the causality, indicating CNN can be applied to time-series modeling. However, for complex sequential tasks, multi-layer or large filters are required to increase the receptive field of causal convolutions, leading to overly complex and computationally intensive models. Therefore, using dilated convolution with a hyperparameter d allows for a significant expansion of the receptive field, which is crucial for detecting long-range patterns within the relevant historical data. In addition, residual connections are embedded in the TCN to prevent performance degradation and avoid gradient vanishing. The complete structure of a TCN network is shown in Figure 10.  
Due to the excellent discontinuous feature extraction and compression capability, the TCN is employed to generate the input features for LSTM, thereby enhancing the long-term memory capability and processing efficiency of LSTM. 1. LSTM layers  
LSTM represents a widely used form of RNN, excelling in addressing challenges related to sequence prediction. The memory unit structure of LSTM is depicted in Figure 11, where the forget gate, input gate, and output gate are adopted to control how many features should be forgotten, consolidated, and output, respectively.