A Type II Singularity Avoidance Algorithm for Parallel Manipulators using Output Twist Screws

Parallel robots (PRs) are closed-chain manipulators with diverse applications due to their accuracy and high payload. However, there are configurations within the workspace named Type II singularities where the PRs lose control of the end-effector movements. Type II singularities are a problem for applications where complete control of the end-effector is essential. Trajectory planning produces accurate movements of a PR by avoiding Type II singularities. Generally, singularity avoidance is achieved by optimising a geometrical path with a velocity profile considering singular configurations as obstacles. This research presents an algorithm that avoids Type II singularities by modifying the trajectory of a subset of the actuators. The subset of actuators represents the limbs responsible for a Type II singularity, and they are identified by the angle between two Output Twist Screws. The proposed avoidance algorithm does not require optimisation procedures, which reduces the computational cost for offline trajectory planning and makes it suitable for online trajectory planning. The avoidance algorithm is implemented in offline trajectory planning for a pick and place planar PR and a spatial knee rehabilitation PR.


Introduction
Parallel robots (PRs) are mechanisms where the end-effector (mobile platform) is linked to the base (fixed platform) by at least two open kinematics chains [1,2].This closed-chain architecture provides PR with high rigidity and the ability to handle large loads with high accuracy [3].The main drawback is the existence of configurations inside of workspace where the number of degrees of freedom (DOFs) changes instantaneously, named Type II singularities by Gosselin and Angeles [4].A Type II singularity is dangerous due to the fact that the end-effector could move despite all actuators being locked.In robotic rehabilitation [5] and collaborative operations [6], the lack of complete control of the PR movements must be solved to keep the user safe.The optimisation of the workspace [7][8][9][10], adding actuators [11][12][13][14], and trajectory planning [15][16][17][18] are some methods to deal with Type II singularities.
Trajectory planning computes PR motions satisfying robot dynamics and actuator constraints, minimising energy consumption or execution time while avoiding collisions with obstacles such as Type II singularities [16].The trajectory planning is performed offline, online, or a combination of both.Offline trajectory planning connects two desired PR locations based on prior information about the PR workspace and the regions with Type II singularities [17].In contrast, online trajectory planning replaces the preceding information about the workspace and singular regions with a partial view of the workspace [16] or sensor feedback [19].
Sen et al. [20] proposed a path planning algorithm for PRs that constrains the potential energy of the PR to avoid singular configurations.In [21], Khoukhi et al. presented a multi-objective dynamic trajectory planning for PRs where a Type II singularity is avoided by maximising the manipulability of the PR.A path planning method by generating singularity-free C-spaces defined in the vicinity of the two configurations to connect is proposed in [22].Bourbonnais et al. [23] proposed a stochastic cubic spline optimisation that avoids Type II singular regions while generating smooth trajectories for a five bars PR.In [24] Li et al. generate feasible trajectories for a 4-DOF PR using a quintic B-spline considering singular configurations as optimisation constraints.The methods reported in [20][21][22][23][24] are mathematically complex and require considerable effort to select the parameters of the optimisation problem.Thus, Type II singularities avoidance is challenging to implement in real-time applications.Agarwal et al. [25] proposed a task-priority controller where a potential function allows online singularity avoidance that requires reducing one DOF of the PR.Hill et al. [26] applied virtual constraints in a controller to online trajectory generation during a Type II singularity crossing.These methods require setting the control law to track location and avoid singularities simultaneously which increases the complexity of implementation.In [14,27] singularity avoidance methods based on redundant PRs are analysed.
The closeness to a Type II singularity could be detected by the determinant of the Forward Jacobian matrix [28,29], motion/force transmission indices [30] or stiffness indices [31].However, the kinematic chains involved in the singularity are not identified.Based on Screw Theory, Pulloquinga et al. [32] proposed the angle between two instantaneous screw axes from the Output Twist Screws (Ωi, j) to measure the closeness to a Type II singularity.This research verified the capability of the index Ωi, j to measure the proximity to a singular configuration by an experimental benchmark in a 4-DOF PR prototype.Next, [33] verifies that the minimum Ωi, j identifies the pair of kinematic chains responsible for the singular configuration in a 4-DOF PR.Then, the minimum angle Ωi, j was applied to Type II singularity avoidance during offline trajectory planning for a 4-DOF PR [34].However, Type II singularity avoidance based on the minimum Ωi, j is limited to a spatial PR, i.e., a general singularity avoidance algorithm is required to include planar PRs.Moreover, online Type II singularity avoidance based on Output Twist Screws (OTSs) has not been analysed.
This paper proposes an algorithm that avoids a Type II singularity by modifying the trajectory of the actuators involved in the singular configuration for planar and spatial PR.The singularity avoidance algorithm works with one trajectory sample at a time.In the vicinity of a Type II singularity, the avoidance algorithm calculates the deviation required in the subset of actuators responsible for the singularity.The actuators responsible for the singularity are identified by the minimum angle between the linear components from two Output Twist Screws (Θi, j) in the planar PR and by the minimum angle Ωi, j in the spatial case.Only the trajectory of the actuators identified by the minimum Θi, j or Ωi, j are modified to avoid a Type II singularity, i.e., the × reference trajectory requires a minimum modification.For this reason, the proposed algorithm is suitable for applications where the significant changes on the reference trajectory are risky, such as human rehabilitation.The modification in the trajectory of the actuators is calculated using a straight line equation, reducing the diffculty of setting the algorithm proposed.The straight line is defined by the sample time of the trajectory and the velocity of the PR.For an arbitrary sample of time, the proposed algorithm only needs the reference and the current location of the PR to avoid a singularity.In offline trajectory planning, the current location of the PR represents the previous reference trajectory sample.In online trajectory planning, the current location of the PR is measured by a 3D tracking sensor or by solving the Forward kinematics based on encoders in the actuators.Thus, the contribution of this paper is a general Type II singularity avoidance algorithm with low complex calculations and minimal requirements for implementation, suitable for offline and online applications.It is important to emphasise that it is the first time the minimum angle Θi, j is applied for singularity avoidance in planar PRs.Therefore, this paper complements the research developed with spatial PRs in [32,34].
Section 2 presents the mathematical foundations concerned with Type II singularities and their detection by the angles Θi, j or Ωi, j.In Section 3, a detailed description of the developed algorithm for Type II singularity avoidance is exposed.Section 4 applies the avoidance algorithm in offline trajectory planning for a five bars PR and discusses the simulation results.Section 5 applies the avoidance algorithm in offline and online trajectory planning for 4-DOF PR for knee rehabilitation.The offline singularity avoidance is verified by measuring the location reached by the actual PR using a 3D tracking system.Then the offline and online trajectory planning results are discussed.Finally, the main conclusions are presented in Section 6.

