Cam Mechanisms Reverse Engineering Based on Evolutionary Algorithms

: Cam follower mechanisms are widely used in automated manufacturing machinery to transform a rotary stationary motion into a more general required movement. Reverse engineering of cams has been studied, and some solutions based on different approaches have been identiﬁed in the literature. This article proposes an innovative method based on the use of an evolutionary algorithm for the identiﬁcation of a law of motion that allows for approximating in the best way the motion or the sampled proﬁle on the physical device. Starting from the acquired data, through a genetic algorithm, a representation of the movement (and therefore of the cam proﬁle) is identiﬁed based on a type of motion law traditionally used for this purpose, i.e., the modiﬁed trapezoidal (better known as modiﬁed seven segments). With this method it is possible to estimate the coefﬁcients of the parametric motion law, thus allowing the designer to further manipulate them according to the usual motion planning techniques. In a ﬁrst phase, a study of the method based on simulations is carried out, considering sets of simulated experimental measures, obtained starting from different laws of motion, and verifying whether the developed genetic algorithm allows for identifying the original law or approximating one. For the computation of the objective function, the Euclidean norm and the Dynamic Time Warping (DTW) algorithm are compared. The performed analysis establishes in which situations each of them is more appropriate. Implementation of the method on experimental data validates its effectiveness.


Introduction
Cam follower mechanisms are the classical mechanical solution to transform, with a high level of precision, a rotary stationary motion into a translating or oscillating or indexing movement. More in general, they transform the cam's motion in a prescribed movement of the follower [1,2]. Although cam devices allow for rigid automation, compared to modern flexible electronic cams, they have some advantages that make them the optimal solution in a wide spectrum of engineering applications. Textile machines, automobile engines, transfer machines, printing presses and bottling machinery are just some examples of systems where cam follower mechanisms are widely adopted. The main characteristics of engineering cam-based solutions, in addition to the aforementioned precision, are simplicity, compactness and high velocities.
Several research topics deal with cam's devices, and many publications treat the design optimization. Flores [3] presents a general and comprehensive procedure for an optimal geometric parameters identification for a cam with translating roller follower, obtaining a constrained optimization multivariate problem, solved with non-linear programming algorithms. Meta-heuristics algorithms are widely used for the solution of the problem arising from the cam design [4,5], and among them the evolution-based category is the most investigated one for this problem. Genetic algorithms (GA) have been used, for example, by Lampinen [6] for cam shape design automation and optimization, or by Tsiafis et al. [7] for the identification of the optimal values for the design parameters, like the cam base circle radius, the follower offset and the face width. The automatic cam profile synthesis is also a constrained non-linear optimization problem for which many solutions based on GA have been proposed: in 2017 [8], a multi-objective GA was developed by Jana and Bhattacharjee, and applied to cam mechanisms with simple and double harmonic profiles; Hamza et al. in 2018 [9] used a modified adaptive differential evolution (MADE) algorithm for the optimal design of a cam mechanism with offset translating roller follower. The dynamic behavior of high-velocity cams is another important issue, and the cam synthesis plays a very significant role on follower vibratory phenomena. Dynamic modelling and optimization procedures are used to synthesize cam curves to improve the dynamic behavior: in 2020 [10], Yu et al. applied GA to find the optimal solution in a constraint optimization problem based on a single degree of the freedom dynamic model; in 2017, an optimization of the cam profile based on mathematical modelling was applied to an offset press by Ouyang et al. [11]. The follower vibrations control is another main research issue in the field of cam mechanisms [12][13][14][15], and it is normally combined with the condition monitoring of these systems [16][17][18].
In the last decades, computer-aided design (CAD) has become widely consolidated, favored by increasingly higher velocities and computing powers and by the integration of different tools in the same design environment. A need that often arises in industrial practice is to reconstruct or to model a part of a system starting from an already existing physical object, in order to update or improve the design of an existing component. Reverse engineering (RE), which dates back to the 1980s, is the solution for such a problem. RE methods aim at the reconstruction of CAD models from measured data [19] and are applied in different fields including medicine [20], dentistry [21] and mechanical engineering [22].
Reverse engineering applied to cam mechanisms has been investigated by many scholars: Li in 2011 [23] presented the reverse design of a spatial cam based on the measurements achieved through a coordinate measuring machine (CMM) and the mathematical reconstruction of the cam's surface; Zhenghao et al. in 2011 [24] proposed an iterative process consisting of fitting the cam profile using the non-uniform rational basis-splines (NURBS) curves, starting from the measured points, then making a further kinematic analysis and a possible correction of the profile, to obtain a cam profile that is smooth but that still satisfies the boundary conditions in terms of displacement, velocity and acceleration of the follower; Alsoufi et al. [25] presented a cam RE converting the scanned data using coordinate-measuring machine (CMM) technology into a 3D model of the disc CAM and investigated the obtained results in terms of the height variation, dimensional accuracy and surface roughness as well as skewness and kurtosis performance with cams of different materials (including aluminum, hardened steel, stainless steel, PLA+, PLA, ABS+ and photo-polymer resin).
This paper proposes an innovative reverse engineering method for a cam mechanism, based on the identification of a law of motion that better approximates the one generated by the device, having acquired the cam profile through a CMM machine or having measured the follower movement. With this method, the coefficients of a parametric motion law can be estimated, thus allowing the designer to further manipulate them according to the usual motion planning techniques. The coefficients values are identified with an optimization process, by setting a first series of values a priori and by correcting them through the minimization of the error between the acquired data and the resulting curve. The minimization is implemented with an evolutionary algorithm (a genetic algorithm) capable of properly probing the solutions space. However, it is important to adequately define a quantity that represents the abovementioned error, since this quantity can make the effectiveness or the convergence of the method critical. In the current work, two methods were used to quantify the difference between the two curves for comparison purposes: the classical Euclidean norm (which measures the curves distance) and the Dynamic Time Warping (DTW) algorithm, capable of capturing and assessing the similarity between two trends. The innovative aspects, with respect to the literature, concern the development of a method whose purpose is to identify the law of motion, instead of directly reconstructing the profile of the cam from the acquired points. The use of evolutionary algorithms within a RE techniques represents a further innovative aspect of the developed research. The law of motion and cam profile are strictly connected. The follower law of motion and stroke are usually selected in accordance with the technological process and are set as the design initial data. The synthesis of the cam, which consists of sizing the cam and of finding the CNC center tool coordinates to profile the cam, follows. The cam sizing is greatly influenced by the law of motion choices, e.g., the maximum velocity influences the dimensioning of the cam's base radius. The choices for the cam manufacturing, such as the material, the production technology, the tolerances chosen in the design phase and the accuracy of the CNC machinery, can instead influence the follower law of motion. Samsonenko in 2020 in [26] researched the influence of errors of cam manufacturing on the law of motion of the output element and concluded that slight deviations of the cam shape from the ideal can lead to significant deviations of the movement's law of the follower. Therefore, a correct choice of the manufacturing method of the cam and of its tolerances is fundamental for the effectiveness of the proposed method.
The paper is organized as follows: Section 2 describes the main concepts related to motion planning and the formulation of a modified trapezoidal motion law in the most general case, the genetic algorithm, the objective function used and the structure of the developed method. Section 3 reports the application of the procedure in some fictitious illustrative cases at the beginning, where the method is tested on data generated by simulation, and afterwards describes the application to a real case. The results are then analyzed in Section 4, and Section 5 summarizes the salient results of the work and the future developments.

