Modeling and Experimental Study for Online Measurement of Hydraulic Cylinder Micro Leakage Based on Convolutional Neural Network

Internal leakage is the most common failure of hydraulic cylinder; when it increases, it decreases volumetric efficiency, pressure and speed of the hydraulic cylinder, and can seriously affect the normal operation of the hydraulic cylinder, so it is important to measure it, especially to measure it online. Firstly, the principle of internal leakage online measurement is proposed, including the online measurement system, the fixed mode of the strain gauge and the mathematical model of the flow-strain signal conversion. Secondly, an experimental system is established to collect internal leakages and strain values, and the data is processed. Finally, the convolutional neural network (CNN), BP neural network (BPNN), Radial Basis Function Network (RBF), and Support Vector Regression (SVR) are used to predict the hydraulic cylinder leakage; the comparison of experimental results show that the CNN has high accuracy and high efficiency. This study provides a new idea for online measurement of small flow on other hydraulic components.


Introduction
Hydraulic cylinder is the actuator in the system, and its failure directly affects the normal operation and life of the system. The leakage is a common failure of hydraulic cylinder, and is generally classified into internal leakage and external leakage. The internal leakage caused by damage or failure of the seal, piston or cylinder wall, so that the oil flows into the oil return chamber from the oil inlet chamber through the small gap between the piston and cylinder inner wall, affects the dynamic balance performance of the hydraulic system, and results in lack of pressure, fall of speed and other issues. The external leakage mainly detects the leakage of the piston rod seal, and detects whether there are leakages at static seal, joint surface, and adjustable structure of the cylinder block. The external leakage is easy to find and measure due to its visibility, while the internal leakage is difficult to detect until the hydraulic system does not work properly. Therefore, it is essential to accurately recognize the leakage to guarantee the hydraulic cylinder works properly.
The fault diagnosis of hydraulic cylinder leakage is divided into two types: Model-based methods and data-driven methods [1]. AN et al. [2] established an EKF-based hydraulic fault diagnostic system,

Online Measurement System
The internal leakage online measurement system is shown in Figure 1. The computer integrates strain data acquisition, data processing and internal leakage prediction module, connected to hydraulic testing rig by strain sensor. The strain data acquisition is completed by the own acquisition software which displays and saves the strain signals in real time at high speed. The data processing module includes extraction and normalization of strain data. The major part of the internal leakage prediction module is trained neural network. When the online measurement system is running, the strain gauge continuously generates the strain signals, the strain sensor collects the strain signals in real time, and the internal leakage prediction module produces the internal leakage value at the moment from extracted and normalized strain data. The online measurement system continuously produces internal leakage values at various times to realize the function of online measurement. The measurement accuracy mainly depends on the installation position and mode of the strain gauge and the internal leakage prediction module.
The strain gauge, as a conversion element for the flow signal, plays an essential role in the test system. Therefore, the adhesion of strain gauge should maximize flow signal conversion ( Figure 2). The strain gauge is attached to the end face of piston, and its outer end slightly exceeds the outer diameter of piston, but does not touch the cylinder inner wall. In order to increase the conversion rate of the flow signal, a fraction of the strain gauge is adhered to the end face of piston, and the oil collecting tank is machined on the side of the piston. During the operation of the hydraulic cylinder, when leakage occurs, the high-pressure oil flows into the oil collecting tank, which impacts strain gauge, and deforms the outer end of the strain gauge to generate deformation signals [22]. The above strain gauge is a resistive based sensor, and its principle is strain effect, that is, the mechanical deformation of the strain gauge sensitive grid causes resistance value change. So the strain generated by hydraulic oil can be equivalent to the resistance change. The strain is at a milli-strain level or lower, so it should measure accurately little change of resistance value. To measure such little change in resistance, the strain sensor must be equipped with the Wheatstone bridge. The strain gauge wire is led out from the oil outlet and makes up a Wheatstone bridge with three external fixed equivalent resistors. The input voltage of bridge is provided by the strain sensor. When the strain gauge is not deformed, the bridge is in equilibrium, and the output voltage is zero. When the strain gauge is deformed, the resistance value changes, the bridge balance is broken, and the output voltage change signals are amplified by the strain sensor and transmitted to the computer, then the strain signals are recorded, saved and processed by the computer (Figure 3).