Singularities in parallel robots
In a close kinematics mechanism [4], the relationship between the input and output coordinates is defined by a set of constraint equations ϕ as follows: where the output x stands for the location and orientation of the end-effector or mobile platform, and the input qind represents the subset of actuated joints.Taking time derivatives of (1), the relationship between the outputs and inputs velocities is: with JI, JD as the Inverse and Forward Jacobian matrix, respectively.Both matrices are square matrices (F F) for non-redundant Parallel Robots (PRs), where F is the number of DOFs of the mobile platform.
Based on the input-output kinematic relationship, Gosselin and Angeles [4] define three types of singularities: I The mobile platform of the PR loses mobility in at least one direction where the JI matrix becomes rank deficient, ∥JI∥ = 0. Figure 1a shows an example using a five bars PR (5R).II The mobile platform of the PR gains at least one uncontrollable motion despite all actuators being locked (see Figure 1b), where the ∥JD∥ = 0. Type II singularities require special attention because they appear within the workspace.Losing control over the mobile platform movements (x ˙ * 0) despite the actuators being fixed (q ˙ind = 0) represents a potential danger for the user or the PR itself.Another drawback of Type II singularities is the increase in the efforts of the actuators because the calculus involves the JD.For PR with F < 6, there are constrain singularities quite analogous to Type II singularities [2].This research is focused on Type II singularities.The calculation of JD presents a simple numerical method to detect a Type II singularity.However, combining rotational and translational joints produces a JD matrix with not homogeneous units that make it difficult to measure the closeness to a singularity.Another disadvantage of ∥JD∥ is the inability to identify the limbs involved in the Type II singularity.