Laws of Motion and Motion Planning
The movement of a cam follower (or, more generally, of a machine element) is identified by the trajectory (Figure 1a) and by the law of motion (Figure 1b), which defines how the trajectory is followed with respect to the time.
Electronics 2021, 10, x FOR PEER REVIEW 3 o ods were used to quantify the difference between the two curves for comparison p poses: the classical Euclidean norm (which measures the curves distance) and the D namic Time Warping (DTW) algorithm, capable of capturing and assessing the similar between two trends. The innovative aspects, with respect to the literature, concern the development o method whose purpose is to identify the law of motion, instead of directly reconstruct the profile of the cam from the acquired points. The use of evolutionary algorithms wit a RE techniques represents a further innovative aspect of the developed research. The l of motion and cam profile are strictly connected. The follower law of motion and stro are usually selected in accordance with the technological process and are set as the des initial data. The synthesis of the cam, which consists of sizing the cam and of finding CNC center tool coordinates to profile the cam, follows. The cam sizing is greatly inf enced by the law of motion choices, e.g., the maximum velocity influences the dimensi ing of the cam's base radius. The choices for the cam manufacturing, such as the mater the production technology, the tolerances chosen in the design phase and the accuracy the CNC machinery, can instead influence the follower law of motion. Samsonenko 2020 in [26] researched the influence of errors of cam manufacturing on the law of mot of the output element and concluded that slight deviations of the cam shape from the id can lead to significant deviations of the movement's law of the follower. Therefore, a c rect choice of the manufacturing method of the cam and of its tolerances is fundamen for the effectiveness of the proposed method.
The paper is organized as follows: Section 2 describes the main concepts related motion planning and the formulation of a modified trapezoidal motion law in the m general case, the genetic algorithm, the objective function used and the structure of developed method. Section 3 reports the application of the procedure in some fictitio illustrative cases at the beginning, where the method is tested on data generated by si ulation, and afterwards describes the application to a real case. The results are then a lyzed in Section 4, and Section 5 summarizes the salient results of the work and the fut developments.

