A General method for a closed-form solution to robot kinematics problems