Flow-Strain Signal Conversion Mathematical Model
The hydraulic oil flows into the oil collecting tank through the annular gap of hydraulic cylinder piston surface, and impacts the end of strain gauge to generate deformation signals. We simplified it into a bending deformation model of cantilever beam, as shown in Figure 4. The strain gauge is simplified into a cantilever beam structure with length L, width b, and thickness h. The free end of the cantilever beam is subjected to a uniform load q, which is simplified by force of hydraulic oil on the free end of cantilever beam. The length a of the uniform load q is approximately the depth of oil collecting tank. The sensitive grid, with length l and its thickness negligible, is distance s from the fixed end of cantilever beam, and its bending deformation produces strain signals.  The blending moment, forcing on the location x(0 ≤ x ≤ L − a) of cantilever beam, can be calculated as: Then calculate average blending moment among the sensitive grid with length l as: From the relationship between stress and bending moment in material mechanics [23]: σ = My I z and the material's Hooke's law: the strain on the sensitive grid is formulated as follows: where E is elastic modulus of material, q is uniform load on the free end of cantilever beam. Equation (3) builds a mathematical model between the uniform load q and the strain ε. The mathematical model between pressure and hydraulic oil volume flow is formulated as [24]: where Q is volume flow of hydraulic oil, k is scale factor, ρ is hydraulic oil density, F is force hydraulic oil on strain gauge. Combine Equations (3) and (4); the mathematical model of flow-strain signal conversion is defined as: From Equation (5), the strain signal can be increased by: • increasing L, namely, reducing the fixed area of the strain gauge and the end face of piston. • appropriately increasing a, namely, deepening the depth of oil collecting tank. Because Q is proportional to cube of annular gap interval, a should not be too large, otherwise strain gauge is not functioning.

Data Acquisition System
The strain data acquisition system consists of hydraulic system and measurement and control system.The hydraulic system shown in Figure 5 supplies stable pressure oil for the entire acquisition system, which consists of power elements (variable displacement piston pump 2), control elements (check valve 7, electromagnetic directional valve 8, orifice check valve 9, electromagnetic relief valve 4), actuators (hydraulic cylinder 10), auxiliary components (filter 6, pressure sensor 5, tank 1). The type of piston pump is 63SCY-Y180, and the system pressure can be adjusted and limited by DBW10AS150B/35 electromagnetic relief valve manufactured by Huade Hydraulic. The oil inlet filter filters impurities of pressure oil to prevent scratching piston and cylinder. The check valve prevents return of pressure oil, and the orifice check valve at the inlet acts as a back pressure. The hydraulic cylinder is a small one for experiment with its piston diameter of 50 mm.
The measurement and control system is used to collect, display and save strain data. The main equipment shown in Figure 6 consists of BX120-1AA high-precision foil strain gauge and DC-204R dynamic strain sensor. The high-precision foil strain gauge has temperature self-compensation function, which eliminates the ill effects of ambient temperature on strain signals. The dynamic strain sensor with DC-7204 measurement and control software, shown in Figure 7, displays and records the instantaneous value and trend of strain during operation of hydraulic cylinder in real time at high speed.
Connect experimental cylinder to hydraulic system, start hydraulic pump 2, then test. The system pressure is set in specified value by electromagnetic relief valve 4. Holding on 5 min, measurement and control software starts to collect and record strain signals, measuring cup receives hydraulic oil from outlet meantime. While measuring cup stops, measurement and control software stops, then read the volume of measuring cup and calculate leakage. Average sample 8 pressure values between 0 and 15 MPa, and repeat above process.

Process Testing Data
According to the hydraulic oil volume measured by the above experiment, calculate internal leakage value for each pressure to obtain relationship between internal leakage and pressure, as shown in Figure 8. Due to interference of the external environment, strain data collected has outliers. So the area under each pressure with strain values slightly fluctuating is selected, and the mean is calculated to obtain the relationship between strain gauge deformation amount and leakage amount, as shown in Figure 9. According to Figure 8, annular gap leakage amount and pressure is approximately linear. It is consistent with the formula of annular gap flow [25]: Q = πdδ 3 12µl p. It can be seen from Figure 9 that there is an approximate linear relationship between strain and leakage, which takes 7 MPa as critical point, with partial higher than 7 MPa good linearity, and partial lower than 7 MPa poor linearity. Possible reason: the strain gauge has high sensitivity, and the strain caused by micro flow at low pressure is extremely small, so above strain value is mainly caused by external noise, such as hydraulic cylinder vibration caused by pressure loading. The strain value with respect to 1 MPa is a negative and is regarded as an outlier.