Laws of Motion and Motion Planning
The movement of a cam follower (or, more generally, of a machine element) is id tified by the trajectory (Figure 1a) and by the law of motion (Figure 1b), which defi how the trajectory is followed with respect to the time. Often, a law of motion is constituted by a succession of sections characterized by d placement, Δs, and related temporal duration, Δt. Therefore, in the study, we can focus a single trait and the same considerations can be extended to the others as well. In addit to duration and displacement, the law of motion sometimes respects further constrain Often, a law of motion is constituted by a succession of sections characterized by displacement, ∆s, and related temporal duration, ∆t. Therefore, in the study, we can focus on a single trait and the same considerations can be extended to the others as well. In addition to duration and displacement, the law of motion sometimes respects further constraints, such as the values of velocity or the successive derivatives to the extremes of the interval or the imposed passage for a specific point at a given instant. Some motion laws have a flexibility that makes this possible, unlike others, which are rigid and do not allow for solving these kinds of problems. For now, let us consider the case in which the motion law segment has null values at the extremes for all the quantities except for the displacement; this represents a very common case in the definition of the requirements of a cam mechanism.
Referring to the first two intervals of the law of motion in Figure 1, the quantities t A , s A , t B and s B (or similarly t A , s A , ∆t and ∆s) are constraints, whereas the definition of the curve shape is based on a set of characteristic coefficients that depend on the motion law type. The displacement is a function of the time, of the parameters of the law of motion (c = [c 0 , c 1 ,..., c i ]) and of the constraints. According to the classical law of motion definition, the c i coefficients are adimensional values. If we denote λ as the vector of constraints, which is assigned, in the most general case the displacement function can be expressed according to Equation (1).
Some of the coefficients c are determined by imposing the constraints defined by λ, whereas others can be chosen within a certain margin to further characterize the curve. A separation is not introduced between these two subgroups because often the coefficients are dependent on each other as a whole. For example, considering a polynomial law of motion, as in Equation (2), it is possible to choose the degree n of the polynomial, in order to both satisfy a certain number of constraints at the extremes of the interval, and introduce further parameters that allow for manipulating the shape of the curve (for example by imposing a certain velocity or acceleration value, or jerk in a generic instant).
In this case, denoting the velocity with v, we could impose the following four constraints: Then, we can define λ = {t A , s A , v A , t B , s B , v B }. Given four constraints, the minimum value of n to satisfy them is three, and consequently, four coefficients are required. If the coefficients' number is equal to the constraints' number, the equations for calculating the coefficients derive from the imposition of the constraints. However, it is also possible to choose a degree n of the polynomial redundant with respect to the constraints, and to use the additional degrees of freedom to manipulate the shape of the curve. For example, in this case we could choose n equal to six, obtaining a vector c made up of six elements, that is, in general, a number greater than the number of constraints. Returning to the more general case of a law of motion, even not a polynomial, the main difficulty consists in determining the value of the coefficients c i , which are sometimes not determinable in closed form. In these cases, for the computation of the coefficients, it is reasonable to use numerical methods based on iterative algorithms, which are able to offer approximate solutions for the additional degrees of freedom in compliance with all other constraints.
Without treating the formulation of the different types of motion law, for which reference is made to the literature [1], here the case of trapezoidal modified seven traits motion laws is especially depicted as an illustrative application. The modified trapezoidal laws are particularly manageable, suitable for the purposes of the presented work and very widespread in the industrial field. These motion laws fall within the more general class of the piecewise motion laws, which consist of the succession of different parts, each defined by a specific mathematical function. In detail, the modified trapezoidal laws are defined by assigning the shape of the acceleration diagram consisting of an alternation of seven sinusoidal and constant strokes. With reference to Figure 2, the total duration ∆t = t B − t A , in which the displacement ∆s = s B − s A occurs, is divided into seven sections whose single duration is identified by the vector of coefficients c = {c 0 , c 1 , . . . , c 6 }. In addition to displacement, non-zero values of both velocity and acceleration can be imposed on the extremes of the law of motion, indicated in the figure by v A , a A , v B and a B . Displacement, velocity and acceleration trend can be consequently determined with a double integration in an analytical form (in parts). The additional parameters A pos , A neg and V max , introduced for convenience, represent the maximum positive and negative acceleration and maximum velocity, respectively. Therefore, in the general case, which is characterized by a duration and a displacement compatible with the velocity and acceleration values assigned to the extremes, the profile can be defined in all its parts thanks to the imposition of the constraints (Equation (4)).
mum velocity, respectively. Therefore, in the general case, which is characterized by a duration and a displacement compatible with the velocity and acceleration values assigned to the extremes, the profile can be defined in all its parts thanks to the imposition of the constraints (Equation (4)). At a computational level, it is convenient to first calculate the vectors of cumulative partial displacements sc and cumulative partial velocities vc at the end of each section, introducing some useful quantities, called a11, a22, a12, a22, b1 and b2, and defined as shown in the formulas in Table A1. For the ith segment, let us define a function ti(t), which expresses the instant of start, as shown in Equation (5). It is possible to define the analytic expression of displacement, velocity and acceleration at time t (s(t), v(t) and a(t), respectively, obtaining the formulation shown in Table A2, in which the symbol ti is used in place of ti(t), omitting the time instant t, for compactness reasons, and where tci indicates the instant of time at the beginning of the i th section (Equation (6)).
As previously stated, this class of motion law is very flexible, since it allows for guaranteeing the constraints λ = {tA, sA, vA, aA, tB, sB, vB, aB} at the extremes on displacement as well as on velocity and acceleration, but also allows for further manipulations of its shape in order to achieve secondary objectives. At a computational level, it is convenient to first calculate the vectors of cumulative partial displacements s c and cumulative partial velocities v c at the end of each section, introducing some useful quantities, called a 11 , a 22 , a 12 , a 22 , b 1 and b 2 , and defined as shown in the formulas in Table A1.
For the ith segment, let us define a function t i (t), which expresses the instant of start, as shown in Equation (5). It is possible to define the analytic expression of displacement, velocity and acceleration at time t (s(t), v(t) and a(t), respectively, obtaining the formulation shown in Table A2, in which the symbol t i is used in place of t i (t), omitting the time instant t, for compactness reasons, and where t ci indicates the instant of time at the beginning of the i th section (Equation (6)).
As previously stated, this class of motion law is very flexible, since it allows for guaranteeing the constraints λ = {t A , s A , v A , a A , t B , s B , v B , a B } at the extremes on displacement as well as on velocity and acceleration, but also allows for further manipulations of its shape in order to achieve secondary objectives.
As an example, Figure 3 shows the comparison of two laws of motion consisting of three movements, in which the dashed modified trapezoidal of the central movement was obtained from the continuous curve by slightly modifying the values of the coefficients c 4 , c 5 and c 6 of the vector c. Often, the coefficients c are in a normalized form with respect to the total motion duration ∆t, to make comparisons independent of the cycle time.
As an example, Figure 3 shows the comparison of two laws of motion consisting of three movements, in which the dashed modified trapezoidal of the central movement was obtained from the continuous curve by slightly modifying the values of the coefficients c4, c5 and c6 of the vector c. Often, the coefficients c are in a normalized form with respect to the total motion duration Δt, to make comparisons independent of the cycle time.

Problem Definition and Genetic Algorithm Implementation
Referring to the laws of motion described in the previous paragraph, the proposed cams reverse engineering method consists of an optimization problem for which the objective function is the distance between two curves. The first curve is obtained starting from the CMM measurements of the profile or direct measurement of the follower's motion; the other one is generated as a sampling of the modified trapezoidal motion law, obtained with the particular vector of seven coefficients c, which defines the potential solution. Denoting the set of law of motion parameters to be identified with c = {x1, x2, …, xn} and the objective function with F = F(c), the problem consists in the minimization of F, therefore determining the particular set of values c*, such that F(c*) = min F(c). Due to the characteristics of this problem, a genetic algorithm represents a valid solution technique.
Genetic algorithms [27] belong to the family of evolutionary algorithms, which adopt the mechanisms of natural selection to solve optimization problems. The use of genetic algorithms is the most suitable method for problems with a large number of parameters or when the function to be optimized is not sufficiently regular or has a domain consisting of several parts that are not connected to each other. In a nutshell, a genetic algorithm, starting from a first set of solutions that are usually randomly generated, carries out the recombination of groups (generations) of solutions (individuals), each consisting of specific characters (variables of the optimization problem).
Each new solution is obtained by recombining, by means of genetic operators, the characters of two solutions selected from the previous group. Selection favors the choice of solutions that best minimize the objective function, so that the properties of the best solutions of a group can propagate in subsequent groups. In addition to the traditional genetic operators (selection, cross-over, mutation, inversion), the algorithm developed in this work uses a further operator, which involves a mutation of the coefficients that is not random, but is bound to a neighborhood of their previous value, thus enabling it to better explore a specific area. As the procedure evolves, the amplitude of this area is narrowed so as to refine the solution in an area that is already optimal in itself. The operators are not always applied, but each one presents a certain probability of occurrence. To ensure the

Problem Definition and Genetic Algorithm Implementation
Referring to the laws of motion described in the previous paragraph, the proposed cams reverse engineering method consists of an optimization problem for which the objective function is the distance between two curves. The first curve is obtained starting from the CMM measurements of the profile or direct measurement of the follower's motion; the other one is generated as a sampling of the modified trapezoidal motion law, obtained with the particular vector of seven coefficients c, which defines the potential solution. Denoting the set of law of motion parameters to be identified with c = {x 1 , x 2 , . . . , x n } and the objective function with F = F(c), the problem consists in the minimization of F, therefore determining the particular set of values c*, such that F(c*) = min F(c). Due to the characteristics of this problem, a genetic algorithm represents a valid solution technique.
Genetic algorithms [27] belong to the family of evolutionary algorithms, which adopt the mechanisms of natural selection to solve optimization problems. The use of genetic algorithms is the most suitable method for problems with a large number of parameters or when the function to be optimized is not sufficiently regular or has a domain consisting of several parts that are not connected to each other. In a nutshell, a genetic algorithm, starting from a first set of solutions that are usually randomly generated, carries out the recombination of groups (generations) of solutions (individuals), each consisting of specific characters (variables of the optimization problem).
Each new solution is obtained by recombining, by means of genetic operators, the characters of two solutions selected from the previous group. Selection favors the choice of solutions that best minimize the objective function, so that the properties of the best solutions of a group can propagate in subsequent groups. In addition to the traditional genetic operators (selection, cross-over, mutation, inversion), the algorithm developed in this work uses a further operator, which involves a mutation of the coefficients that is not random, but is bound to a neighborhood of their previous value, thus enabling it to better explore a specific area. As the procedure evolves, the amplitude of this area is narrowed so as to refine the solution in an area that is already optimal in itself. The operators are not always applied, but each one presents a certain probability of occurrence. To ensure the convergence of the method, it was decided to reintroduce in each new generation the best individual obtained in the previous one, thus adopting an elitist algorithm.
As for many optimization algorithms, genetics have intrinsic parameters that affect their effectiveness, such as the number of individuals and the probability of application of the different operators. The chosen parameter values are reported in Section 3.

Objective Function
The objective function is an indicator of how much close the identified law of motion and the original one are and could be calculated considering either the position or the velocity or the acceleration. The comparison based on the displacement has an important negative aspect: even large variations of the law of motion, for example in terms of accelerations, are very slightly perceived at displacement level. To overcome this drawback, comparing the curves as time derivatives, therefore at the velocity or acceleration level rather than as displacements, is more effective. In the case of the modified trapezoidal, a further advantage emerges when considering the acceleration, since the law of motion is defined starting exactly from the acceleration diagram itself.
To measure the dissimilarity between two curves, the most commonly used method is the Euclidean norm (EN), i.e., the distance (Equation (7)) between the vectors representing the curves. If we denotex and x as these vectors, the EN is evaluated as follows: Besides, the EN is not always the ideal tool for measuring the distance between the curves for the problem under consideration.
Indeed, the acquired data are frequently subjected to noise and, sometimes, disturbances (due to a surface damage, for example), which are amplified in the derivation of the signal and can affect the results. This usually makes the comparison between the analytic law of motion and the experimental one critical, and even more so if an evolutionary algorithm is used. As an example, Figure 4 shows the acquired displacement (red curve), of the follower movement of a rocker arm cam, damaged near the point with abscissa 270 • , and the computed velocity (green curve) and acceleration (blue curve) signals. The data reveal a peak in the acceleration that could greatly affect the Euclidean norm.   As alternative method for measuring the similarity between the curves, the Dynamic Time Warping (hereinafter DTW) algorithm [28][29][30] was considered, which in some situations may be more effective than the Euclidean norm. With this technique, each point of a curve is compared with some points of the other curve in order to have a more reliable measurement of similarity. Let us consider curves 1 and 2 of Figure 5: with Euclidean distance, each point of curve 1 is compared with the corresponding point of curve 2 (Figure 5a), whereas the DTW algorithm compares different points between the two curves ( Figure 5b). The adoption of the DTW technique allows for an optimization that tends to avoid falling and remaining in relative minimums. Obviously, the use of a complex algorithm for calculating the distance between the curves penalizes the computation time, but, on the other hand, it allows the algorithm to converge faster. As a demonstration of this, Figure 6 shows the trend of the objective function, over the generations of the genetic algorithm, in the case of the Euclidean norm (red curve) and with the DTW algorithm (green curve), for an optimization in 500 generations with 100 individuals, and with a distance calculation on 500 samples. In Figure 6, no values are reported on the ordinate axis because the DTW algorithm and Euclidean norm are not directly comparable, but the profiles' trends emphasize that DTW allows for faster convergence. In terms of computation time over 500 generations, the Euclidean norm requires about 4 ms whereas DTW algorithm requires about 6 ms; however, as the figure depicts, DTW has a higher convergence rate. With the DTW algorithm, the goal can be considered achieved at about 150 generations, with a noticeable reduction in convergence time (about 1.8 ms).

Developed Cam Mechanisms RE Framework
The RE framework generally adopted and commonly referred to in the literature [31][32][33] is based on the following six main phases: data capture, pre-processing, segmentation, feature classification, surfaces fitting and CAD model reconstruction. Several methodologies are available for each one of these phases and an in-depth analysis of these techniques is discussed in [19]. This approach can also be applied to realize the RE of a cam, as done in [25], which presents the process of reversed disc CAM from an existing one. Alsoufi red: displacement). The law of motion is defined as a function of the rotation angle of the cam, and the displacem referring to the red vertical axis is a rotation of the follower in degrees. In Figure 6, no values are reported on the ordinate axis because the DTW alg and Euclidean norm are not directly comparable, but the profiles' trends emphas DTW allows for faster convergence. In terms of computation time over 500 gene the Euclidean norm requires about 4 ms whereas DTW algorithm requires abou however, as the figure depicts, DTW has a higher convergence rate. With the DTW rithm, the goal can be considered achieved at about 150 generations, with a no reduction in convergence time (about 1.8 ms).

Developed Cam Mechanisms RE Framework
The RE framework generally adopted and commonly referred to in the literatu 33] is based on the following six main phases: data capture, pre-processing, segme feature classification, surfaces fitting and CAD model reconstruction. Several meth gies are available for each one of these phases and an in-depth analysis of these tech is discussed in [19]. This approach can also be applied to realize the RE of a cam, in [25], which presents the process of reversed disc CAM from an existing one. In Figure 6, no values are reported on the ordinate axis because the DTW algorithm and Euclidean norm are not directly comparable, but the profiles' trends emphasize that DTW allows for faster convergence. In terms of computation time over 500 generations, the Euclidean norm requires about 4 ms whereas DTW algorithm requires about 6 ms; however, as the figure depicts, DTW has a higher convergence rate. With the DTW algorithm, the goal can be considered achieved at about 150 generations, with a noticeable reduction in convergence time (about 1.8 ms).

