Abstract
Many robots are dedicated to replicate trajectories recorded manually; the recorded trajectories may contain singularities, which occur when positions and/or orientations are not achievable by the robot. The optimization of those trajectories is a complex issue and classical optimization methods present a deficient performance when solving them. Metaheuristics are well-known methodologies for solving hard engineering problems. In this case, they are applied to obtain alternative trajectories that pass as closely as possible to the original one, reorienting the end-effector and displacing its position to avoid the singularities caused by limitations of inverse kinematics equations, the task, and the workspace. In this article, alternative solutions for an ill-posed problem concerning the behavior of the robotic end-effector position and orientation are proposed using metaheuristic algorithms such as cuckoo search, differential evolution, and modified artificial bee colony. The case study for this work considers a three-revolute robot (3R), whose trajectories can contain or not singularities, and an optimization problem is defined to minimize the objective function that represents the error of the alternative trajectories. A tournament in combination with a constant of proportionality allows the metaheuristics to modify the gradual orientation and position of the robot when a singularity is present. Consequently, the procedure selects from all the possible elbow-configurations the best that fits the trajectory. A classical numerical technique, Newton’s method, is used to compare the results of the applied metaheuristics, to evaluate their quality. The results of this implementation indicate that metaheuristic algorithms are an efficient tool to solve the problem of optimizing the end-effector behavior, because of the quality of the alternative trajectory produced.
Keywords
Introduction
Singularities during robotic motion are an important problem when using robots, and its solution is an open issue due to its degree of complexity and the extended use of such devices. Those singularities can be classified as internal or boundary. Boundary singularities occur when the manipulator is stretched or retracted and are easy to avoid if the robot is not taken to its workspace limits. Internal singularities occur within the available workspace, and they are caused by the alignment of two or more axes, or by the end-effector configuration. In these singularities, the end-effector position and/or orientation produces undesired movements in one or more specific points during a trajectory. Unlike the first type of singularities, these constitute a serious problem since they can appear in any part of the robot envelope when a trajectory in the operational space has been generated. 1
A way to solve the problem is by detecting in advance the singularities in a specific trajectory, and the subsequent calculation of a new optimized path from the set of points corresponding to the original trajectory. Nevertheless, the problem has not been addressed from this avoidance perspective. There are several techniques for solving manipulator kinematics as an optimization problem such as neural networks, hybrid algorithms, Jacobian approximation, and dual quaternions, among others. 2 –8 In the study by Srisuk et al., 9 a custom neural network implementation is used to solve the inverse kinematics of a 4 DOF robot with the ability to reach objects in 3-D avoiding obstacles within its envelope. In the study by Horváth et al., 10 an interesting solution is presented using the Jacobian pseudo-inverse and the best mobility direction. Another recent robotic-algorithm implementation is the length relaxation method. 11 This methodology consists on determining an approximation kinematic chain with randomly located points, considering that the links are not identical, and the extreme positions are known (base and end-effector). As a difference to other approaches, it focuses its attention on obtaining the Cartesian coordinates located in the joint intersection and consequently, the angles of every joint.
In addition to the aforementioned methodologies, alternative approaches such as metaheuristics have been applied. They are approximated techniques for solving hard problems established as optimization cases. These algorithms are used in different engineering areas such as mechanism synthesis, 12 the design of electromagnetic devices, 13 delivery planning, 14 network routing, 15 among others. In this work, a novel methodology for avoiding robotic singularities in a trajectory is proposed, by establishing an optimization problem with a weighted objective function that modifies the position and/or orientation in the Euclidean space, enabling the manipulator to maintain its reference direction concerning to the original target. Cuckoo search (CS), differential evolution (DE), and modified artificial bee colony (MABC) were implemented for this development, using two specific functions as test cases with and without singularities.
The content of this article is as follows: In the second section, the end-effector kinematics, manipulator elbow-configurations, and the equations that define the paths are presented. In the third section, the objective function and the selection criteria for elbow-configuration are described, while in the fourth section the procedure for optimizing trajectories and the implemented metaheuristic algorithms are explained in detail. The fifth section includes the experimental results and their analysis. Finally, in the sixth section, the conclusions are discussed.
Forward kinematics and manipulator elbow-configuration
In order to accomplish the optimization proposed in this article, it is required to establish the parameters that conform the kinematic chain of the manipulator. The Denavit–Hartenberg parameters are used to obtain a 4 × 4 matrix as a representation of the position and orientation of a rigid body.
16
Two parameters describe the dimension of every link (d
, a) and two more

