Trajectory planning of an end-effector for path with loop