Developed Cam Mechanisms RE Framework
The RE framework generally adopted and commonly referred to in the literature [31][32][33] is based on the following six main phases: data capture, pre-processing, segmentation, feature classification, surfaces fitting and CAD model reconstruction. Several methodologies are available for each one of these phases and an in-depth analysis of these techniques is discussed in [19]. This approach can also be applied to realize the RE of a cam, as done in [25], which presents the process of reversed disc CAM from an existing one. Alsoufi focuses on the strategy for converting the scanned data using coordinate measuring machine (CMM) technology in the form of point cloud data into a 3D model of the disc CAM. Different approaches for the RE of cam mechanisms are also present in the literature, which have the aim of tracing the motion law of the follower of the cam mechanism starting from the sampling of the cam profile. In [34], Tsay considers a planar cam and uses a least squares periodic B-splines approximation to interpolate the digitized cam surfaces and to create their derivatives required in determining the follower motion. In [24] and in [35], Zhenghao presented a similar approach, with the improvement of obtaining a smoother Electronics 2021, 10, 3073 9 of 22 cam profile, while still exactly satisfying the boundary condition of follower displacement, velocity and acceleration, and used NURBS curves to fit the profile via the measured data.
The proposed cam's RE differs from the RE classical approach. Although the current approach shares with the latest cited works the purpose of tracing the follower's law of motion, it significantly differs from them in the method. In fact, rather than performing an interpolation of the points of the cam profile, the here proposed identification process focuses on the law of motion that generates a cam's profile as close as possible to the measured one, through the optimization process of an objective function. The main advantage of this approach consists in the fact that it enables exploiting at best the flexibility provided by parametric laws. Indeed, if we use this method and a very flexible parametric law, such as the modified trapezoidal, we have the possibility to control, and within certain limits to intervene on, speed and acceleration trends, with all the advantages that influence the dynamic behavior and the dimensioning of the cam. A GA-based optimization procedure allows for identifying the coefficients of a trapezoidal modified motion law, which best approaches the law of motion of the device to be reengineered, and the objective function is evaluated through the DTW algorithm or the Euclidean norm. The flowchart of this method is shown in Figure 7. and to create their derivatives required in determining the follower motion. In [ [35], Zhenghao presented a similar approach, with the improvement of ob smoother cam profile, while still exactly satisfying the boundary condition o displacement, velocity and acceleration, and used NURBS curves to fit the prof measured data.
The proposed cam's RE differs from the RE classical approach. Although t approach shares with the latest cited works the purpose of tracing the followe motion, it significantly differs from them in the method. In fact, rather than p an interpolation of the points of the cam profile, the here proposed identificatio focuses on the law of motion that generates a cam's profile as close as possi measured one, through the optimization process of an objective function. The vantage of this approach consists in the fact that it enables exploiting at best the provided by parametric laws. Indeed, if we use this method and a very flexible p law, such as the modified trapezoidal, we have the possibility to control, and w tain limits to intervene on, speed and acceleration trends, with all the advan influence the dynamic behavior and the dimensioning of the cam. A GA-based tion procedure allows for identifying the coefficients of a trapezoidal modifie law, which best approaches the law of motion of the device to be reengineere objective function is evaluated through the DTW algorithm or the Euclidean n flowchart of this method is shown in Figure 7. Basically, the idea is to redesign the cam, but respecting the functionality performed by a pre-existing cam, for example, a damaged cam or one of which the original project is not available. The choice of the modified trapezoidal motion law is motivated by the fact that numerous motion laws commonly used in industrial applications can be represented through the mathematical formulation of this law. In the optimization process, it may occur sometimes that some coefficients have a null value, even simultaneously, and this can lead to inconsistencies or calculation errors, such as divisions by zero. Therefore, in the software implementation of the formulas presented in Section 2.1, checking tests are inserted in order to degenerate, if necessary, the seven segments law of motion into a three segments law, or to report a warning of the impossibility of satisfying all conditions. The presented innovative cam mechanism reverse engineering method was implemented in an executable software developed in Delphi 10.4 environment