Singularities detection based on Output Twist Screws
In a non-redundant PR, the motion of the mobile platform is produced by the combined action of F actuators, i.e., the contribution of each actuator is challenging to identify.According to Takeda and Funabashi [35], if all actuators are locked except one, the instantaneous unit motion of the mobile platform is represented by an Output Twist Screw (OTS).Then, the linear and angular velocity of an arbitrary point of the mobile platform $ is a linear combination of F unit OTSs $ ˆO: where k1, k2 . . .ki are the amplitude of each OTS.
For an i = 1 . . .F limb, $ ˆOi is produced by the unit wrench transmitted by the correspondent actuator $ ˆTi while the other actuators apply no work to the mobile platform (see Figure 2).Thus, each $ ˆOi is defined by solving: In [8], Wang et al. proved that for a singular configuration, at least two OTSs are linearly dependent.Then, in a Type II singularity, at least two limbs are contributing to the mobile platform motion in the same direction, i.e.: where i, j identify the limbs under analysis.From a geometrical point of view, in a singular configuration the linear and angular components of the $ ˆOi and $ ˆO j are parallel.Thus, the parallelism in the linear components µ * vO is measured by the angle Θi, j, and by the angle Ωi, j for the angular components µw O , as follows: In a Type II singularity Θ i, j = Ωi, j = 0, where the limbs i, j are responsible for the configuration because they contribute to the mobile platform motion in the same direction.The Θi, j and Ωi, j have the advantage of having physical meaning because they are angular magnitudes as opposed to the JD .Examples of calculating the angles Θi, j and Ωi, j are presented at the beginning of Section 4 and Section 5, respectively.
For a planar PR (F = 2), the closeness to a Type II singularity is measured by decreasing Θi, j.It is because the µw O i and µw O j are perpendicular to the plane maintaining Ωi, j = 0.
For a spatial PR (F > 2), the combination of pairs of limbs in expressions ( 7) and ( 8) generates several possible angles Θ i, j and Ωi, j, respectively.However, the parallelism between two $ ˆO is the minimum condition to reach a singular configuration.Then, the proximity to a Type II singularity is defined by the minimum angles Θi, j and Ωi, j.However, in (5), the µ * vO can be rewritten with respect to the µw O i as follows: where h is the screw's pitch and rOP is the minimal distance between the selected point of the mobile platform O and µw O i , see Figure 2.
Rewriting the cross product with matrix multiplication (9) becomes: (10) with the matrix H and the skew-symmetric matrix R ˜ defined as: According to (10), if H and R ˜ are null matrices, µ * vO = 0 even though µw O i * 0, i.e., the limb i contributes with pure angular motion.Then, there are arbitrary non-singular configurations with Θi, j = 0 and Ωi, j * 0 because the µ * vO and µ * vO could disappear or become parallel.In contrast, the angle Ωi, j = 0 if and only if the µw O i and µw O j become parallel.Therefore, in a spatial PR, the closeness to a Type II singularity depends mainly on decreasing the minimum angle Ωi, j.The effectiveness of the minimum angle Ωi, j as a Type II singularity proximity detector was proved by an experimental benchmark in [32].In that work, the minimum angle Θi, j was used to verify that the PR reaches a singular configuration.An example of the Type II singularity proximity detection using the minimum angle Ω i, j is presented in Section 5.
The minimum angle Ωi, j has been used to avoid singularities during an offline trajectory planning in a 4-DOF PR [34].However, the index Θi, j has not been used for Type II singularities avoidance in planar PRs.This paper presents a novel Type II singularity avoidance algorithm for general purposes based on the minimum angles Ωi, j and Θi, j.The avoidance algorithm uses Θi, j to detect the proximity to a singularity in the planar PR and Ωi, j for the spatial case.Moreover, the execution time of the avoidance algorithm is measured to verify the low computational cost of calculating the minimum angles Ωi, j and Θi, j.