CNN Architecture
In 2006, Hinton et al. [26] proposed deep learning in science. The key points contain that multi-layer neural network has excellent feature learning ability and layer-by-layer pre-training can effectively overcome difficulties on deep neural network training. CNNs are deep neural networks with convolution operation. Compared with BP neural networks, sparsity of connections and parameter sharing reduce network parameters and easier to train. Sparsity of connections, that is, the kernel, an array of numbers, is convolved with the local region of feature map, and slides in feature map according to specified strides to obtain a new feature map. Parameter sharing, namely, for each convolution operation, kernel convolved with local region is same. Different kernels can be considered as different feature extractors.
Generally, CNN architecture contains input layer, convolution layer, pooling layer, fully connected layer and output layer. Pooling layer is next to convolution layer and they appear alternately, that is, convolution layer-pooling layer-convolution layer. Figure 10 shows the typical CNN architecture.  The convolution layer performs feature extraction, which is composed of a stack of mathematical operations, such as convolution, a specialized type of linear operation [27]. The feature map in upper layer is convolved with kernel, and then the outputs of convolution operation are passed through nonlinear activation to obtain feature map. Multiple kernels are set to obtain multiple feature maps.
where a l j is the jth feature map of lth convolution layer. z l j is net activation of jth channel on lth convolution layer, which is calculated as each feature map a l−1 i of previous layer convolves one kernel, then sum and add bias. k l ij is the kernel, an array of numbers, in respond to ith channel of l − 1th layer, b l j is the bias of jth channel on lth convolution layer, N l−1 is the number of feature maps of l − 1th layer, f (·) is activation function, * is convolution operation.
Pooling layer performs feature extraction, too, which gets the characteristics of spatial non-deformation by reducing resolution of feature map [28]. Define the feature maps of pooling layer to be: a l+1 j = p(a l j ) where a l j is jth feature map of lth convolution layer, a l+1 j is jth feature map of l + 1th pooling layer. p(·) is pooling operation, which uses sliding windows to divide feature map into nxn blocks without overlapping, then average and maximize all pixels in the blocks. According to Equation (7), pooling operation does not change the number of feature maps, that is, N l+1 = N l The fully connected layer is next to convolution layer or pooling layer, connecting all the neurons of the previous layer to each neuron of current layer, which can map extracted features into final output, such as regression to continuous value. If lth layer is the fully connected layer and the previous layer is convolution layer or pooling layer, it can be divided two steps to compute the activation value of fully connected layer: Firstly, arranging all the feature maps of the previous layer into a feature vector. Secondly, compute the activation value by Equation (8).
where a l j is activation of jth neuron of lth fully connected layer, a l−1 i is ith element of feature vector. w l ij is the weight of ith element of feature vector to jth neuron of lth layer.
The form of output layer needs to be selected according to each task. Output layer applied to the multi-class classification task is a softmax layer whose output of jth neuron can be computed by Equation (9). The output layer applied to the binary classification task is the only one neuron with sigmoid activation function whose output is calculated as Equation (10). Output layer applied to the regression to continuous value task is a single linear neuron whose output is expressed as Equation (11) where M is the number of categories CNN identifies. z L j is the net activation of the jth channel of output layer. y j refers to target class probabilities with the scope of 0 to 1.