Simulations
Before testing the method on actual data, simulated data were used for preliminary analysis and validation. Figure 8 shows an example of application of the method to a simulated case. Loaded data were generated through a modified trapezoidal motion law (with non-zero initial and final values for velocity and acceleration), in which a noise with zero mean and unitary amplitude was added to the acceleration (light-blue curve). This law of motion realizes a unitary displacement in a unitary time (1 rad in 1 s, as for all the laws of motion in simulation) and is subjected to the constraints λ and the normalized coefficients c src synthesized in Table 1. These coefficients were chosen randomly, but without null values, so that all the segments are present.

21, 10, x FOR PEER REVIEW 11 of 23
Keeping the intrinsic parameters of the genetic algorithm fixed (Table 2), tests for nine different cases were carried out, related to the different motion laws used to generate simulated input data. In the following sections, we refer to these laws of motion as "original", in the sense that they originated the data that replaced the experimental measurements in simulation. All these motion laws can be represented through the formulas of the modified trapezoidal law; that is, they fall within the class of modified trapezoids. For all the considered cases, a unitary displacement in a unitary time, null constraint vector and 300 extracted sampled points were assumed. The maximum number of generations was set 500, or less in case the algorithm no longer evolves. Table 3 contains the values of the seven coefficients of the considered laws of motion, whereas Table 4 collects the results of the identification in four cases: identification on acceleration, identification on velocity and for each one adopting either the Euclidean norm or DTW algorithm in the objective function calculation.
For one of the previous laws of motion (L7), further tests were made with and without noise, carrying out the identification based on displacement, speed and acceleration. Table 5 shows the final errors on displacement, speed and acceleration calculated with the EN and DTW algorithm.
Subsequently, tests were carried out with original motion laws that cannot be represented by modified trapezoidal laws.