Type II Singularity Avoidance Algorithm
For a discretised instant time, the reference pose of the mobile platform xr and the actual pose reached by the PR xm are the inputs required by the avoidance algorithm.Each discretised instant time, the inputs xr and xm are taken simultaneously.The Inverse Kinematic model calculates the correspondent reference location in joint space qind r .Figure 3 shows an overview of the algorithm proposed.
The avoidance algorithm first takes xr to calculate all $ ˆOi (i = 1 . . .F), and calculates the arrays vΘr and vΩr that store all possible angles Θi, j and Ωi, j (i, j = 1 . . .F, i * j), respectively.Next, αr calculates the minimum element in vΘr for planar PRs or in vΩr for a spatial case.Analogously, the vΘm, vΩm, αm are calculated for the measured xm, and ich stores the two limbs identified by αm.
The proposed algorithm calculates a non-singular desired location qind d by using: νd and ts are the constant velocity for singularity avoidance and the sample time for the trajectory discretisation, respectively.∆ι is an integer accumulator (F 1) for the deviation required in the actuators.The non-singular desired reference in configuration space xd could be calculated by solving the Forward Kinematics problem for qind d .The proposed algorithm starts with qind d = qind r , i.e., ∆ι = 0.If αr is below a predefined threshold (limα), the ∆ι is modified because the reference xr is proximal to a Type II singularity.Two rows of ∆ι are modified by one at each discretised instant time until the qind d drives the PR to a non-singular configuration xm, i.e., αm > limα.With αm > limα, if the reference xr becomes non-singular (α r > limα), ∆ι must return progressively to zero because a Type II singularity has been avoided.Figure 4a shows a detailed process of modifying ∆ι when the PR is proximal to a Type II singularity.In contrast, Figure 4b explains how ∆ι returns to zero after Type II singularity avoidance.
In Figure 4a, the ∆ι is modified by one only in the two rows corresponding to the elements in ich.Each row, identified by ich, could hold, increase or decrease, generating eight possible modifications of ∆ι.Considering that an actuator could stop (0), go forwards (1) or go backwards (-1), the eight possible modifications are grouped as columns of the matrix Mav, see (13).For each k possible modification of ∆ι, the qind d and αd are calculated.The index αd is the element in vΘd or in vΩd for the limbs ich.The vΘd and vΩd allocate all possible angles Θi, j and Ωi, j for the location xd.The best modification of ∆ι is selected to generate a feasible qind d that steps the PR away from the singularity, i.e., αd > αm.The deviation on the reference trajectory continues in successive iterations until xm becomes non-singular, αm > limα.
In the case of Figure 4b, the two rows of ∆ι with the maximum value (max∆) are identified and saved in ire.The ∆ι is modified in the rows ire according to the columns of Mav, generating eight new possible ∆ι.The proper ∆ι is selected to ensure a feasible qind d and to decrease the absolute value of ∆ι.The returning procedure continues until ∆ι = 0.
Figure 3 shows that the proposed algorithm does not require complex optimisation problems, making it suitable for offline trajectory planning and combining with controllers for online Type M II singularity avoidance.For online applications, the algorithm is implemented by setting ts as the controller sample time and νd as the average feasible velocity for the PR under analysis.xm could be measured by a 3D tracking system or by estimation based on embedded encoders.In offline trajectory planning, the avoidance algorithm is applied at each sample of a discrete reference trajectory of Nptos samples (Nptos > 1).The reference trajectory could have different shapes, including a linear interpolation between two different desired points.The avoidance parameter ts is set to the sample time of the reference trajectory while νd is the average of the velocity reference trajectory.For offline trajectory planning, the measured signal xm is initialised with xr, and for the consequent iterations, xd is used as a feedback signal, i.e., xm = xd.
The value of limα is calculated previously to implement the Type II singularity avoidance algorithm.First, the fundamental movements of the PR are combined to generate a set of trajectories that approach a Type II singularity from different non-singular configurations.The application under study defines the fundamental movements of PR.Next, 70 % of the trajectories are executed until the PR under study loses control of the mobile platform.During the execution of trajectories, the pose reached by the PR must be measured.A set of minimum Θi, j and minimum Ωi, j is calculated based on the pose of the PR measured at each configuration of the trajectories executed.Subsequently, the limα is defined as the average of the set of minimum Θi, j for planar PR or the set of minimum Ωi, j for the spatial case.Next, the remaining 30 % of trajectories are executed until the PR reaches the limα.If the PR holds control over the mobile platform with the actuators locked, the setting of limα is finished.A detailed explanation of the experimental procedure to set the limα is presented in [32].
The Type II singularity avoidance algorithm presents the following advantages: • At each discretised instant time, only two actuators require modifications for singularity avoidance.
• The avoidance parameters νd and ts are set directly by the PR application.
• Low computational cost due to the absence of optimisation functions.The execution time of the avoidance algorithm is compared with existing algorithms in Sections 4 and 5.
The proposed avoidance algorithm is designed to modify the trajectory of two actuators because, in the closeness of a Type II singularity, at least two OTSs are parallel.The case of three OTSs aligned appears when the PR already reaches the singular configuration [32].However, if three OTSs become parallel in closeness to a singular configuration, the algorithm modifies the trajectory of the actuators by pairs.For example, consider a spatial PR at an arbitrary instant time.If the Ω1,2 and Ω1,3 are the minimum elements in αm the avoidance algorithm modifies the trajectory for actuators 1 and 2. Assuming that the Ω1,2 has increased for the next discretised instant time, the proposed algorithm modifies the trajectory on actuators 1 and 3.
It is important to emphasise that the proposed avoidance algorithm is limited to Type II singularities.It is because the minimum angles Ωi, j and Θi, j measure when two actuators transmit motion to the end-effector in the same direction, i.e., they detect the loss of controlled DOFs.The proposed avoidance algorithm is unsuitable for Type I singularities because, in this configuration, the PR retains control over all DOFs.

