**11. Computer Implementation and Comparison of TGMS Measurement with Reference Irregularity**

The methods and algorithms described in this paper have been implemented in Matlab environment. However, only built in functions of the basic package have been used, avoiding the use of functions, for example, of the computer vision toolbox. The program that produces the track irregularity out of the sensor data includes the following modules:


The results of this program are now compared with the reference value of the irregularities that were obtained with the method described in the previous section. Figures 16–19 show the comparison between the reference geometry measurement explained in the previous section and the measurement of the TGMS developed in this investigation. The experiment was done with the vehicle shown in Figure 14 at a forward velocity of 2.5 m/s, that, considering the scale, it is equivalent to 25 m/s = 90 km/h of a real train. This is approximately the maximum forward velocity of metropolitan trains. The figures show the irregularities in the first 56 m of the track. The complete length of the scale track could not be measured because the vehicle had difficulties to negotiate the 12 m-radius curve at that forward velocity. The irregularities shown in the figures are high-pass filtered with a cut-off wave length of 3 m (wavelengths above 3 m are filtered out). It is a common practice in the geometry measurement of metropolitan trains to measure just wave lengths below 30 m, what is equivalent to 3 m in our scaled track.

The cross-level shown in Figure 16 shows a good agreement between the reference geometry and the measure of the TGMS. The agreement in gauge variation shown in Figure 17 is even better. Both curves are almost identical. However, in both figures, some edge effect is observed at the beginning of the measurement.

**Figure 16.** Measurements of cross level.

**Figure 17.** Measurements of gauge variation.

The absolute irregularities are compared in Figures 18 and 19. As it can be observed, the agreement is fine, but not as good as the agreement of the relative track irregularities. The reason is clearly the influence in the results of the approximations and noise associated with the calculation of the TGMS to TF relative trajectory explained in Section 9. Recall that this relative trajectory is not needed for the calculation of the relative irregularities. It can also be observed that the measurements of the designed TGMS shows higher spatialfrequencies than the measurement with the total station. However, these higher frequencies must not be considered as noise, because the measuring method used with the total station can not detect high-frequency (short wavelength) irregularities.

**Figure 18.** Measurements of alignment.

**Figure 19.** Measurements of vertical profile.

#### **12. Summary and Conclusions**

This paper explains the numeric algorithms used to calculate track geometry irregularities with a new TGMS. These algorithms are basically kinematic relationships that describe the motion of a body moving along a track. After the description of the system and the sensors needed, the multibody-based kinematics is described in detail as well as the approximations used due to the small angles assumption. In this kinematic description, the track geometry (design geometry plus irregularities) is assumed totally arbitrary. As a result that the TGMS uses a computer vision system, the kinematic equations needed to locate the recorded rail cross-sections in the TGMS frame have been deduced, as well as a method to find the relative coordinates of the rail cross-sections with respect to the TGMS frame.

Section 6 shows the equations that can be used to find the value of the four independent track irregularities: gauge and cross-level in Equation (24), and alignment and vertical profile in Equation (27), as a function of the output of the computer vision system (explained in Section 5), the relative TGMS to TF relative orientation and the relative TGMS to TF relative trajectory. However, there is a long way to go to apply these equations.

Section 7 explains the development of a linear dynamic model that can be used to find the TGMS to TF relative orientation using the installed inertial sensors, 3D accelerometer and 3D gyroscope. This model is the basis of a Kalman filter that provides as the output the required TGMS angles. The application of this algorithm requires a precise knowledge of the position of the TGMS along the track. This position together with the vehicle forward velocity are needed to calculate the accelerations due to the motion of the TGMS along the design geometry of the track. In turn, these accelerations are needed to calculate the relative orientation based on the accelerometer signals. Section 8 explains the odometry algorithm that is used in this investigation for the precise calculation of the value of the arc-length *s* of the TGMS along the track. This algorithm is based on the measurement of the track horizontal curvature and the knowledge of the track design geometry.

The most difficult step for the calculation of the track irregularities is to obtain the TGMS to TF relative trajectory. Fortunately, this trajectory is needed to find the absolute irregularities but not needed to find the relative irregularities. The calculation of the relative trajectory is explained in Section 9. After a set of approximations, Equation (46) shows a second-order linear system of ordinary differential equations that can be solved to find the TGMS to TF relative trajectory. However, these equations are intrinsically unstable, requiring special solution methods that need to be improved, as it can be deduced from the experimental results.

The calculation of the track irregularities has been experimentally validated in a scale track that is described in Section 10 as well as the alternative method used to measure the track irregularities. This alternative method is accurate and based on the sensors used in the commercial rail track trolleys, LVDT and inclinometer, and a total station. The comparison of the measurements of the TGMS presented in this paper and this reference measurement is shown in Section 11. The relative irregularities are measured with high accuracy. The measurement of the absolute irregularities can be considered as acceptable, but the accuracy is much less. It can be concluded that the method of calculation of the TGMS to TF relative trajectory, that is the additional input needed for the calculation of the absolute irregularities, needs to be improved.

**Author Contributions:** Conceptualization and algorithm implementation, J.L.E.; Investigation, J.L.E., P.U. and S.M.; Design of the experiments, J.L.E., P.U. and S.M.; Instrumentation of the vehicle and data acquisition, P.U.; Experimentation, P.U. and S.M.; Writing, J.L.E.; Supervision, J.L.E. All authors have read and agreed to the published version of the manuscript.

**Funding:** This research was supported by the *Conserjería de Economía, Conocimiento, Empresas y Universidad de la Junta de Andalucía* under the project reference US-1257665. This support is gratefully acknowledged.

**Data Availability Statement:** The data presented in this study are available on request from the corresponding author.

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