Parameter Value
Constraints λ = t A = 0.0s, s A = 0.0rad, v A = 0.2rad/s, a A = 1.4rad/s 2 , . . . At the beginning of the identification procedure based on GA, an initial solution with all the seven coefficients of c equal to 1/7 was chosen (black curve in Figure 9). The blue curve is the law of motion obtained at the end of the optimization procedure with Euclidean norm evaluated on the acceleration as an objective function. As can be seen, it matches the simulated experimental data very well (light-blue curve). In this case the Euclidean norm proved to be adequate, allowing for convergence after a limited number of generations. The convergence time was of about 2/5 s. The software displayed the acceleration, the velocity and the displacement diagrams, which, however, were substantially superimposed. The absolute maximum error on the coefficients was about 0.0076. Figure 8. Application of the method to a simulated case, with random disturbance added to acceleration. (Black: acceleration of the starting step of the identification process; red: displacement; green: velocity; blue: acceleration, after the identification).  Figure 9 shows the case with the same shaped law of motion, but without noise. The error on coefficients in this case was 0.00034, so it was reduced by an order of magnitude. This case completely validates the procedure, since it substantially offers the values of the coefficients of the loaded motion law. As visible in the lower part of Figures 8 and 9, the genetic algorithm converges quite quickly, reaching a good reduction of the objective function already after 50 generations. This case, completely general, was used to tune the genetic algorithm, i.e., to establish the values of the algorithm intrinsic parameters that can be used for the developed RE method. After a high number of tests, the values shown in Table 2 were chosen. Keeping the intrinsic parameters of the genetic algorithm fixed (Table 2), tests for nine different cases were carried out, related to the different motion laws used to generate simulated input data. In the following sections, we refer to these laws of motion as "original", in the sense that they originated the data that replaced the experimental measurements in simulation. All these motion laws can be represented through the formulas of the modified trapezoidal law; that is, they fall within the class of modified trapezoids. For all the considered cases, a unitary displacement in a unitary time, null constraint vector and 300 extracted sampled points were assumed. The maximum number of generations was set 500, or less in case the algorithm no longer evolves. Table 3 contains the values of the seven coefficients of the considered laws of motion, whereas Table 4 collects the results of the identification in four cases: identification on acceleration, identification on velocity and for each one adopting either the Euclidean norm or DTW algorithm in the objective function calculation.  For one of the previous laws of motion (L7), further tests were made with and without noise, carrying out the identification based on displacement, speed and acceleration. Table 5 shows the final errors on displacement, speed and acceleration calculated with the EN and DTW algorithm. Subsequently, tests were carried out with original motion laws that cannot be represented by modified trapezoidal laws.
Three polynomial laws, with degrees of three, four and five, respectively, were considered. Six cases for each law were investigated: identification on acceleration, on velocity and on displacement, and for each one adopting either the EN or DTW algorithm. Table 6 collects the values of the EN and DTW algorithm on displacement, velocity and acceleration evaluated at the starting step of the identification, with a trapezoidal law characterized by seven coefficients equal to 1/7 (black curve in Figure 10). Table 7 contains the results of the identifications, in terms of the final values of the EN and DTW algorithm on displacement, velocity and acceleration. Table 6. Initial values of the Euclidean norm and DTW algorithm on displacement, velocity and acceleration, in the simulated cases with laws of motion of the polynomial class used as the original law of motion.