Case of study: 5R parallel mechanism
The 5R parallel mechanism is a planar PR with 2-DOF used for positioning a point P on a defined plane (see Figure 5).Point P is connected to the base by two limbs each of which consists of two links.The mechanism is named 5R because the links are connected by revolute joints where the two joints connected to the base are actuated.The kinematic model of the 5R mechanism is shown in Figure 5 where r11, r12, r21 and r22 are the length of the links.r10 and r20 are the horizontal distance to the connecting points A1 and A2 measured from O in the fixed frame O xyz , respectively.The active joints are defined as q11, q21, while the passive joints are q12, q22.In this research, the 5R mechanism has a symmetrical architecture where the inverse kinematic model considers the working mode + [36].The geometrical parameters of the 5R mechanism are shown in Table 1.The movement of the 5R mechanism is divided into $ ˆO1 and $ ˆO2 , which by using ( 7) and ( 8) define the indices Θ1,2 and Ω1,2, respectively.In the 5R mechanism, Ω1,2 = 0 because the movement takes place in the plane xy remaining the instantaneous screw axis in the z axis.
At point P, the $ ˆO1 represents the contribution of limb 1 to the motion of the point P, i.e.: $ ˆO1 = 0 0 1 ; vx vy 0 ( Considering the reciprocal product property and the unitary norm of the linear motion, the components vx, vy are calculated by solving the non-linear system: Due to the rotational actuator on limb 2 (q21) transmitting pure force to point P, the $ ˆT2 is: fT 2 stands for the unitary force vector in the direction of the link B2P represented on the fixed frame O xyz .Considering two moving frames attached to the links A2B2 and B2P, the fT 2 is calculated as follow: T where the rotation matrix R1 and 1 R2 are defined as: T The $ ˆO2 is calculated solving (15) replacing $ ˆT2 with the pure force screw $ ˆT1 as: with the force fT 1 in the direction of the link B1P defined as follow: fT 1 = cos q11 cos q12 − sin q11 sin q12 sin q11 cos q12 + cos q11 sin q12 0 ] T (21) Developing ( 17) with ( 18), fT 2 is: 0 0 * *

Offline planning results
The offline trajectory planning starts with generating a constant velocity trajectory on the plane xy with a Type II singularity in the middle.The description of the trajectory in configuration space is shown in Table 2. Next, the singularity avoidance algorithm is applied to the original trajectory to obtain the non-singular version of the trajectory.The 5R mechanism is driven by an Arduino Uno board at a rate of 200 Hz with a maximum working velocity of 29 • /s.Therefore, the singularity avoidance algorithm is set to ts = 20 ms and νd = 0.5 rad/s.For 5R mechanism α = Θ1,2, Figure 6a shows that the non-singular trajectory holds αd greater than limα while the original trajectory reaches a singularity at 2 s (αr = 0).The threshold for avoidance is set to 6 • (limα = 0.1047 rad) based on several simulation results.The Type II singularity avoidance is verified by analysing the ∥JD∥ of the original (∥JD∥r) and the nonsingular trajectory (∥JD∥d).Figure 6b shows that ∥JD∥d always differs from zero while ∥JD∥r reaches a Type II singularity at 2 s.In this research, the ∥JD∥ is not deeply analysed.However, [37] shows the expression of ∥JD∥ considering x = [xp yp] T .
Figure 7 shows that the proposed algorithm requires a maximum deviation of 1.2 • in the joint trajectories to avoid a Type II singularity.The offline trajectory planning was performed in MATLAB on a desktop PC with 32 GB of RAM.Table 3 compares the proposed algorithm with a constrained multi-objective (CMO) algorithm and roadmap (C-space) algorithm.In Table 3, tI represents the average elapsed time in each iteration, and tT is the total trajectory time.The results for the CMO algorithm were taken from [21] for offline trajectory planning in a planar PR.The results for the C-space algorithm were calculated based on the information reported in [22] for offline path planning in 3-RRR mechanism.According to Table 3, the proposed avoidance algorithm is the fastest during offline trajectory planning, with an average elapsed time of 0.5 ms.Thus, the Type II singularity avoidance algorithm is suitable for offline trajectory planning with a minimum modification of the original trajectory and low computational cost.1.2620 9.5 unspecified C-space [22] 0.0756 1 Intel Core i7 2.66 GHz