Prediction Process for Leakage in Hydraulic Cylinder
Prediction process can be divided into four steps: create dataset, create CNN architecture, training CNN, and predict leakage in hydraulic cylinder.
Create dataset: It includes create samples and create labels. Create samples by a random way, that is, select a fixed-length continuous strain starting from an arbitrary position as a training sample under each operating pressure. The fixed length value is taken as k · 2 n ,where k, n are positive integers [29]. Randomly create samples, which can enlarge dataset and enhance generalization of CNN model. Create CNN architecture: it contains determining the input and output layer, the depth of network, the size of the kernels, the number of feature maps, the size of the filter of pooling layer, and the activation function for each layer.
CNN performs well in a variety of visual recognition tasks, especially in the field of image classification [30]. In order to make full use of the virtue of CNN in image recognition, the input layer is 2D matrix converted by 1D sequence. The task of CNN is to output an internal leakage value, so the output layer has a node. Increasing the depth of CNN can improve the model performance, but CNN will be overfitting with depth too deep. Reference [31] studied how the size of kernel, the number of feature maps, and the filter size of the pooling layer affect CNN. The results show that the recognition accuracy increases with the decrease of the size of kernel, increases first and then maintains stability with the increase of the number of feature maps, and increases with the decrease of filter size of pooling layer. However, the smaller the kernel and the filter of the pooling layer are, and the more the number of feature maps, the more complex the CNN model is, which increases the difficulty of training a network. Therefore, size and numbers are determined by actual situation. The activation function is divided into linearity and nonlinearities, the former is used for the output layer of network with the task of regression, and the latter includes saturating nonlinearities tanh(x) or sigmoid(x), and non-saturating nonlinearity Relu(x). In terms of training time, saturating nonlinearities are much slower than the non-saturating nonlinearity [32]. So the hidden layer of deep neural networks generally uses activation function Relu.
Training a network: it aims to optimize the loss function. Typical loss function contains mean squared loss applied to regression to continuous values, cross entropy loss used for multi-class classification [27], and hinge loss [33] usually applied to large-margin classification. Commonly used for optimizing is gradient descent algorithm with the downsides of slow converge, falling into local minimum or saddle. Optimization algorithms, such as momentum gradient descent algorithm [34], RMSprop algorithm [35], Adam algorithm [36], have appeared. The Adam algorithm combining the momentum gradient descent algorithm and the RMSprop algorithm has the fastest convergence rate. After determining the loss function and the optimization algorithm, set the number of iterations or the error threshold, and train the CNN with training data.
Predict leakage in hydraulic cylinder: The internal leakage can be output by inputting the strain data to be predicted into the trained CNN.

Materials and Methods
Firstly, create dataset and feature extraction to obtain input data for CNN, BPNN, RBF, and SVR. Secondly, determine the parameters and architecture of CNN according to Section 4. Then, determine the architecture of BPNN according to CNN architecture. Finally, introduce RBF and SVR for regression problem on leakage prediction.

Create Dataset
The sampling frequency of the strain data is 1 kHz, so there are plenty of strain values under each pressure. If they are input to the CNN, training will be much harder. Between the pressure of 0 to 15 MPa, take 4096 continuous strain values at an arbitrary position as one sample, as shown in Figure 11. According to Figure 11, there are 160 samples with 20 samples for each operating pressure and each sample set a label which is an internal leakage corresponding to the strain. The created data set is denoted as , where x i denotes ith sample, y i denotes the label of ith sample, n denotes the number of samples. The samples under each operating pressure are randomly divided into training data and test data by a rate of 4:1. To eliminate the magnitude difference between different data, the data must be normalized. Data normalization can avoid the network prediction errors that are too large due to excessive differences in the magnitude of the input data, which contains min-max normalization and zero-mean normalization. The latter can convert the distribution of the inputs to a standard normal distribution with a mean of 0 and a variance of 1. It can be defined as: wherex is the average value of n input data and x std the standard deviation of n input data,ȳ is the average of n output value, y std is the standard deviation of n output value. The data {x i } n i=1 after normalized is used as input data of BPNN. After data normalization, the 1-D time-series strain data with length 4096 is stacked row by row to form a 2-D input matrix of size 64 × 64. The 2-D matrices, which constructs the temporal information and spatial information, are used as the input data of CNN. The process of conversion from 1-D time-series data to 2-D data [37] is shown in Figure 12.

Feature Extraction
Each sample x i is a signal sequence in time domain, denoted as x t , t = 1, 2, 3, T, and T is the length of time domain signals. The mean, root mean square, skewness, kurtosis, pulse factor, crest factor, waveform factor, and margin factor are selected as the features of time domain signal sequence, as shown in Table 1. The data after manual feature extraction is used as input data of RBF, SVR.

Features
Formulation

Parameters and Architecture of CNN
According to Section 4, the kernel size of convolution layer is 3 × 3, the filter size of max pooling is 2 × 2, the activation function of the convolutional layer is Relu, and the output layer is an unit, using a linear activation function. The CNN architecture is shown in Figure 13 and the specific parameters of CNN are shown in Table 2.

BPNN Architecture
In order to ensure the rationality of comparison on BPNN and CNN, the BPNN structure is 4096-8192-4096-2048-1 which is approximately equivalent to CNN structure. There are 75,542,529 parameters to be trainable in the BPNN and 8049 parameters in the CNN.