Multiple solutions to the 3R robot configuration and their corresponding parameters.
A planar 3R robot arm contemplates a large workspace because any position within the interior of its envelope can be reached. 18 However, there is a singularity problem that arises depending on the numerical methodology and the number of elbow-configurations in which a robot can reach the target with a desired position and orientation. As can be seen in Figure 1, the manipulator has multiple elbow-configurations, which involves sequencing the system to select the optimal for every run, based on the best solution recorded from the last iteration.
The equations corresponding to the mathematical development of the elbow-configuration from Figure 1 are as follow: assuming that
Considering equations from (6) to (11), it is possible to obtain equation (12)
The inverse kinematics can be obtained using closed-form solutions or numerical methodologies. The former allows a quick and efficient calculation of the elbow-configuration once the desired end-effector position and orientation is determined. From a numerical perspective, the inverse kinematics can be formulated to determine the articulatory coordinates
The orientation and translation for the sinusoidal function are defined by the range [−160, 160] with increments of
The orientation and translation for the spiral function are defined by the range [0, 1] with increments
It is important to mention that Mspiral has 360 poses recorded in an interval [0,1], and Msin has 320 poses in the interval [−160,160], and every recorded pose corresponds to one optimization problem.
The objective function
The primary purpose of a mono-objective optimization problem is to find the minimum or maximum of a function (optimal). Since an optimum is a solution, it can be local, global, or both.
20,21
In this work, the objective function focuses on reducing the error between the desired position and orientation, and the best obtained with a metaheuristic, using the elements of equation (2) that constrain the kinematic chain. For this case,
Must minimize the objective function, f(X). This function is conformed as in equation (17)
where
The design variables are subject to expression (18)
where k defines a relative weight between position and orientation as well as a direct relationship with the maximum angle of end-effector inclination. The lesser the k value, the greater the penalization rank for

Difference of distances between the previous position and the possible current elbow-configuration.
Figure 3 shows how the global search finds solutions during the Msin trajectory. In general, metaheuristics do not exceed the limits of the design variables, unlike Local Search Methods (LSM) such as NM, which do not need to be bounded. After finding all possible elbow-configurations with their corresponding values for,

Example of the robot angles
where
Procedure for optimizing the test trajectories
In general, robot arms cannot take decisions independently, this means that generally there is an operator in charge of the movements produced by the manipulator. However, it is possible for some robots to suggest alternative solutions with the aim to optimize a process or a specific task, in which the user has the chance to decide the application of such optimization. One of the advantages that offer the implemented metaheuristics is the capability to produce solutions based on decision-making by means of a greedy selection. Imagine that a person wants to catch an object with a desired orientation and position. If at least one of the two parameters cannot be reached, the person tries to stretch out his arm to intercept the target, discriminating one of the two parameters. Under this criterion, three cases should be considered in the manipulator decision-making: existence, uniqueness, and stability. 22 In Figure 4, an overview of how the robot operates to solve the ill-posed problem is shown. The first block (I) represents the human–machine interaction (HMI) and the variable declaration. In the second block (II), the path generation box determines the trajectory depending on the operator preference. Once the path is declared, the optimization stage (in orange) will optimize the robot inverse kinematics for every point traced by considering the proposed objective function. This stage corresponds to each of the algorithms implemented in this article (DE, CS, MABC, and NM). Finally, the simulation is ready to solve the dynamics and control in the same manner as the HMI feedback. However, this work is limited to the singularity avoiding approach.

