IKSolution - as IK Solution dataclass
- class IKSolution(q, success, iterations=0, searches=0, residual=0.0, reason='')[source]
A dataclass for representing an IK solution
- q
The joint coordinates of the solution (ndarray). Note that these will not be valid if failed to find a solution. The shape is (n,) for a single pose, or (N, n) for a trajectory of N poses
- Type:
Changed in version 1.0.3: Added IKSolution dataclass to replace the IKsolution named tuple
Changed in version 1.4.2: Added
__getitem__(positional indexing matching__iter__’s order) and a__repr__matching__str__, soik_LM/ik_NR/ik_GN(which now also returnIKSolution, seeik_LM()) remain compatible with code that indexed the old bare tuple returnChanged in version 1.5.0: An
IKSolutionis now a sequence of the rows ofq, one per pose:len(sol)is the number of poses (1 for a single pose), andfor q in solandsol[i]give the joint vector of each pose. This replaces iterating over the fields, soq, success, ... = solandsol[1]no longer work, use the attributes orastuple. AnIKSolutionis true ifsuccessis true. Printing a trajectory shows the number of poses and abbreviates a longq, and the residual of a failed solution is no longer rounded to zero.The solution is a sequence of the rows of
q, one per pose.>>> import numpy as np >>> import roboticstoolbox as rtb >>> panda = rtb.models.Panda() >>> T = panda.fkine(panda.qr + np.array([[0], [0.05], [0.1]])) >>> sol = panda.ikine_LM(T, q0=panda.qr, seed=0) >>> len(sol) 3 >>> sol[2] array([ 0.098 , -0.2004, 0.1018, -2.1014, 0.1013, 2.1012, 0.8844]) >>> sol[:2] array([[ 0. , -0.3 , 0. , -2.2 , 0. , 2. , 0.7854], [ 0.0491, -0.25 , 0.0509, -2.1501, 0.0503, 2.05 , 0.8352]]) >>> bool(sol) == sol.success True
A single pose is treated as one row, so
len(sol)is 1 andsol[0]isq.sol[i]is the same asnp.atleast_2d(sol.q)[i], it does not return anIKSolutionsincesuccess,residualandreasonare values for the whole solution, not for each pose.