Tests on Experimental Data
For the validation of the system, data gathered from the real case study of Figure 4 were used. For this system, composed of a damaged rocker arm follower cam, no construction drawings or characteristics of the laws of motion were available; still, displacement data in terms of follower rotation could be directly acquired on the real mechanism as a function of the cam rotation angle. The goal is to reconstruct the global motion law in order to be able to redesign the cam. The movement starts from the cam angle 110 • and is characterized by the three phases-"Phase I", "Phase II" and "Phase III"-highlighted in Figure 4 with different background colors. The constraints of the movement are reported in Table 8. Note that, in this case, the law of motion is expressed in terms of geometric law of motion, and this explains the measurement units in Table 8 and in the following tables. Since the speed of the cam is constant, the angular displacement of the cam and time are proportional, so the displacement of the follower (in deg) can be expressed as a function of the displacement of the cam (in deg) and not of time; accordingly, the units of follower displacement, speed and acceleration are deg, deg/deg and deg/deg 2 , respectively. The procedure was applied to each one of the three phases independently. A comparison between the Euclidean norm and DTW algorithm to calculate the objective function in the identification based on displacement, velocity and acceleration was performed and the report of the results, in terms of final values of the EN and DTW algorithm, is in Table 9.  Figure 10 shows the comparison between experimental law of motion (light blue) and modified trapezoidal laws for each phase (with equal coefficients values) when used as starting point of the identification procedure. Figure 11 reports the comparison with the identified laws based on displacement and EN, whereas Figure 12 reports on displacement and the DTW algorithm. Similarly, Figures 13 and 14 refer to identification based on speed, whereas Figures 15 and 16 refer to acceleration.        The values of the seven coefficients of the best laws identified for the three areas are shown in Table 10. The computation time in all the examined cases keeps within the order of a few seconds.

Discussion
Through the performed tests, the suitability of the method for the current purpose was proven (Figures 8 and 9), even in the presence of noise, and an effective set of GA intrinsic parameters was identified. In the study, for both simulation-based and real-databased tests, data filtering prior to the application of the presented method was not considered. In this specific problem, filtering the acquired data could cause important components of the signal to be lost. Therefore, it was preferred to investigate the robustness of the method even in presence of disturbances.
Analyzing Table 4, the simulation tests on nine original motion laws of the trapezoidal class revealed that the identification based on acceleration achieved higher performances than with velocity in all the considered cases. For the objective function calculation, the DTW algorithm provided better results for law L1, L2 and L4, whereas the EN provided better results for the others. However, the errors on the coefficients obtained with identification based on acceleration, with both the EN and DTW algorithm, were present in all cases very small maximum values, so it can be said that the identification adequately reached the goal in both cases. The combined use of speed and DTW is characterized, in all the cases, by errors on the significant coefficients and, therefore, is a combination to be discarded.
Considering the errors in terms of displacement, velocity and acceleration for law L7 (Table 5), in the case without noise, a progressive improvement can be detected passing from the identification based on the displacement to that with speed and that with acceleration, with both the EN and DTW algorithm, and in all cases the errors are lower with the EN than with the DTW algorithm. In the case with noise, the error on acceleration substantially does not change identifying the EN on displacement, speed or acceleration, whereas there is a slight improvement with the DTW algorithm, and the obtained error is lower with acceleration. The lowest errors are obtained for displacement and speed when the identification is performed on speed with the EN, and for acceleration when the fitting is on acceleration with the DTW algorithm.
According to the tests with original laws of the polynomial class, the EN performs better than the DTW algorithm, almost in all the tested situations. Analyzing Table 7 by rows, the performance worsens as the degree of the polynomial increases. In particular, in terms of percentage of variation error, the worsening gets higher when passing from degree three to degree four than when passing from degree four to five. Analyzing data by columns, an overall improvement can be seen passing from identification on displacement to identification on speed and subsequently on acceleration, as observed for the law