Flowchart diagram of the robot data management scheme.
The classical optimization methods are analytical, and their objective is to find the optimal solution of continuous and differentiable functions. 23 However, these methodologies have a limited approach because some practical problems involve objective functions that do not fulfill such characteristics. Then, it is necessary to use alternative methods such as metaheuristics, which are consistent algorithms for optimization problems, based on some explicit search strategy in the set of all feasible solutions . 24 The metaheuristics used in this article are nature-inspired algorithms (NIA) that can be classified by tournament type 25,26 and their interaction with LSM. 27 –31 In general, the optimization problems are classified as monobjective or multiobjective, 32 –35 also taking into account the type of constraints, 36 and if they are combinatory or numerical.
Evolutionary algorithms are highly effective metaheuristics that have been applied in diverse types of engineering problems. 25,37,38 In the case of DE, the algorithm begins with the creation of an initial population in which a target vector and a base vector are selected. Then, some individuals are chosen randomly and extracted from the population to create an entirely new individual; the next step is crossing the result with a target solution, and this creates a new trial vector. The result is compared with the target, in a tournament by greedy selection. This procedure is repeated for a specific number of generations declared as GenMax until convergence to an optimal or suboptimal is obtained. 25,32,38 The pseudo-code of the implemented DE version is in Algorithm 1.
Differential evolution/rand/1/bin
The second implemented metaheuristic is the CS algorithm that operates simulating the cuckoo breeding parasitism (see Algorithm 2). Cuckoos lay eggs in different nests randomly (one egg per nest). The nests with better eggs (optimal solutions) pass to the next generation. The host also has the chance to discover a foreign egg, and it can either discard the egg or abandon the nest and build a new one somewhere else. 39 –41 CS runs up to a maximum number of generations GenMax, until one solution is reached. An important thing about CS is that this algorithm can work with the help of an additional local search method such as the random walk algorithm.
Cuckoo search.
The MABC is a NIA, based on the foraging behavior of honey bees. 36 MABC uses three types of bees for the implementation: employee, onlooker, and scout, to find new food sources (solutions). Once a bee reaches a source, it flies to another nearby, and both food sources are compared in a greedy selection. Later, onlooker bees seek for new solutions from the ones with the best fitness. When a food source has not been improved after a specific number of iterations, then it is replaced by one scout bee, generating a new random solution. 42,43 Again, the maximum number of generations GenMax terminates the algorithm. The MABC pseudo-code can be seen in Algorithm 3.
Modified artificial bee colony.
The last algorithm implemented is a numerical methodology called Newton’s method (NM), which uses the pseudo-inverse Jacobian to get faster convergence in comparison with metaheuristics (assuming that a solution exists.) From NM approach, it is possible to solve nonlinear simultaneous equations starting from the fact that they can be linearized using Taylor expansion. 44 Two stop criteria were implemented for NM: (1) MaxN is a constant for finishing the algorithm once a specific number of iterations have been reached, and (2) an additional constant called ε is in charge of terminating the algorithm if the absolute solution of every subfunction in OF is less than ε itself, (see Algorithm 4).
Newton’s method.
It is also important to mention that OF is the difference between the actual and the desired value, considering both position and orientation during a specific pose in the trajectory. In other words, OF is the minimization of the difference between the desired and the best solution obtained. Consequently, the second stop criterion is as follows
Experimental results and discussions
Three metaheuristic algorithms (DE, CS, and MABC) were implemented to evaluate the proposed objective function performance in two different trajectories, during 60 runs. The first trajectory is generated by a spiral function, in which 360 points are recorded. Every recorded point corresponds to one different optimization problem. The second trajectory is derived from a sinusoidal function, in which 320 points are recorded.
The first algorithm studied, DE, was tuned as recommended in previous works.
25
In this context, it is possible to get an initial estimation for the DE parameters by considering the expressions (21) to (23), where the range of the mutation scale factor F is
For the proposed trajectories, the tuning of DE was as follows: D = 3 (design variables), Np = 30 (population size), and GenMax = 500 (maximum number of generations). Figures 5(c) and 6(c) show the convergence of the objective function, while Figures 5(d) and 6(d) present a zoomed view of such convergence after approximately 200 generations during the entire spiral and sinusoidal trajectories.

Objective function convergence for spiral function. Evolution of the objective function for (a) CS, (c) DE, (e) MABC, and (g) NM; (b) evolution of the objective function for CS until 500 generations.; (d) evolution of the objective function for DE until 160 generations; (f) evolution of the objective function for MABC until 45 generations; (h) evolution of the objective function for NM until 1000 generations. CS: cuckoo search; DE: differential evolution; MABC: modified artificial bee colony; NM: Newton’s method.