Case of study: 3UPS+RPU PR
The 3UPS+RPU PR is a 4-DOF mechanism for knee rehabilitation and diagnosis purposes.Figure 8 shows the actual prototype and its kinematic model.The 4-DOF of the PR are two translational movements (xm, zm) in the tibiofemoral plane, one rotation (ψ) around the coronal plane and one rotation (θ) around the tibiofemoral plane [38].These four DOFs are controlled by four linear actuators represented by q13, q23, q33 and q42, see Figure 8b.The designation 3UPS+RPU refers to the three external limbs with UPS configuration and the central one with RPU configuration (Figure 8b).The letters R, U, S and P represent revolute, universal, spherical and prismatic joints, respectively, and " " identifies the actuated joint.4. The movement of the 3UPS+RPU PR is divided into $ ˆO1 , $ ˆO2 , $ ˆO3 and $ ˆO4 that using (8) define the six indices Ω1,2 Ω1,3, Ω1,4, Ω2,3, Ω2,4 and Ω3,4.Analogously, (7) generates six indices Θ1,2, . . ., Θ3,4.Section 2.2 mentioned that for a spatial PR, the minimum angle Θi, j = 0 in some non-singular configurations.Figure 9a shows the angles Θ1,3 and Θ3,4 during a trajectory that goes from a non-singular configuration to a Type II singularity in the 4-DOF PR. Figure 9b shows the angles Ω1,3 and Ω3,4 for the same trajectory to a Type II singularity.This figure shows that the minimum angle Θi, j (Θ1,3) disappears for non-singular configurations, only the minimum angle Ωi, j (Ω3,4) has a continuous decrement in the proximity to singularity.Therefore, the closeness to a Type II singularity is measured by the minimum angle Ωi, j.The constraint singularities are not analysed because the 3UPS+RPU PR has mechanical constraints for linear motion on the Yf axis and the angular motion around the mobile axis Xm, i.e., the constraint wrench screws are  For an arbitrary point on the mobile platform of the 3UPS+RPU PR, wx is related to wz as follows: The expression in ( 23) is determined by taking the time derivatives of the rotation matrix between the moving and fixed frame f Rm.Considering the Euler Y-Z' angle convention f Rm is: Based on the reciprocal product, the relationship ( 23) and the unitary norm of the instantaneous screw axis, wx, wy, wz, vx and vz are calculated by solving the non-linear system: In this case, the actuators transmit force and moment to the mobile platform because the external limbs are not connected directly to the point Om.Thus the transmission wrench $ ˆT1 , $ ˆT2 and $ ˆT3 are defined as: where rO m A1 , rO m B1 and rO mC1 stand for the location vector between the point Om and the vertices A 1, B1 and C1, respectively.The central limb is connected to the point Om, so the $ ˆT4 is: fT is the unit vector of the force applied by each actuator with respect to the fixed frame.The direction of the fT 1 , fT 2 and fT 3 depends on the universal joint that connects the external limbs with the fixed platform, see Figure 8b.The direction of the fT 4 depends on the revolute joint that connects the central limb with the fixed frame.
The universal joint in limb 1 is represented by two orthogonal rotations q11 and q12 (Figure 8b).Thus, the fT 1 is defined as follows: with the rotation matrix R1 and 1 R2 as:  T The fT 2 is equal to the (32) with q21 and q22 instead of q11 and q12, respectively.The same replacement is performed to fT 3 , considering q31 and q32.
In the central limb, the fT 4 is defined by the orientation of the revolute joint (q41) as follows: T The $ ˆO2 is calculated based on (25) by modifying the reciprocal product as follows: The $ ˆO3 and $ ˆO4 are calculated with the analogous process of removing the reciprocal product related to $ ˆT3 and $ ˆT4 , respectively.Developing ( 30) with (31), fT 1 is:

Offline and online planning results
For offline trajectory planning, the original trajectory represents a knee rehabilitation exercise, specifically a hip flexion, where a singular configuration arises halfway.The description of the trajectory for hip flexion in configuration space is shown in Table 5.Then, the proposed Type II singularity avoidance algorithm is applied to generate a new non-singular trajectory.The actual 3UPS+RPU PR is driven by a PID controller in Robot Operating System 2 (ROS2) using the C++ programming language at a rate of 100 Hz.The maximum working velocity is 0.01 m/s because the actual PR works in knee rehabilitation.For these reasons, the singularity avoidance algorithm is adjusted to ts = 10 ms and νd = 0.01 m/s.For the 3UPS+RPU PR, α is calculated as the minimum element in vΩ = [Ω1,2 Ω1,3 . . .Ω3,4].For the hip flexion trajectory under analysis α = Ω3,4.Figure 10a verifies that the non-singularity trajectory holds αd > limα and the original trajectory decreases αr under limα.After several tests in the actual PR under analysis, the threshold for avoidance is set to 2 • (limα = 0.0349 rad).In addition, Figure 10b shows that JD for the non-singular trajectory ( JD d) is farther from zero than the original trajectory ( JD r).These results verify the effectiveness of the Type II singularity avoidance algorithm.In this research, the JD is only used for verifying the Type II singularity closeness.The reader could review [32] for the detailed expression of ∥JD∥ with x = [xm zm θ ψ] T .The avoidance algorithm deviates the original trajectory of the linear actuators q33 and q42 to generate a non-singular trajectory because limbs 3 and 4 are involved in the Type II singularity − (α = Ω3,4).Figure 11a presents the original trajectory for actuators 3 (q33 r ) and the non-singular trajectory q33 d generated by the proposed algorithm.Figure 11b presents the original (q42 r ) and non-singular (q42 d ) trajectory for actuator 4. In this case, the maximum ∆ι was [0 0 56 57] T .Figure 11 verifies that the proposed algorithm introduces a smooth deviation in the actuators 3 and 4 to avoid a Type II singularity with a maximum modification of 6 mm.In this case, the original and the non-singular trajectory are executed in the actual 3UPS+RPU PR while the location and orientation of the mobile platform are measured.The measurement is performed on the point Om by a 3D tracking system composed of 10 cameras, with an accuracy of 0.5 mm [33].In Figure 12a, the height measured by the 3D tracking system is plotted for both trajectories.An external perturbation occurs at instant t = 18s where the original trajectory (zm r ) yields to the force and moves unexpectedly.In contrast, the trajectory modified by the proposed algorithm (zm d ) remains stiff.Moreover, Figure 12b shows the orientation around the tibiofemoral plane for the original (θr) and modified trajectory (θd).
During the offline trajectory planning, the proposed Type II singularity avoidance algorithm has modified only the trajectory of two actuators with a maximum modification of 6 mm.The offline trajectory planning is implemented in MATLAB on a desktop PC with a processor Core i7 3.7 GHz.In this case, the avoidance algorithm takes on average 1 ms in each iteration.Note that although the proposed algorithm is applied in a spatial case, the execution time is lower than in other algorithms for the planar case, see Table 3.Therefore, these results verify that the Type II singularity avoidance algorithm requires minimum deviation from the original trajectory with low computational cost.
For online trajectory planning, the original trajectory is a hip flexion movement used previously in offline trajectory planning with a different starting location, see Table 6.In this case, the proposed Type II singularity avoidance algorithm analyses each sample of the original trajectory.Then, the non-singular trajectory generated is sent to the PID controller.The PID controller combined with the avoidance algorithm is implemented in ROS2 using the C++ programming language at a rate of 100 Hz.The signal xm required by the Type II singularity avoidance al-  gorithm is provided by a 3D tracking system at a rate of 120 Hz.As in the offline trajectory planning, the singularity avoidance algorithm is set to ts = 10 ms and νd = 0.01 m/s. Figure 13a presents the original trajectory for the actuator 3 (q33 r ) and the non-singular trajectory q33 d calculated online.Figure 13b presents the original reference for the actuator 4 (q42 r ) and the non-singular trajectory q42 d .This figure verifies that the proposed algorithm introduces a maximum modification of 7 mm in actuators 3 and 4 during an online Type II singularity avoidance.
Figure 14a presents the height for the original (zm r ) and the height calculated online by the proposed algorithm (zm d ). Figure 14b shows the orientation around the tibiofemoral plane for the original (θr) and the orientation modified by the proposed algorithm (θd).Figure 14 shows that the original trajectory on the configuration space is modified maximum 7 mm and 1.5 • .The Type II singularity avoidance algorithm for online trajectory planning is implemented in an industrial PC with a processor Core i7 3.4 GHz.The proposed avoidance algorithm requires on average 3.86 ms at each iteration during the online trajectory planning, and the PID controller is executed in 2 ms.If the controller is executed every 10 ms, the avoidance algorithm employs 38.6 % of the control period and the PID controller 20 %, i.e., 41.4 % of the control period is free.Thus, these results verify that the Type II singularity avoidance algorithm is suitable for online trajectory planning.