Discussion
Through the performed tests, the suitability of the method for the current purpose was proven (Figures 8 and 9), even in the presence of noise, and an effective set of GA intrinsic parameters was identified. In the study, for both simulation-based and real-data-based tests, data filtering prior to the application of the presented method was not considered. In this specific problem, filtering the acquired data could cause important components of the signal to be lost. Therefore, it was preferred to investigate the robustness of the method even in presence of disturbances.
Analyzing Table 4, the simulation tests on nine original motion laws of the trapezoidal class revealed that the identification based on acceleration achieved higher performances than with velocity in all the considered cases. For the objective function calculation, the DTW algorithm provided better results for law L1, L2 and L4, whereas the EN provided better results for the others. However, the errors on the coefficients obtained with identification based on acceleration, with both the EN and DTW algorithm, were present in all cases very small maximum values, so it can be said that the identification adequately reached the goal in both cases. The combined use of speed and DTW is characterized, in all the cases, by errors on the significant coefficients and, therefore, is a combination to be discarded.
Considering the errors in terms of displacement, velocity and acceleration for law L7 (Table 5), in the case without noise, a progressive improvement can be detected passing from the identification based on the displacement to that with speed and that with acceleration, with both the EN and DTW algorithm, and in all cases the errors are lower with the EN than with the DTW algorithm. In the case with noise, the error on acceleration substantially does not change identifying the EN on displacement, speed or acceleration, whereas there is a slight improvement with the DTW algorithm, and the obtained error is lower with acceleration. The lowest errors are obtained for displacement and speed when the identification is performed on speed with the EN, and for acceleration when the fitting is on acceleration with the DTW algorithm.
According to the tests with original laws of the polynomial class, the EN performs better than the DTW algorithm, almost in all the tested situations. Analyzing Table 7 by rows, the performance worsens as the degree of the polynomial increases. In particular, in terms of percentage of variation error, the worsening gets higher when passing from degree three to degree four than when passing from degree four to five. Analyzing data by columns, an overall improvement can be seen passing from identification on displacement to identification on speed and subsequently on acceleration, as observed for the law L7.
The percentage of error reduction, also in this case, is more significant for the 3-3 laws and progressively lessens as the degree increases.
Considering all three errors (on displacement, velocity and acceleration), for all the three considered laws of motion, the best case is the one with identification based on acceleration and with the EN.
For the actual case, the comparison between the identification with displacement, velocity and acceleration based on numerical errors (Table 9) shows that for all three phases the errors on the acceleration are substantially equivalent to the variation of the quantity to be identified and both with the EN and DTW algorithm. For the error on the displacement, in Phase I the best case is the identification on the displacement with the EN, in Phase II on the displacement with the DTW algorithm and in Phase 3 on displacement with the EN. In all three cases, however, the difference between the EN and DTW algorithm is low. Phase II is characterized by an anomalous behavior due to the breaking of the cam; therefore, as was hypothesized, the DTW algorithm may be more effective than the Euclidean norm in situations where anomalies are present. It is observed, however, that the numerical results of the errors do not provide information on the shape of the acceleration, which significantly affects the dynamic behavior of the system. A smoother law of motion for the acceleration, i.e., which presents a trend with a slope (Jerk) that varies more gradually, is always preferable, because it improves the dynamic behavior when subjected to high loads and high speeds [14,15]. Therefore, a visual comparison of trends is also useful. From the visual comparison of acceleration trends (Figures 11-16), in Phases I and II, the identifications based on speed with the DTW algorithm and acceleration with the EN are better and substantially equivalent, and in Phase III the identifications based on speed with the EN are the best ones.
The flexibility offered by manipulating the coefficients c, while keeping fixed the values at the extremes of the range of motion, is a key element of the presented reverse engineering technique. It is based, in fact, on an optimized reconstruction of the cam profile, by manipulating these coefficients.
A further significant advantage of the proposed method is that, based on the identification of the laws of motion, it offers the designer the possibility of verifying the limit values of the kinematic quantities (speed and acceleration), which significantly influence some design aspects (such as the overall dimensions for speed and dynamic loads for acceleration). In this way, when these values are excessive, the designer has the possibility to apply a well-known optimization method to improve the motion law from this point of view.

Conclusions
The developed procedure, which can be used as a phase of a wider reverse engineering process of cams, proved to be effective and with excellent performance in computational terms. Computational times of the method are well tolerable if the procedure is inserted, as tools, in a mechanical design software.
In all the examined cases, the procedure achieved good results. Using a GA as optimization tool and the EN or DTW algorithm for the evaluation of the objective function, it allows for the analytic reconstruction of a modified seven trapezoidal motion law that best approximates the motion law of the original cam.
The performed tests revealed that in many cases assessing the distance with the Euclidean norm on acceleration diagrams remains more effective, in particular when the signal to be recognized is little or not at all disturbed. Instead, the use of the DTW algorithm is more effective in case of anomalous situations, for instance in the acquired law of motion. In general, the DTW algorithm applied to velocity diagrams gives poor results, and therefore it is a combination that can generally be discarded. In general, there is no configuration that performs better than the others in all cases, but comparing the different conditions, an optimal configuration can be identified for each specific application, considering, for instance, the numerical results, the visual observation of the trend or the speed of execution of the algorithm.
A limitation of the procedure is that it considers only one type of law of motion, the trapezoidal modified law. While the tests with original motion of the trapezoidal family showed excellent results, performance was much worse with motion laws of the polynomial family, as it was reasonable to expect. Therefore, a future development of the study is the extension of the method by integrating the use of other types of motion laws, such as polynomials, with the aim of identifying, among the different types of motion laws, the one that allows for the best representation of the movement to be recognized. A further development is to investigate the effectiveness of a multi-objective optimization, for which genetic algorithms are particularly suitable. For example, the passage for a precision point could be imposed.
Finally, although this methodology was applied to cam mechanisms in the present work, it has a more general validity and can be applied to any system that generates a movement. It could, therefore, be defined more generally as a reverse engineering methodology of laws of motion. Funding: This research received no external funding.

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