Objective function convergence for sinusoidal function. Evolution of the objective function for (a) CS, (c) DE, (e) MABC, (g) NM; (b) evolution of the objective function for CS until 820 generations; (d) evolution of the objective function for DE until 185 generations; (f) evolution of the objective function for MABC until 165 generations; (h) evolution of the objective function for NM until 1.2 generations. CS: cuckoo search; DE: differential evolution; MABC: modified artificial bee colony; NM: Newton’s method.
For the Cuckoo Search implementation, the tuning criterion is according to Xin-She Yang and Suasg Deb, 41 the number of nest should be in between n = 14 and 40, and the probability of abandoning a nest is equal to P a = 0.25, when applying CS for most optimization problems. Starting from this recommendation, the best tuning for both trajectories was: n = 40, P a = 0.25, and GenMax = 12,025. In Figures 5(a) and 6(a) is possible to appreciate the objective function convergence to zero, while Figures 5(b) and 6(b) show the behavior until 500 and 800 generations.
According to Karaboga, 45 for the MABC tuning implementation, the limit of trials for abandoning a source is limit = SN × D, where D corresponds to the number of design variables and SN to the number of source or food solutions. The best parameters found in addition to this criterion are: SN = 40 and GenMax = 167 for the spiral trajectory, and SN = 40 and GenMax = 165 in the case of the sinusoidal path. However, MABC was not able to find good solutions for the proposed paths, as can be seen in Figure 5(e) and (f), and Figure 6(e) and (f).
Finally, in order to find the best tuning for the NM implementation, the eight possible combinations in Table 1 were evaluated for 60 runs each, modifying the following parameters: maximum number of iterations MaxN, stop criterion value ε, and design variable increment dx. The results in Table 2 were obtained from applying the eight combinations to both case studies, the sinusoidal and spiral trajectories Msin and Mspiral, showing that the combination G is almost as good as combination H for the sinusoidal function, and at least two times better for the spiral function.
Comparison between the possible combinations analyzed from NM.
NM: Newton’s method.
Results obtained from the possible combinations for NM.
NM: Newton’s method.
As can be seen from the results, none of the combinations for spiral trajectory was satisfactory, since this path presents two regions of singularities which cause discontinuities and elbow-configuration changes, and NM is only able to find one solution at the time as shown in Figure 5(g) and (h). In the case of the sinusoidal trajectory, all the combinations were successfully executed, presenting continuity and maintaining the elbow-configurability. For the case of the sinusoidal function, the eight possible combinations were able to follow the trajectory since it is out of singularities (see Figure 6(g) and (h)).
Table 3 includes the average values of the objective function for both trajectories using CS, DE, MABC, and NM. Every recorded pose that conforms Msin and Mspiral involves the definition of a different OF. In general, NM, CS, and DE offer a similar average of the objective function corresponding to the sinusoidal trajectory, while in the case of the spiral trajectory, MABC does not really demonstrate superiority in comparison to NM, CS, and DE, since the mean error shown in Table 3 only evaluates how near from the optimal solution the algorithm is capable to reach (the closer the value to zero the better the solution for finding the optimal). In Figures 7(g) and 8(g), it can be appreciated from the robotic arm tracking that MABC do not offer an alternative solution in comparison with DE and CS, as can be seen in Figure 7(a) and (d), Figure 8(a) and (d).
Statistical comparison between CS, DE, MABC, and NM after 60 runs.
CS: cuckoo search; DE: differential evolution; MABC: modified artificial bee colony; NM: Newton’s method.

Graphs with spiral function implemented for CS, DE, MABC, and NM. The end-effector trajectory from a starting position to the desired position with (a) CS, (d) DE, (g) MABC, (j) NM; robotic arm tracking of a 3R robot with (b) CS, (e) DE, (h) MABC, (k) NM; (c) CS, (f) DE, (i) MABC, (l) NM convergence during spiral trajectory. (a, d, g, and j) EE path; (b, e, h, and k) robotic arm tracking; (c, f, i, and l) Cartesian error position. CS: cuckoo search; DE: differential evolution; MABC: modified artificial bee colony; NM: Newton’s method; EE: end-effector; 3R: three-revolute.