Other Models for Regression about Leakage Prediction
We formulated the dataset extracted according to Table 1 , which x i is the ith input feature vector, y i is the ith output value. In this paper, x i ∈ R d , d = 8, contains 8 features and x i ∈ R 1 , denotes the leakage value for ith feature vector.

Support Vector Regression
The process of internal leakage prediction based on SVR contains the map of the feature vector x j to be predicted to a high-dimensional space, and then predict the leakage according to the following formula: Firstly, w and b are obtained by solving the following optimization problem [38]: where C > 0, ε > 0, they are given parameters, w is a vector in high dimension, Φ x i maps the d-dimension vector x i to higher dimension vector. Then, solve the dual problem of above optimization problem and obtain the prediction leakage as follows [39]: where K x i , x j is the kernel function, calculating the inner product of Φ x i and Φ x j . Gaussian kernel is commonly used, which is expressed as: where γ is kernel parameter.

RBF Network for Regression
RBF network consists of three layers: input layer, hidden layer and output layer. The node of hidden layer is the distance of input feature vector and center vector with radial basis function. The output layer has one node with linear activation function. Its structure is shown in Figure 14. The RBF network can be applied on leakage prediction, which contains three steps as follows: Step 1: determine the center vectors µ i , i = 1, 2, . . . , m. Center vectors can be randomly selected from all the input feature vectors. In this paper, we use the K-means algorithm to select center vectors.
Step 2: train the RBF network with training data to obtain parameter w i , i = 1, 2, ..., m.
Step 3: for the input feature x to be predicted, the prediction leakage Q can be calculated as: The models mentioned above were run on a Lenovo with a Intel Core i5-3230M CPU and 8 GB memory based on the Keras and scikit-learn library in Python.

The Metric of Model Performance
In this paper, Root Mean Square Error (RMSE), Relative Absolute Error (RAE), and R square are used to evaluate the model performance. The three metrics can be formulated as follows: where, f x i denotes the predicted leakage value, y i denotes the actual leakage value,ȳ is the mean of actual leakage value. The smaller the value of RMSE and RAE, the better the performance. The range of R square values is 0 to 1, and the closer to 1, the better the model performance.

Comparison and Discussion
The compare results of the RMSE, RAE, and R square of four models and training time and testing time between CNN and BPNN are listed in Table 3. Figure 15 shows the prediction leakage of four models. Comparing Table 3 and Figure 15, it can be obviously seen that the CNN has great advantages. In terms of accuracy of leakage prediction, the R square of CNN is equal to 1 and the ones of BPNN, RBF, and SVR are 0.9624, 0.9852, and 0.9528, respectively, and the curves of measured leakage and predicted leakage based on CNN almost coincide, which indicates the CNN model performs best in leakage prediction. For the RMSE and RAE, the CNN is much less than the other three models. In terms of speed of training and prediction, the CNN is about 2 times that of BPNN on training speed and 5.63% faster than BPNN on prediction speed with 32 samples. The weights of BP neural network are about 10,000 times that of CNN, which increases the time cost of training and prediction.
When training, CNN and BPNN used the same data, optimization algorithm, learning rate, batch size, and epochs. The concrete parameters above are shown in Table 4. The raw data after manual feature extraction are used to train RBF, with hidden nodes being 16, γ being 1, and SVR with Kernel function being Gaussian kernel, kernel parameter γ being 3, the penalty factor C = 1.0, and the permissible error ε = 0.1.
As can be seen from above, the CNN model without any feature extraction or signal preprocessing performs much better than the other three models on leakage prediction. So the CNN is selected as the main component of the internal leakage prediction module, and it can well reflect the relationship between the deformation amount of the strain gauge and the leakage amount in the hydraulic cylinder.

Conclusions
This paper studies the online measurement of hydraulic cylinder leakage based on CNN: (1) A method for online measurement of leakage in hydraulic cylinder is proposed, which uses a strain gauge as a core sensor to convert flow signals into strain signals and takes the CNN as the internal leakage prediction module to output the internal leakage in real time. (2) Established a mathematical model for flow-strain signal conversion. Reducing the fixed area of the strain gauge and the end face of the piston and appropriately increasing the depth of the oil collecting tank can enhance the strain signal.
In the leakage prediction of hydraulic cylinder, CNN automatically extracts the features, avoiding the complexity brought by manually extracting features, saving time and enhancing the model performance. (4) This study can be applied to measure the small flow of other hydraulic components and related equipment online.

Conflicts of Interest:
The authors declare no conflict of interest.