# IK numerical vs analytical solutions and singularities

Currently I'm using the Robotics-Toolbox python library by Peter Corke to perform inverse kinematics calculations for a 6 DOF (non-spherical wrist) robot arm. I'm using the robotics-toolbox ctraj function to create a path for the arm to follow. The IK are then performed on each 'point' along the path for the joint angles to be found. I'm getting a lot of singularity errors and believe it could be due to the nature of using a numerical solution. I also understand there are tools online that provide analytical solutions for an arm such as the pyikfast tool that generates an analytical solution using the IKFast Kinematics Solver.

How does the performance compare when creating trajectories using a numerical solution approach such as the Robotics-Toolbox one and an analytical solution such as IKFast. I understand the speed of analytical solutions are much better than numerical ones, but what about frequency of failing to find solutions for general paths?

Secondly, am I running into these IK errors because numerical solutions can be lackluster or can the consistency of finding viable solutions be good with numerical solutions? In other words, maybe I could improve my code and deal with finding IK errors and planning trajectories 'around' them and the issue isn't the numerical solution at all but with my implementation. I'd like advice on what kind of methods are preferred by the community.

I'm getting a lot of singularity errors and believe it could be due to the nature of using a numerical solution.

Singularities are inherent to the mechanical structure of the robot. At a singular configuration there are end-effector angular or linear velocities that can't be produced by any set of joint velocities. This is a nice resource.

The choice of a numerical or analytical technique for solutions should not be the problem. The singularity still exists at a given robot configuration and needs to be avoided.

If you can tolerate significant deviation from your desired path, I've found that the selectively damped least-squares (SDLS) IK algorithm is good at "steering around" singularities and keeping robot motions feasible while tracking the path accurately well away from the singular configurations. Limiting the joint angle updates to small values also helps prevent joint-space jumping from one IK solution to another, which also improves feasibility. I don't know of a public implementation of SDLS, but if you've got a library that's giving you the end-effector Jacobian and that computes the singular value decomposition for you, it's not too difficult to implement.

I don't know that much about precise path tracking with singularity avoidance, but you can look into dynamic control and other more sophisticated control approaches. There's a classic example of singularity crossing in five-bar parallel manipulators, where you lose a degree of freedom when the two moving passive arms that meet at the end-effector line up, like the first trajectory in this video.

I've not explored this kind of control for 6DOF arms, so maybe others can say more about real-world feasibility of singularity crossing without sacrificing path/trajectory tracking accuracy (especially where you can only command joint position or velocity, not joint torques).

The practical safety issue of large joint velocities that can arise near a singularity often will be as much or more of a limiting factor than precise crossing of the singularity itself if you're trying to do path or especially trajectory tracking. A good example is tracking a straight line that passes close to the base of a robot arm, where the wrist and vertical shoulder pan joint rotate in opposite directions very rapidly.

The "inner workspace limit" animation for a UR robot here is an example, where the elbow needs to swing around wildly in order to accomplish a simple straight-line task-space motion near the base of the robot.