Graphs with sinusoidal function implemented for CS, DE, MABC, and NM. The end-effector trajectory from a starting position to the desired position with (a) CS, (d) DE, (g) MABC, (j) NM; robotic arm tracking of a 3R robot with (b) CS, (e) DE, (h) MABC, (k) NM; (c) CS, (f) DE, (i) MABC, (l) NM convergence during sinusoidal trajectory. (a, d, g, and j) EE path; (b, e, h, and k) robotic arm tracking; (c, f, i, and l) Cartesian error position. CS: cuckoo search; DE: differential evolution; MABC: modified artificial bee colony; NM: Newton’s method; EE: end-effector; 3R: three-revolute.
The following experiment, reported in Table 4, consists of 60 runs of every metaheuristic algorithm to assess the quality of the obtained solutions. The run effectiveness is based on the quality in which the robot traced the path without undesired movements such as changes in the elbow-configuration sequence, and in the trajectory smoothness. The number of function evaluations (NFE) indicates that CS and DE have a similar performance, since they also reach a similar solution. The proportionality constant is k = 0.2 (the lower of the value, the higher the reorientation for [0 ≤ k ≤ 1]). The results show a slight improvement in the solutions found concerning CS over DE, taking into consideration the path quality, maximum number of generations GenMax, elbow-configuration sequence, and population size Np; this result is also shown in Figure 7(a) and (b), Figure 8(a) and (b). CS and DE can avoid the singularity by proposing a new path that fits almost completely with the original trajectory. MABC was the implemented metaheuristic with the worst performance (see Figure 7(g) to (i) and Figure 8(g)to (i)), since it could not optimize any path in the same manner that CS and DE (see Figure 7(a) and (d), Figure 8(a) and (d)), while there is an optimal solution during the trajectory, NM can converge faster than the metaheuristics mentioned above. In Figures 5(h) and 6(h) can be appreciated that the objective function takes just one iteration to converge to zero whenever there is no singularity.
Comparison between DE, CS, MABC, and NM, with respect to the case studies.
CS: cuckoo search; DE: differential evolution; MABC: modified artificial bee colony; NM: Newton’s method.
Figures 7 and 8(a, d, g, and j) show the alternative trajectories generated by the robot arm with the CS, DE, MABC, and NM algorithms, using the closer elbow up and down configuration to find the best solution. Figures 7 and 8(b, e, h, and k) represent the robot arm tracking and how orientation and position were gradually varying to reach the continuous path. In Figures 7 and 8 (c, f, i, and l), the best, mean, and worst solutions obtained for the objective function can be seen. This means that every metaheuristic solution conforming the path of Msin and Mspiral corresponds to the lines plotted in Figures 5 and 6. According to Table 4, DE had a higher number of successful runs over CS in the spiral function (96.66% vs. 80%). In the sinusoidal function, CS obtained 100% of runs successfully over 93.33% from DE, with a similar trajectory quality, as can be seen in Figure 7(a) and (d), and Figure 8(a) and (d). In the case of MABC for the sinusoidal trajectory, the algorithm improves in comparison with the spiral trajectory but not enough to optimize the path smoothly (see Figures 7(g) and 8(g)). From Figure 7(j), it can be inferred that NM is more susceptible of losing its position and elbow-configuration when orientation is not attainable, while in the case of the sinusoidal trajectory, the algorithm performs with a better quality than DE and CS (see Figure 8(k)). In general, CS and DE represent continuous sequences in the elbow-configuration for the case studies 1 and 2. For the metaheuristics, the design variables were bounded to ±360° and ±460° (see Table 4), reducing the search space in the proposed solutions. In NM, angular intervals are unbounded, which means that the solution of every design variable needs to be adjusted before implementation. Unlike CS and DE, NM presents path discontinuities and elbow-configuration changes at the beginning and in the middle of the spiral trajectory when experiencing singularities (see Figure 7(k)). In the case of CS, two peaks appear in Figure 7(c) for the worst solution found. This corresponds to each of the singularities in the spiral function. Since CS is not able to get an objective function convergence to zero, it is in charge of choosing the best possible solution by a greedy selection. MABC was unable to optimize the desired trajectories in Figures 7(g) and 8(g); consequently, it shows discontinuity in the trajectory and elbow configurability changes in Figures 7(h) and 8(h). Unlike CS and DE, in MABC it was impossible to find an acceptable solution to both problems even when doubling the population size and the NFE.
Conclusions
In this work, a method for avoiding singularities in trajectories of a robotic arm is developed. It consists in calculating an alternative path by solving a weighted optimization problem with a metaheuristic algorithm. For the proposed case studies, CS and DE offered greater reliability to find an alternative solution in comparison with MABC. The best numerical solution (DE) demonstrated an effectiveness of 96.66% in the spiral function and 93.33% in the sine wave function, while the second quality solution (CS) had 80% of effectiveness in the first function and 100% in the second. MABC and NM could not reach at least one successful run in the spiral trajectory. On the one hand, global search methods require knowing the multiple configurations concerning the desired pose, which makes the programming more complex. On the other hand, the bounds of every design variable reduce the solution space considerably. In general, CS and DE have a similar performance by considering a maximum number of generations and population size. Although DE seems to be more robust due to its error repeatability, CS has advantages over DE corresponding to end-effector angular displacement. Classical numerical methodologies such as NM present greater simplicity of programming and regularly converge rapidly. However, they lose their elbow-configuration when a singularity occurs, and they only contemplate the closest solution to the analysis point.
Footnotes
Acknowledgements
All authors thank Instituto Politécnico Nacional (COFAA, SIP, ESIME UA, and CIDETEC), and CONACYT, for all their support provided during the elaboration of this paper, and Miguel Angel Funes wants to thank CONACYT for the scholarship grant during his doctorate.
Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Funding
The author(s) disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: This study was financially supported by Instituto Politécnico Nacional-COFAA.