Conclusions
Based on the angles between the linear part Θi, j and the angular part Ωi, j of two OTSs, a Type II singularity avoidance algorithm has been developed for planar and spatial PRs.The singularity avoidance is achieved by modifying the trajectory of the two actuators identified by the minimum angles Θi, j and Ωi, j for the planar and spatial case, respectively.The Type II avoidance algorithm has been successfully applied in offline trajectory planning for a symmetrical 5R mechanism (planar case) and a 3UPS+RPU PR (spatial case).Moreover, the proposed avoidance algorithm has been applied in online trajectory planning for the 3UPS+RPU PR.The 3UPS+RPU PR has been analysed without human interaction to avoid risking the integrity of the patient.Table 7 summarises the results of the Type II avoidance algorithm during offline and online trajectory planning.In Table 7, tI represents the execution time in each iteration, ∆q stands for the maximum modification in the trajectory of actuators, and ∆q˙ is the average deviation in the velocity reference in joint space.The Type II singularity avoidance algorithm requires 1 ms in each iteration during offline trajectory planning of spatial case, see Table 7.The proposed algorithm was compared with a constrained multi-objective (CMO) algorithm and roadmap (C-space) algorithm for offline trajectory in planar PRs.The proposed avoidance algorithm applied to a 4-DOF PR is faster than CMO and C-space algorithms applied to planar cases.Thus, the low computational cost of the Type II singularity avoidance algorithm is verified.During the online trajectory planning for a 3UPS+RPU PR, the Type II avoidance algorithm requires 3.86 ms for execution.Considering that the controller is executed at every 10ms and the PID law takes 2 ms, there is 4.41 ms free at each iteration.Therefore, the Type II singularity avoidance algorithm is suitable for online applications in the 3UPS+RPU PR.
In offline trajectory planning with a 5R mechanism, the proposed avoidance algorithm introduced a maximum deviation of 2 • that is imperceptible for the planar PR under study.The velocity trajectory was modified 0.58 • /s, i.e., 2 % of the working velocity.In offline trajectory planning with the 3UPS+RPU PR, the trajectories of the two actuators were modified by a maximum of 6 mm, and the velocity profile changed on average 0.24 mm / s (2.4 % of the working velocity).Considering that the 3UPS+RPU PR is applied for knee rehabilitation, 6 mm is a minimum deviation compared with the range of movement of the human leg.In addition, the proposed algorithm modifies the trajectory of two actuators with a maximum deviation of 7 mm during the online trajectory planning in the 3UPS+RPU PR.Thereby, the proposed algorithm requires a minimum deviation on two actuators to avoid a Type II singularity during offline and online trajectory planning for the 5R and 3UPS+RPU PRs.The minimum deviation on the original trajectory and the low computation cost make the Type II singularity avoidance algorithm suitable for knee rehabilitation assisted by the 3UPS+RPU PR.Note that the proposed avoidance algorithm modifies the trajectory of two actuators because in the proximity to a Type II singularity at least two actuators transmit motion in the same direction.Three actuators contributing in the same direction appear when the Type II singularity is already reached.
The proposed Type II avoidance algorithm requires little tuning for implementation.The proposed avoidance algorithm is tuned by three comprehensible parameters: the sample time (ts), the avoidance velocity (vd) and the limit for the proximity to a singularity (limα).The ts is defined by the controller sample time.The vd is set by the maximum working velocity of the actuators according to the PR application.The limα is calculated by trial and error with trajectories with a Type II singularity as the final location.The experimental setting of limα allows the incorporation of non-modelled effects such as join clearances and manufacturing errors which increase the accuracy of the avoidance algorithm in real implementations.In addition, the Type II avoidance algorithm only requires the previous reference location during offline trajectory planning.This suppresses the necessity of prior information about the workspace of the PR.The possibility to avoid Type II singularity online reduces the optimisation procedures during the design of PRs and allows to integrate PRs into human interaction tasks with minimum risks.
This research extends the application of the proposed avoidance algorithm for spatial PRs presented by the authors in [34] to planar PRs.In addition, for the first time, the minimum angle Θi, j is applied as a proximity detector of Type II singularities for a planar PR during offline trajectory planning.The analysis of the angle between the linear part of two OTSs (Θi, j) complements the research developed for proximity detection to a Type II singularity based on the angle Ωi, j [32].
In future work, the proposed algorithm is going to be combined with a force controller to perform active and passive exercises for knee rehabilitation using the 3UPS+RPU PR.The force controller requires an online Type II singularity avoidance algorithm because the user could drive the PR to a singular configuration by accident.In this case, the actual location of the PR should be measured by a redundant 3D tracking system or by solving the Forward kinematics based on embedded encoders.The implementation of the proposed avoidance algorithm was limited to offline trajectory planning for the 5R mechanism and the 3UPS+RPU PR.Moreover, the implementation of the index Θi, j in online trajectory planning has not been analysed.Therefore, the Type II singularity avoidance algorithm should be tested in PRs with different architectures to generalise the features discussed in this research.
and JD become rank deficient.This configuration is only possible for specific values of geometric parameters.

Figure 1 :
Figure 1: 5R parallel mechanism in singular configuration (a) Type I (b) Type II.

Figure 2 :
Figure 2: Motion decomposition for a PR.

Figure 3 :
Figure 3: Block diagram for Type II singularity avoidance algorithm.

Figure 9 :
Figure 9: Angles (a) Θi, j (b) Ωi, j during a trajectory approaching a Type II singularity.The contribution to the motion of the limb 1 $ ˆO1 in point Om with respect to the fixed frame

Figure 13 :
Figure 13: Results of online trajectory planning for the actuator in limb (a) 3 (b) 4.

Figure 14 :
Figure 14: Results of online trajectory planning: (a) location on zm (b) rotation around θ.

Table 1 :
Geometrical parameters of the 5R mechanism in meters

Table 2 :
Description of the trajectory for offline planning in the 5R mechanism.

Table 3 :
Comparative results of avoidance algorithm for offline trajectory planning in planar PRs.

Table 5 :
Description of the trajectory for offline planning in the 4-DOF PR.

Table 6 :
Description of the trajectory for online planning in the 4-DOF PR.

Table 7 :
Results for the proposed avoidance algorithm for planar and spatial PRs.