diff --git a/src/roboticstoolbox/ets/ETS.py b/src/roboticstoolbox/ets/ETS.py index 8e4f669dc..7f92cbd93 100644 --- a/src/roboticstoolbox/ets/ETS.py +++ b/src/roboticstoolbox/ets/ETS.py @@ -426,7 +426,7 @@ def insert( elif isinstance(value, ETS): for j, et in enumerate(value): self._data.insert(index + j, et) - self._fknm_stale = True + self._changed() def fkine( self, @@ -1011,6 +1011,10 @@ def partial_fkine0(self, q: ArrayLike, n: int) -> NDArray: where the Jacobian is the first partial derivative and the Hessian is the second. + The result has shape ``(self.n,) * (n - 1) + (6, self.n)``. Each + leading axis differentiates with respect to a joint in sequence order; + the last two axes have the same ordering as :meth:`jacob0`. + .. rubric:: Examples The following example makes a ``Panda`` robot object, and solves for the @@ -1135,6 +1139,11 @@ def add_pdi(pdi: Any) -> Any: rot = np.zeros(3) trn = np.zeros(3) + # H[k, :3, j] = w[min(j, k)] x v[max(j, k)]. + # H[k, 3:, j] = w[k] x w[j] only when k precedes j: + # a downstream joint cannot change an upstream joint axis. + first, last = sorted(count[:2]) + # This loop calculates a single column ([trn, rot]) # of the tensor for dT(x) for j in range(len(indices)): @@ -1158,11 +1167,14 @@ def add_pdi(pdi: Any) -> Any: col0_rot = pdr0[tuple(idx0_slices) + (slice(3, 6), idx0_n)] col1_rot = pdr1[tuple(idx1_slices) + (slice(3, 6), idx1_n)] - # Use our indices to select the translational column from pdr1 - col1_trn = pdr1[tuple(idx1_slices) + (slice(0, 3), idx1_n)] - # Perform the cross product as described in the maths above - rot += np.cross(col0_rot, col1_rot) + if count[1] < count[0]: + rot += np.cross(col0_rot, col1_rot) + + # Apply the same product rule to the ordered translational + # Hessian factors, retaining each factor's derivative indices. + col0_rot = pdr0[tuple(idx0_slices) + (slice(3, 6), first)] + col1_trn = pdr1[tuple(idx1_slices) + (slice(0, 3), last)] trn += np.cross(col0_rot, col1_trn) pd[tuple(np.flip(count[1:])) + (slice(0, 3), count[0])] = trn diff --git a/src/roboticstoolbox/ets/ETS2.py b/src/roboticstoolbox/ets/ETS2.py index 8453499ee..9652d39cd 100644 --- a/src/roboticstoolbox/ets/ETS2.py +++ b/src/roboticstoolbox/ets/ETS2.py @@ -268,7 +268,7 @@ def insert( elif isinstance(arg, ETS2): for j, et in enumerate(arg): self._data.insert(i + j, et) - self._fknm_stale = True + self._changed() def fkine( self, @@ -336,6 +336,7 @@ def eval( ``T = ets.eval(q)`` evaluates forward kinematics for the robot at joint configuration ``q``, returning the raw ndarray. + An empty sequence evaluates to the identity, with base and tool applied. **Trajectory operation**: If ``q`` has multiple rows (mxn), it is considered a trajectory and the result is an ndarray of shape (m,3,3). @@ -356,7 +357,7 @@ def eval( q = self._resolve_q(q, allow_trajectory=True) l, _ = q.shape - end = self[-1] + end = self[-1] if self.m else None if base is None: bases = None @@ -376,16 +377,20 @@ def eval( else: # pragma: nocover tools = tool + T: NDArray if l > 1: T = np.zeros((l, 3, 3), dtype=object) else: T = np.zeros((3, 3), dtype=object) for k, qk in enumerate(q): - link = end # start with last link - - jindex = 0 if link.jindex is None and link.isjoint else link.jindex - Tk = link.A(qk[jindex]) + if end is None: + # Constant folding can leave an empty identity sequence. + Tk = np.eye(3) + else: + link = end # start with last link + jindex = 0 if link.jindex is None and link.isjoint else link.jindex + Tk = link.A(qk[jindex]) if tools is not None: Tk = Tk @ tools @@ -560,6 +565,10 @@ def ikine_LM( that lies outside the joint limits is rejected when ``joint_limits`` is True, and the search continues. + Coordinates follow :meth:`fkine`: when explicit joint indices permute + ``0..n-1``, ``q0`` and the returned ``q`` use joint-index order. For a + sparse subchain they use compact ET order. + **Trajectory operation**: for a trajectory of N poses the solver is run once per pose, each from the same starting points, and the returned ``q`` has shape (N, n). ``success`` is True only if every pose was @@ -617,7 +626,12 @@ def ikine_LM( ) n = self.n - qlim = self.qlim + # FK interprets a full 0..n-1 vector in joint-index order, whereas + # limits, joint types and Jacobian columns are stored in ET order. + order = np.arange(n) + if np.array_equal(np.sort(self.jindices), order): + order = np.argsort(self.jindices) + qlim = self.qlim[:, order] if not np.all(np.isfinite(qlim)): bad = np.flatnonzero(~np.all(np.isfinite(qlim), axis=0)) @@ -639,7 +653,7 @@ def ikine_LM( rows = min(q0a.shape[0], slimit) starts[:rows] = q0a[:rows] - revolute = np.array([joint.isrotation for joint in self.joints()]) + revolute = np.array([joint.isrotation for joint in self.joints()])[order] def solve_one(T: NDArray) -> IKSolution: theta_d = np.arctan2(T[1, 0], T[0, 0]) @@ -692,7 +706,7 @@ def error(q: NDArray) -> tuple[NDArray, float]: i += 1 - J = self.jacob0(q) + J = self.jacob0(q)[:, order] A = J.T @ We @ J + k * E * np.eye(n) g = J.T @ We @ e diff --git a/src/roboticstoolbox/ets/_ETS.py b/src/roboticstoolbox/ets/_ETS.py index 54aef4650..641cb73e9 100644 --- a/src/roboticstoolbox/ets/_ETS.py +++ b/src/roboticstoolbox/ets/_ETS.py @@ -46,7 +46,7 @@ def _dirties_fknm(func: _F) -> _F: @wraps(func) def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any: result = func(self, *args, **kwargs) - self._fknm_stale = True + self._changed() return result return wrapper # type: ignore[return-value] @@ -611,7 +611,7 @@ def data(self) -> list[ETT]: @data.setter def data(self, new_data: list[ETT]) -> None: self._data = new_data - self._fknm_stale = True + self._changed() def inv(self) -> Self: r""" @@ -731,7 +731,8 @@ def random_q(self, i: int = 1) -> NDArray: :rtype: ndarray(n,) or ndarray(i,n) Generates a random q vector within the joint limits defined by - ``self.qlim``. + ``self.qlim``, in the coordinate order accepted by :meth:`fkine`. + A subchain with sparse joint indices returns compact coordinates. .. rubric:: Examples @@ -745,18 +746,14 @@ def random_q(self, i: int = 1) -> NDArray: """ - if i == 1: - q = np.zeros(self.n) - - for i in range(self.n): - q[i] = uniform(self.qlim[0, i], self.qlim[1, i]) - - else: - q = np.zeros((i, self.n)) + qlim = self.qlim + shape = (self.n,) if i == 1 else (i, self.n) + q = uniform(qlim[0], qlim[1], size=shape) - for j in range(i): - for i in range(self.n): - q[j, i] = uniform(self.qlim[0, i], self.qlim[1, i]) + # A full chain consumes global coordinates, even when its joints occur + # in a different order. Sparse subchains consume compact coordinates. + if self.n and np.array_equal(np.sort(self.jindices), np.arange(self.n)): + q[..., self.jindices] = q.copy() return q diff --git a/src/roboticstoolbox/robot/BaseRobot.py b/src/roboticstoolbox/robot/BaseRobot.py index 4eea5076c..ad6dacead 100644 --- a/src/roboticstoolbox/robot/BaseRobot.py +++ b/src/roboticstoolbox/robot/BaseRobot.py @@ -1861,7 +1861,8 @@ def random_q(self) -> Any: Return a random joint configuration The value for each joint is uniform randomly distributed between the - limits set for the robot. + limits set for the robot. Values are addressed by joint index, as in + the robot's configuration vector. .. rubric:: Notes @@ -1876,7 +1877,10 @@ def random_q(self) -> Any: qlim = self.qlim if np.any(np.isnan(qlim)): raise ValueError("some joint limits not defined") # pragma nocover - return np.random.uniform(low=qlim[0, :], high=qlim[1, :], size=(self.n,)) + q = np.empty(self.n) + indices = [link.jindex for link in self.links if link.jindex is not None] + q[indices] = np.random.uniform(low=qlim[0, :], high=qlim[1, :], size=(self.n,)) + return q def hierarchy(self) -> None: """ diff --git a/tests/test_ETS.py b/tests/test_ETS.py index 72b3746c3..68f66f75d 100644 --- a/tests/test_ETS.py +++ b/tests/test_ETS.py @@ -2039,2430 +2039,14 @@ def test_partial_fkine(self): q1 = np.array([1.4, 0.2, 1.8, 0.7, 0.1, 3.1, 2.9]) - ans = np.array( + # Differentiate the independently implemented Hessian. The previous + # literal tensor reproduced the old recursion's incorrect downstream + # angular dependencies and asymmetric position derivatives. + step = 1e-5 + ans = np.stack( [ - [ - [ - [ - 1.61683957e-01, - -1.07925929e-01, - 3.41453006e-02, - -3.35029257e-01, - 1.07195463e-02, - -1.03187865e-01, - 0.00000000e00, - ], - [ - -4.46822947e-01, - -6.25741987e-01, - -4.16474664e-01, - 8.04745724e-02, - -7.78257566e-02, - 1.17720983e-02, - 0.00000000e00, - ], - [ - -3.17334834e-18, - 1.10026604e-17, - 2.42699171e-18, - 1.47042021e-17, - 2.53075280e-19, - 4.65397353e-18, - 0.00000000e00, - ], - [ - 0.00000000e00, - 9.85449730e-01, - -3.37672585e-02, - 6.16735653e-02, - -6.68449878e-01, - 1.35361558e-01, - -6.37462344e-01, - ], - [ - 0.00000000e00, - -1.69967143e-01, - -1.95778638e-01, - -9.79165111e-01, - -1.84470262e-01, - -9.82748279e-01, - -1.83758244e-01, - ], - [ - 0.00000000e00, - -4.38924163e-17, - 3.44245060e-18, - 6.56556980e-18, - 3.26553464e-17, - 3.19571960e-18, - 3.12169108e-17, - ], - ], - [ - [ - -7.73258609e-18, - 2.31853293e-01, - 8.08253690e-02, - 5.06596965e-01, - 9.83518983e-03, - 1.99678676e-01, - 0.00000000e00, - ], - [ - 5.05851038e-17, - -3.99892968e-02, - -1.39404950e-02, - -8.73761859e-02, - -1.69634134e-03, - -3.44399243e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - -1.38777878e-17, - -1.38777878e-17, - 5.55111512e-17, - 0.00000000e00, - -1.38777878e-17, - 0.00000000e00, - ], - [ - -9.85449730e-01, - 0.00000000e00, - -9.65806345e-01, - 1.90658563e-01, - -7.10033786e-01, - 1.24194307e-01, - -7.37360525e-01, - ], - [ - 1.69967143e-01, - 0.00000000e00, - 1.66579116e-01, - -3.28841647e-02, - 1.22464303e-01, - -2.14206274e-02, - 1.27177529e-01, - ], - [ - 4.38924163e-17, - 0.00000000e00, - 4.85722573e-17, - 2.77555756e-17, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - ], - ], - [ - [ - 1.58461042e-01, - -1.13719243e-01, - 3.06951191e-02, - -3.45709946e-01, - 1.01688580e-02, - -1.07973135e-01, - 0.00000000e00, - ], - [ - -4.37916236e-01, - -6.59330946e-01, - -4.24230421e-01, - -2.17748413e-02, - -7.82283735e-02, - -2.81325889e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 1.38777878e-17, - 1.73472348e-17, - 0.00000000e00, - 6.07153217e-18, - 0.00000000e00, - ], - [ - 3.37672585e-02, - 9.65806345e-01, - 0.00000000e00, - 5.39111251e-02, - -6.30795483e-01, - 1.28407717e-01, - -5.99489263e-01, - ], - [ - 1.95778638e-01, - -1.66579116e-01, - 0.00000000e00, - -9.97525009e-01, - -3.97312016e-02, - -9.87832342e-01, - -3.36043908e-02, - ], - [ - -3.44245060e-18, - -4.85722573e-17, - 0.00000000e00, - 0.00000000e00, - 4.16333634e-17, - 0.00000000e00, - 3.46944695e-17, - ], - ], - [ - [ - -3.12815864e-02, - 3.53911729e-02, - -1.54782657e-03, - 9.65242924e-02, - -1.45842251e-03, - 3.24608603e-02, - 0.00000000e00, - ], - [ - 8.64484696e-02, - -1.09310078e-01, - 2.66964059e-04, - -5.18935898e-01, - 5.28476698e-03, - -2.00682834e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.38777878e-17, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - ], - [ - -6.16735653e-02, - -1.90658563e-01, - -5.39111251e-02, - 0.00000000e00, - 8.48905588e-02, - -1.84162966e-02, - 7.71850655e-02, - ], - [ - 9.79165111e-01, - 3.28841647e-02, - 9.97525009e-01, - 0.00000000e00, - 7.41195745e-01, - 6.67336352e-02, - 7.68210453e-01, - ], - [ - -6.56556980e-18, - -2.77555756e-17, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -2.77555756e-17, - ], - ], - [ - [ - 1.16496122e-01, - -2.35033157e-01, - -3.02231459e-02, - -5.85029103e-01, - 1.05221866e-03, - -2.09794626e-01, - 0.00000000e00, - ], - [ - -3.21943757e-01, - -4.94259600e-01, - -3.15207311e-01, - -3.68485664e-02, - -5.79159088e-02, - -2.88966443e-02, - 0.00000000e00, - ], - [ - 1.38777878e-17, - 0.00000000e00, - 1.38777878e-17, - 0.00000000e00, - 0.00000000e00, - 1.38777878e-17, - 0.00000000e00, - ], - [ - 6.68449878e-01, - 7.10033786e-01, - 6.30795483e-01, - -8.48905588e-02, - 0.00000000e00, - 1.32869389e-02, - 4.08633244e-02, - ], - [ - 1.84470262e-01, - -1.22464303e-01, - 3.97312016e-02, - -7.41195745e-01, - 0.00000000e00, - -7.31335770e-01, - 5.62842325e-03, - ], - [ - -3.26553464e-17, - 0.00000000e00, - -4.16333634e-17, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - ], - ], - [ - [ - -2.03767136e-02, - 4.54491056e-02, - 6.79892209e-03, - 1.11809337e-01, - 0.00000000e00, - 4.04324654e-02, - 0.00000000e00, - ], - [ - 5.63122241e-02, - -1.52356663e-01, - -2.81163100e-02, - -5.15350265e-01, - -5.20417043e-18, - -2.00614904e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - -5.55111512e-17, - 1.38777878e-17, - -1.38777878e-17, - 3.46944695e-18, - 0.00000000e00, - ], - [ - -1.35361558e-01, - -1.24194307e-01, - -1.28407717e-01, - 1.84162966e-02, - -1.32869389e-02, - 0.00000000e00, - -2.09458434e-02, - ], - [ - 9.82748279e-01, - 2.14206274e-02, - 9.87832342e-01, - -6.67336352e-02, - 7.31335770e-01, - 0.00000000e00, - 7.58497864e-01, - ], - [ - -3.19571960e-18, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - ], - ], - [ - [ - 1.20979654e-01, - -2.30735324e-01, - -2.67347299e-02, - -5.78389562e-01, - 1.65874227e-03, - -2.06377139e-01, - 0.00000000e00, - ], - [ - -3.34334256e-01, - -5.11444043e-01, - -3.26697847e-01, - -3.42509562e-02, - -6.00669280e-02, - -2.84259272e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 6.93889390e-18, - 0.00000000e00, - 0.00000000e00, - 1.38777878e-17, - 0.00000000e00, - ], - [ - 6.37462344e-01, - 7.37360525e-01, - 5.99489263e-01, - -7.71850655e-02, - -4.08633244e-02, - 2.09458434e-02, - 0.00000000e00, - ], - [ - 1.83758244e-01, - -1.27177529e-01, - 3.36043908e-02, - -7.68210453e-01, - -5.62842325e-03, - -7.58497864e-01, - 0.00000000e00, - ], - [ - -3.12169108e-17, - 0.00000000e00, - -3.46944695e-17, - 2.77555756e-17, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - ], - ], - ], - [ - [ - [ - -1.07925929e-01, - 2.31853293e-01, - 8.08253690e-02, - 5.06596965e-01, - 9.83518983e-03, - 1.99678676e-01, - 0.00000000e00, - ], - [ - -6.25741987e-01, - -3.99892968e-02, - -1.39404950e-02, - -8.73761859e-02, - -1.69634134e-03, - -3.44399243e-02, - 0.00000000e00, - ], - [ - 1.10026604e-17, - -1.03268599e-17, - -3.60000174e-18, - -2.25640783e-17, - -4.38064199e-19, - -8.89378659e-18, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - -9.65806345e-01, - 1.90658563e-01, - -7.10033786e-01, - 1.24194307e-01, - -7.37360525e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 1.66579116e-01, - -3.28841647e-02, - 1.22464303e-01, - -2.14206274e-02, - 1.27177529e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 4.30174903e-17, - -8.49202631e-18, - 3.16252545e-17, - -5.53167558e-18, - 3.28424010e-17, - ], - ], - [ - [ - 1.26880993e-17, - -1.07925929e-01, - -6.87706209e-02, - 3.80041092e-03, - -1.27256780e-02, - -1.00921994e-03, - 0.00000000e00, - ], - [ - 7.35641246e-17, - -6.25741987e-01, - -3.98724063e-01, - 2.20343406e-02, - -7.37820011e-02, - -5.85133986e-03, - 0.00000000e00, - ], - [ - -1.24900090e-16, - 2.35276631e-01, - 8.20187641e-02, - 5.14076923e-01, - 9.98040745e-03, - 2.02626953e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - -3.37672585e-02, - -1.62222678e-01, - -5.02084106e-02, - -1.60694077e-01, - -4.91939581e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - -1.95778638e-01, - -9.40548220e-01, - -2.91102526e-01, - -9.31685572e-01, - -2.85220849e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - -9.80066578e-01, - 1.93473657e-01, - -7.20517510e-01, - 1.26028049e-01, - -7.48247732e-01, - ], - ], - [ - [ - -1.70045802e-02, - -4.16333634e-17, - 3.52650006e-03, - -1.16102817e-02, - 8.03370202e-04, - -3.50123667e-03, - 0.00000000e00, - ], - [ - -5.81147164e-01, - 3.81639165e-17, - 2.04462373e-02, - -6.73150634e-02, - 4.65784701e-03, - -2.02997631e-02, - 0.00000000e00, - ], - [ - 3.56738040e-01, - -9.54097912e-17, - 1.02353729e-01, - -3.36978765e-01, - 2.33171516e-02, - -1.01620481e-01, - 0.00000000e00, - ], - [ - 9.65806345e-01, - 3.37672585e-02, - 0.00000000e00, - 7.67199187e-03, - -2.11845605e-02, - 1.01445937e-02, - -2.01575078e-02, - ], - [ - -1.66579116e-01, - 1.95778638e-01, - 0.00000000e00, - 4.44813167e-02, - -1.22825619e-01, - 5.88171749e-02, - -1.16870886e-01, - ], - [ - -4.30174903e-17, - 9.80066578e-01, - 0.00000000e00, - 2.22673179e-01, - -6.14864240e-01, - 2.94438391e-01, - -5.85054890e-01, - ], - ], - [ - [ - 4.47344513e-01, - -2.45209972e-02, - 1.31697505e-03, - -5.49139714e-02, - 9.68203187e-04, - -1.70497322e-02, - 0.00000000e00, - ], - [ - 2.75381501e-01, - -1.42169890e-01, - 7.63566820e-03, - -3.18384821e-01, - 5.61352949e-03, - -9.88523645e-02, - 0.00000000e00, - ], - [ - 5.60528715e-01, - 5.34553435e-02, - -1.57068039e-03, - 1.83321890e-01, - -2.33543881e-03, - 6.60980339e-02, - 0.00000000e00, - ], - [ - -1.90658563e-01, - 1.62222678e-01, - -7.67199187e-03, - 0.00000000e00, - -1.13181076e-01, - 1.22260298e-02, - -1.08016484e-01, - ], - [ - 3.28841647e-02, - 9.40548220e-01, - -4.44813167e-02, - 0.00000000e00, - -6.56210717e-01, - 7.08850988e-02, - -6.26267014e-01, - ], - [ - 8.49202631e-18, - -1.93473657e-01, - -2.22673179e-01, - 0.00000000e00, - -4.23235448e-02, - -2.94908598e-02, - -5.45085339e-02, - ], - ], - [ - [ - 5.42292833e-02, - 6.77094759e-02, - 4.83881552e-02, - -1.96475479e-02, - 9.17823507e-03, - -4.57282155e-03, - 0.00000000e00, - ], - [ - -4.03096507e-01, - 3.92571668e-01, - 2.80548897e-01, - -1.13914198e-01, - 5.32143397e-02, - -2.65126876e-02, - 0.00000000e00, - ], - [ - 3.57094795e-01, - -1.47605469e-01, - 2.37914951e-02, - -5.70253726e-01, - 1.08807101e-02, - -2.01830577e-01, - 0.00000000e00, - ], - [ - 7.10033786e-01, - 5.02084106e-02, - 2.11845605e-02, - 1.13181076e-01, - 0.00000000e00, - 1.15898581e-01, - 8.90683876e-04, - ], - [ - -1.22464303e-01, - 2.91102526e-01, - 1.22825619e-01, - 6.56210717e-01, - 0.00000000e00, - 6.71966493e-01, - 5.16408154e-03, - ], - [ - -3.16252545e-17, - 7.20517510e-01, - 6.14864240e-01, - 4.23235448e-02, - 0.00000000e00, - 1.37396662e-01, - 3.93121050e-02, - ], - ], - [ - [ - 4.36046879e-01, - -3.24238553e-02, - -3.87838234e-03, - -5.41101044e-02, - 0.00000000e00, - -1.69651356e-02, - 0.00000000e00, - ], - [ - 2.31723847e-01, - -1.87989743e-01, - -2.24864098e-02, - -3.13724093e-01, - 5.20417043e-18, - -9.83618836e-02, - 0.00000000e00, - ], - [ - 5.70686384e-01, - 7.06834356e-02, - 1.14788448e-02, - 1.97775093e-01, - 8.67361738e-19, - 7.39421042e-02, - 0.00000000e00, - ], - [ - -1.24194307e-01, - 1.60694077e-01, - -1.01445937e-02, - -1.22260298e-02, - -1.15898581e-01, - 0.00000000e00, - -1.10706199e-01, - ], - [ - 2.14206274e-02, - 9.31685572e-01, - -5.88171749e-02, - -7.08850988e-02, - -6.71966493e-01, - 0.00000000e00, - -6.41861667e-01, - ], - [ - 5.53167558e-18, - -1.26028049e-01, - -2.94438391e-01, - 2.94908598e-02, - -1.37396662e-01, - 0.00000000e00, - -1.49560791e-01, - ], - ], - [ - [ - 4.85696011e-02, - 6.44268400e-02, - 4.61905080e-02, - -1.91831542e-02, - 8.76704022e-03, - -4.49833175e-03, - 0.00000000e00, - ], - [ - -4.21413485e-01, - 3.73539326e-01, - 2.67807194e-01, - -1.11221697e-01, - 5.08302797e-02, - -2.60808044e-02, - 0.00000000e00, - ], - [ - 3.59829170e-01, - -1.40449380e-01, - 2.91821673e-02, - -5.64152301e-01, - 1.18440113e-02, - -1.98542822e-01, - 0.00000000e00, - ], - [ - 7.37360525e-01, - 4.91939581e-02, - 2.01575078e-02, - 1.08016484e-01, - -8.90683876e-04, - 1.10706199e-01, - 0.00000000e00, - ], - [ - -1.27177529e-01, - 2.85220849e-01, - 1.16870886e-01, - 6.26267014e-01, - -5.16408154e-03, - 6.41861667e-01, - 0.00000000e00, - ], - [ - -3.28424010e-17, - 7.48247732e-01, - 5.85054890e-01, - 5.45085339e-02, - -3.93121050e-02, - 1.49560791e-01, - 0.00000000e00, - ], - ], - ], - [ - [ - [ - 3.41453006e-02, - 8.08253690e-02, - 3.06951191e-02, - -3.45709946e-01, - 1.01688580e-02, - -1.07973135e-01, - 0.00000000e00, - ], - [ - -4.16474664e-01, - -1.39404950e-02, - -4.24230421e-01, - -2.17748413e-02, - -7.82283735e-02, - -2.81325889e-02, - 0.00000000e00, - ], - [ - 2.42699171e-18, - -3.60000174e-18, - 2.66095901e-18, - 1.61807814e-17, - 2.82387683e-19, - 5.25873718e-18, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 5.39111251e-02, - -6.30795483e-01, - 1.28407717e-01, - -5.99489263e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -9.97525009e-01, - -3.97312016e-02, - -9.87832342e-01, - -3.36043908e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 7.10071903e-18, - 2.95240677e-17, - 3.56586331e-18, - 2.80188451e-17, - ], - ], - [ - [ - 8.10577678e-19, - -6.87706209e-02, - 3.52650006e-03, - -1.16102817e-02, - 8.03370202e-04, - -3.50123667e-03, - 0.00000000e00, - ], - [ - 4.99661867e-17, - -3.98724063e-01, - 2.04462373e-02, - -6.73150634e-02, - 4.65784701e-03, - -2.02997631e-02, - 0.00000000e00, - ], - [ - 1.04435486e-01, - 8.20187641e-02, - 1.02353729e-01, - -3.36978765e-01, - 2.33171516e-02, - -1.01620481e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 7.67199187e-03, - -2.11845605e-02, - 1.01445937e-02, - -2.01575078e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 4.44813167e-02, - -1.22825619e-01, - 5.88171749e-02, - -1.16870886e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 2.22673179e-01, - -6.14864240e-01, - 2.94438391e-01, - -5.85054890e-01, - ], - ], - [ - [ - 3.34646679e-02, - 0.00000000e00, - 3.41453006e-02, - -3.52192202e-01, - 1.08915293e-02, - -1.09853801e-01, - 0.00000000e00, - ], - [ - -4.08172899e-01, - 3.81639165e-17, - -4.16474664e-01, - -1.90341873e-02, - -7.68286193e-02, - -2.68762218e-02, - 0.00000000e00, - ], - [ - 8.03838495e-02, - -7.37257477e-18, - 8.20187641e-02, - 1.59367259e-02, - 1.49720700e-02, - 9.15371670e-03, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 6.16735653e-02, - -6.42623254e-01, - 1.37533281e-01, - -6.10758051e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -9.79165111e-01, - -3.47305003e-02, - -9.70156883e-01, - -2.89298617e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.93473657e-01, - 2.90787547e-02, - 1.89060494e-01, - 2.68221308e-02, - ], - ], - [ - [ - -2.67749497e-02, - -4.27379584e-01, - 0.00000000e00, - 3.13469337e-02, - -3.14115013e-04, - 1.21748711e-02, - 0.00000000e00, - ], - [ - 7.32787717e-02, - -2.52079454e-01, - 1.38777878e-17, - -4.97682007e-01, - 4.98707121e-03, - -1.93295280e-01, - 0.00000000e00, - ], - [ - -4.45303046e-02, - -5.99740038e-01, - 0.00000000e00, - 9.83372027e-02, - -9.85397553e-04, - 3.81932978e-02, - 0.00000000e00, - ], - [ - -5.39111251e-02, - -7.67199187e-03, - -6.16735653e-02, - 0.00000000e00, - -4.71705446e-02, - -3.96650160e-03, - -4.87735455e-02, - ], - [ - 9.97525009e-01, - -4.44813167e-02, - 9.79165111e-01, - 0.00000000e00, - 7.48906785e-01, - 6.29744683e-02, - 7.74356953e-01, - ], - [ - -7.10071903e-18, - -2.22673179e-01, - -1.93473657e-01, - 0.00000000e00, - -1.47976815e-01, - -1.24431524e-02, - -1.53005525e-01, - ], - ], - [ - [ - 8.02939201e-02, - -8.68221386e-02, - 2.61157664e-02, - -5.95998728e-01, - 1.16033016e-02, - -2.10879959e-01, - 0.00000000e00, - ], - [ - -2.79925137e-01, - 2.37618361e-01, - -3.18537393e-01, - -3.22106832e-02, - -5.85848803e-02, - -2.74121559e-02, - 0.00000000e00, - ], - [ - 1.38239466e-01, - -1.44396771e-01, - 6.27314110e-02, - 2.69689911e-02, - 1.13031672e-02, - 1.27415350e-02, - 0.00000000e00, - ], - [ - 6.30795483e-01, - 2.11845605e-02, - 6.42623254e-01, - 4.71705446e-02, - 0.00000000e00, - 1.46521218e-01, - 4.10747232e-02, - ], - [ - 3.97312016e-02, - 1.22825619e-01, - 3.47305003e-02, - -7.48906785e-01, - 0.00000000e00, - -7.39783239e-01, - 5.33927794e-03, - ], - [ - -2.95240677e-17, - 6.14864240e-01, - -2.90787547e-02, - 1.47976815e-01, - 0.00000000e00, - 1.42731258e-01, - -2.48176748e-03, - ], - ], - [ - [ - -3.09721687e-02, - -4.14953750e-01, - 2.19603632e-03, - 4.72532385e-02, - 1.73472348e-18, - 2.00850184e-02, - 0.00000000e00, - ], - [ - 4.28372826e-02, - -2.78984158e-01, - -2.67853401e-02, - -4.94327552e-01, - -5.20417043e-18, - -1.93245510e-01, - 0.00000000e00, - ], - [ - -4.82359054e-02, - -5.79629005e-01, - 5.27499193e-03, - 9.71190784e-02, - 1.38777878e-17, - 3.79108193e-02, - 0.00000000e00, - ], - [ - -1.28407717e-01, - -1.01445937e-02, - -1.37533281e-01, - 3.96650160e-03, - -1.46521218e-01, - 0.00000000e00, - -1.48046549e-01, - ], - [ - 9.87832342e-01, - -5.88171749e-02, - 9.70156883e-01, - -6.29744683e-02, - 7.39783239e-01, - 0.00000000e00, - 7.65372332e-01, - ], - [ - -3.56586331e-18, - -2.94438391e-01, - -1.89060494e-01, - 1.24431524e-02, - -1.42731258e-01, - 0.00000000e00, - -1.47790395e-01, - ], - ], - [ - [ - 7.85407802e-02, - -8.07082629e-02, - 2.70032608e-02, - -5.88956619e-01, - 1.17240955e-02, - -2.07444792e-01, - 0.00000000e00, - ], - [ - -2.92451072e-01, - 2.26787537e-01, - -3.29362278e-01, - -2.97571131e-02, - -6.06113306e-02, - -2.69656206e-02, - 0.00000000e00, - ], - [ - 1.36676893e-01, - -1.34689562e-01, - 6.48632182e-02, - 2.62362355e-02, - 1.17038102e-02, - 1.25339795e-02, - 0.00000000e00, - ], - [ - 5.99489263e-01, - 2.01575078e-02, - 6.10758051e-01, - 4.87735455e-02, - -4.10747232e-02, - 1.48046549e-01, - 0.00000000e00, - ], - [ - 3.36043908e-02, - 1.16870886e-01, - 2.89298617e-02, - -7.74356953e-01, - -5.33927794e-03, - -7.65372332e-01, - 0.00000000e00, - ], - [ - -2.80188451e-17, - 5.85054890e-01, - -2.68221308e-02, - 1.53005525e-01, - 2.48176748e-03, - 1.47790395e-01, - 0.00000000e00, - ], - ], - ], - [ - [ - [ - -3.35029257e-01, - 5.06596965e-01, - -3.45709946e-01, - 9.65242924e-02, - -1.45842251e-03, - 3.24608603e-02, - 0.00000000e00, - ], - [ - 8.04745724e-02, - -8.73761859e-02, - -2.17748413e-02, - -5.18935898e-01, - 5.28476698e-03, - -2.00682834e-01, - 0.00000000e00, - ], - [ - 1.47042021e-17, - -2.25640783e-17, - 1.61807814e-17, - 5.30332170e-19, - 1.65636617e-20, - 4.29940126e-19, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 8.48905588e-02, - -1.84162966e-02, - 7.71850655e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 7.41195745e-01, - 6.67336352e-02, - 7.68210453e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.10485573e-17, - 2.09158392e-19, - -1.09523226e-17, - ], - ], - [ - [ - 2.35023767e-17, - 3.80041092e-03, - -1.16102817e-02, - -5.49139714e-02, - 9.68203187e-04, - -1.70497322e-02, - 0.00000000e00, - ], - [ - -1.27668360e-17, - 2.20343406e-02, - -6.73150634e-02, - -3.18384821e-01, - 5.61352949e-03, - -9.88523645e-02, - 0.00000000e00, - ], - [ - -3.43832524e-01, - 5.14076923e-01, - -3.36978765e-01, - 1.83321890e-01, - -2.33543881e-03, - 6.60980339e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.13181076e-01, - 1.22260298e-02, - -1.08016484e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -6.56210717e-01, - 7.08850988e-02, - -6.26267014e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -4.23235448e-02, - -2.94908598e-02, - -5.45085339e-02, - ], - ], - [ - [ - -3.28350978e-01, - 5.00876302e-01, - -3.52192202e-01, - 3.13469337e-02, - -3.14115013e-04, - 1.21748711e-02, - 0.00000000e00, - ], - [ - 7.88704387e-02, - -8.63895046e-02, - -1.90341873e-02, - -4.97682007e-01, - 4.98707121e-03, - -1.93295280e-01, - 0.00000000e00, - ], - [ - -4.44218266e-03, - -6.93889390e-18, - 1.59367259e-02, - 9.83372027e-02, - -9.85397553e-04, - 3.81932978e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -4.71705446e-02, - -3.96650160e-03, - -4.87735455e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 7.48906785e-01, - 6.29744683e-02, - 7.74356953e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.47976815e-01, - -1.24431524e-02, - -1.53005525e-01, - ], - ], - [ - [ - 6.48193356e-02, - -7.61193490e-02, - 0.00000000e00, - -3.35029257e-01, - 5.85989604e-03, - -1.04502264e-01, - 0.00000000e00, - ], - [ - -1.55697098e-02, - 1.82839914e-02, - 1.90819582e-17, - 8.04745724e-02, - -6.71145042e-04, - 3.26402475e-02, - 0.00000000e00, - ], - [ - -9.94603424e-02, - 1.16799354e-01, - 9.71445147e-17, - 5.14076923e-01, - -5.26460556e-03, - 1.98503607e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -6.68449878e-01, - 7.39961036e-02, - -6.37206328e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.84470262e-01, - -8.47491453e-03, - -1.87822895e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -7.20517510e-01, - -6.64790460e-02, - -7.47444596e-01, - ], - ], - [ - [ - 5.61448369e-02, - 8.05790870e-01, - 2.26019439e-02, - 2.77555756e-17, - 5.26713933e-02, - 1.42461283e-02, - 0.00000000e00, - ], - [ - 1.65648643e-01, - 2.46157927e-02, - 1.13501279e-01, - 8.32667268e-17, - 1.45355786e-02, - 3.93146458e-03, - 0.00000000e00, - ], - [ - 5.26562926e-01, - 1.50442818e-01, - 5.40897217e-01, - 1.52655666e-16, - 5.67741313e-02, - 1.53558033e-02, - 0.00000000e00, - ], - [ - -8.48905588e-02, - 1.13181076e-01, - 4.71705446e-02, - 6.68449878e-01, - 0.00000000e00, - 6.65110413e-01, - -2.77482876e-03, - ], - [ - -7.41195745e-01, - 6.56210717e-01, - -7.48906785e-01, - 1.84470262e-01, - 0.00000000e00, - 1.83548679e-01, - -7.65761810e-04, - ], - [ - 1.10485573e-17, - 4.23235448e-02, - 1.47976815e-01, - 7.20517510e-01, - 0.00000000e00, - 7.16917924e-01, - -2.99096877e-03, - ], - ], - [ - [ - 1.00823383e-02, - -9.12151146e-02, - -5.50296030e-02, - -3.33355506e-01, - 6.93889390e-18, - -1.05557206e-01, - 0.00000000e00, - ], - [ - -2.17722592e-02, - 3.75026544e-02, - -3.48488893e-03, - 8.00725347e-02, - 1.51788304e-18, - 3.26578012e-02, - 0.00000000e00, - ], - [ - -9.16405905e-02, - 1.94212992e-01, - 3.02504923e-03, - 5.11508680e-01, - 5.20417043e-18, - 1.98928729e-01, - 0.00000000e00, - ], - [ - 1.84162966e-02, - -1.22260298e-02, - 3.96650160e-03, - -7.39961036e-02, - -6.65110413e-01, - 0.00000000e00, - -6.33715782e-01, - ], - [ - -6.67336352e-02, - -7.08850988e-02, - -6.29744683e-02, - 8.47491453e-03, - -1.83548679e-01, - 0.00000000e00, - -1.86919743e-01, - ], - [ - -2.09158392e-19, - 2.94908598e-02, - 1.24431524e-02, - 6.64790460e-02, - -7.16917924e-01, - 0.00000000e00, - -7.43986450e-01, - ], - ], - [ - [ - 3.32773173e-02, - 7.98996386e-01, - -2.22953651e-04, - 1.39075322e-03, - 5.01851912e-02, - 1.40140634e-02, - 0.00000000e00, - ], - [ - 1.62967320e-01, - 3.25210512e-02, - 1.11958911e-01, - -3.34061184e-04, - 1.48025397e-02, - 3.86742228e-03, - 0.00000000e00, - ], - [ - 5.29555141e-01, - 1.82151411e-01, - 5.41683062e-01, - -2.13400507e-03, - 5.89177408e-02, - 1.51056622e-02, - 0.00000000e00, - ], - [ - -7.71850655e-02, - 1.08016484e-01, - 4.87735455e-02, - 6.37206328e-01, - 2.77482876e-03, - 6.33715782e-01, - 0.00000000e00, - ], - [ - -7.68210453e-01, - 6.26267014e-01, - -7.74356953e-01, - 1.87822895e-01, - 7.65761810e-04, - 1.86919743e-01, - 0.00000000e00, - ], - [ - 1.09523226e-17, - 5.45085339e-02, - 1.53005525e-01, - 7.47444596e-01, - 2.99096877e-03, - 7.43986450e-01, - 0.00000000e00, - ], - ], - ], - [ - [ - [ - 1.07195463e-02, - 9.83518983e-03, - 1.01688580e-02, - -1.45842251e-03, - 1.05221866e-03, - -2.09794626e-01, - 0.00000000e00, - ], - [ - -7.78257566e-02, - -1.69634134e-03, - -7.82283735e-02, - 5.28476698e-03, - -5.79159088e-02, - -2.88966443e-02, - 0.00000000e00, - ], - [ - 2.53075280e-19, - -4.38064199e-19, - 2.82387683e-19, - 1.65636617e-20, - 5.08258833e-19, - 9.97012277e-18, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.32869389e-02, - 4.08633244e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -7.31335770e-01, - 5.62842325e-03, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 6.41806152e-18, - -1.94195804e-18, - ], - ], - [ - [ - -1.61086476e-19, - -1.27256780e-02, - 8.03370202e-04, - 9.68203187e-04, - 9.17823507e-03, - -4.57282155e-03, - 0.00000000e00, - ], - [ - 9.37818968e-18, - -7.37820011e-02, - 4.65784701e-03, - 5.61352949e-03, - 5.32143397e-02, - -2.65126876e-02, - 0.00000000e00, - ], - [ - 2.37913955e-02, - 9.98040745e-03, - 2.33171516e-02, - -2.33543881e-03, - 1.08807101e-02, - -2.01830577e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.15898581e-01, - 8.90683876e-04, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 6.71966493e-01, - 5.16408154e-03, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.37396662e-01, - 3.93121050e-02, - ], - ], - [ - [ - 1.05058690e-02, - -5.01907994e-03, - 1.08915293e-02, - -3.14115013e-04, - 1.16033016e-02, - -2.10879959e-01, - 0.00000000e00, - ], - [ - -7.62744229e-02, - 8.65674476e-04, - -7.68286193e-02, - 4.98707121e-03, - -5.85848803e-02, - -2.74121559e-02, - 0.00000000e00, - ], - [ - 1.48746510e-02, - -1.24683250e-18, - 1.49720700e-02, - -9.85397553e-04, - 1.13031672e-02, - 1.27415350e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.46521218e-01, - 4.10747232e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -7.39783239e-01, - 5.33927794e-03, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.42731258e-01, - -2.48176748e-03, - ], - ], - [ - [ - -2.07394982e-03, - -7.52143130e-02, - 2.66073585e-03, - 5.85989604e-03, - 5.26713933e-02, - 1.42461283e-02, - 0.00000000e00, - ], - [ - 1.50572337e-02, - -4.28938883e-03, - 1.54266371e-02, - -6.71145042e-04, - 1.45355786e-02, - 3.93146458e-03, - 0.00000000e00, - ], - [ - 7.68653783e-02, - 2.26756948e-03, - 7.72256438e-02, - -5.26460556e-03, - 5.67741313e-02, - 1.53558033e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 6.65110413e-01, - -2.77482876e-03, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.83548679e-01, - -7.65761810e-04, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 7.16917924e-01, - -2.99096877e-03, - ], - ], - [ - [ - 7.72362080e-03, - -6.72512034e-03, - 8.19876123e-03, - 8.67361738e-19, - 1.07195463e-02, - -1.56123717e-01, - 0.00000000e00, - ], - [ - -5.60748204e-02, - 4.88255347e-02, - -5.95244219e-02, - -6.07153217e-18, - -7.78257566e-02, - -2.83646224e-03, - 0.00000000e00, - ], - [ - 7.19105833e-03, - -6.26140691e-03, - 7.63343666e-03, - 7.58941521e-19, - 9.98040745e-03, - 1.45567764e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.35361558e-01, - 3.04094258e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -9.82748279e-01, - 5.52479723e-04, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 1.26028049e-01, - -2.83533610e-02, - ], - ], - [ - [ - -3.06034236e-01, - -4.98379189e-01, - -2.79535843e-01, - 6.74871090e-02, - -6.93889390e-18, - 1.07195463e-02, - 0.00000000e00, - ], - [ - -1.00442146e-01, - -1.08393727e-01, - -7.27677599e-02, - -1.47405316e-01, - -8.67361738e-18, - -7.78257566e-02, - 0.00000000e00, - ], - [ - -2.50991746e-01, - -4.53195110e-01, - -2.26781234e-01, - 5.79144367e-02, - -6.93889390e-18, - 9.98040745e-03, - 0.00000000e00, - ], - [ - -1.32869389e-02, - -1.15898581e-01, - -1.46521218e-01, - -6.65110413e-01, - -1.35361558e-01, - 0.00000000e00, - -1.35244491e-01, - ], - [ - 7.31335770e-01, - -6.71966493e-01, - 7.39783239e-01, - -1.83548679e-01, - 9.82748279e-01, - 0.00000000e00, - 9.81898349e-01, - ], - [ - -6.41806152e-18, - -1.37396662e-01, - -1.42731258e-01, - -7.16917924e-01, - -1.26028049e-01, - 0.00000000e00, - -1.25919053e-01, - ], - ], - [ - [ - 5.67937662e-03, - -6.39875381e-05, - 9.64647527e-03, - 2.13841071e-02, - 1.07102755e-02, - -1.53580512e-01, - 0.00000000e00, - ], - [ - -5.90802231e-02, - 4.83482186e-02, - -6.12645420e-02, - 4.97217187e-03, - -7.77584490e-02, - -2.79025718e-03, - 0.00000000e00, - ], - [ - 3.37578191e-03, - 1.97430655e-03, - 8.84164962e-03, - 1.31960342e-02, - 9.97177590e-03, - 1.43196511e-01, - 0.00000000e00, - ], - [ - -4.08633244e-02, - -8.90683876e-04, - -4.10747232e-02, - 2.77482876e-03, - -3.04094258e-02, - 1.35244491e-01, - 0.00000000e00, - ], - [ - -5.62842325e-03, - -5.16408154e-03, - -5.33927794e-03, - 7.65761810e-04, - -5.52479723e-04, - -9.81898349e-01, - 0.00000000e00, - ], - [ - 1.94195804e-18, - -3.93121050e-02, - 2.48176748e-03, - 2.99096877e-03, - 2.83533610e-02, - 1.25919053e-01, - 0.00000000e00, - ], - ], - ], - [ - [ - [ - -1.03187865e-01, - 1.99678676e-01, - -1.07973135e-01, - 3.24608603e-02, - -2.09794626e-01, - 4.04324654e-02, - 0.00000000e00, - ], - [ - 1.17720983e-02, - -3.44399243e-02, - -2.81325889e-02, - -2.00682834e-01, - -2.88966443e-02, - -2.00614904e-01, - 0.00000000e00, - ], - [ - 4.65397353e-18, - -8.89378659e-18, - 5.25873718e-18, - 4.29940126e-19, - 9.97012277e-18, - 6.10077242e-20, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -2.09458434e-02, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 7.58497864e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -6.32539630e-18, - ], - ], - [ - [ - 7.34083974e-18, - -1.00921994e-03, - -3.50123667e-03, - -1.70497322e-02, - -4.57282155e-03, - -1.69651356e-02, - 0.00000000e00, - ], - [ - -2.38093275e-18, - -5.85133986e-03, - -2.02997631e-02, - -9.88523645e-02, - -2.65126876e-02, - -9.83618836e-02, - 0.00000000e00, - ], - [ - -1.03687324e-01, - 2.02626953e-01, - -1.01620481e-01, - 6.60980339e-02, - -2.01830577e-01, - 7.39421042e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.10706199e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -6.41861667e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.49560791e-01, - ], - ], - [ - [ - -1.01130978e-01, - 1.94535915e-01, - -1.09853801e-01, - 1.21748711e-02, - -2.10879959e-01, - 2.00850184e-02, - 0.00000000e00, - ], - [ - 1.15374401e-02, - -3.35529177e-02, - -2.68762218e-02, - -1.93295280e-01, - -2.74121559e-02, - -1.93245510e-01, - 0.00000000e00, - ], - [ - 1.17964594e-03, - -3.46944695e-18, - 9.15371670e-03, - 3.81932978e-02, - 1.27415350e-02, - 3.79108193e-02, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.48046549e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 7.65372332e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.47790395e-01, - ], - ], - [ - [ - 1.99641336e-02, - -4.44465872e-02, - 7.19654101e-04, - -1.04502264e-01, - 1.42461283e-02, - -1.05557206e-01, - 0.00000000e00, - ], - [ - -2.27759091e-03, - 6.29701679e-03, - 4.17247079e-03, - 3.26402475e-02, - 3.93146458e-03, - 3.26578012e-02, - 0.00000000e00, - ], - [ - -1.78907915e-02, - 4.60372682e-02, - 2.08873614e-02, - 1.98503607e-01, - 1.53558033e-02, - 1.98928729e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -6.33715782e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.86919743e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -7.43986450e-01, - ], - ], - [ - [ - -7.43486637e-02, - 1.42776647e-01, - -8.15965276e-02, - 4.88405015e-03, - -1.56123717e-01, - 1.07195463e-02, - 0.00000000e00, - ], - [ - 8.48200297e-03, - -2.08454900e-02, - -6.50029553e-03, - -7.75419986e-02, - -2.83646224e-03, - -7.78257566e-02, - 0.00000000e00, - ], - [ - 6.68043138e-02, - -1.27122045e-01, - 7.73642547e-02, - 1.53215570e-02, - 1.45567764e-01, - 9.98040745e-03, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.35244491e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 9.81898349e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.25919053e-01, - ], - ], - [ - [ - 1.30045653e-02, - -3.10004133e-02, - -6.63647108e-03, - -1.02672356e-01, - 3.46944695e-18, - -1.03187865e-01, - 0.00000000e00, - ], - [ - -1.48361458e-03, - 3.53665533e-03, - 7.57116061e-04, - 1.17132869e-02, - 7.80625564e-18, - 1.17720983e-02, - 0.00000000e00, - ], - [ - -2.55366795e-02, - 6.08745931e-02, - 1.30318416e-02, - 2.01614663e-01, - 5.20417043e-17, - 2.02626953e-01, - 0.00000000e00, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -6.37462344e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -1.83758244e-01, - ], - [ - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - 0.00000000e00, - -7.48247732e-01, - ], - ], - [ - [ - 2.13823046e-01, - 5.50959991e-01, - 1.84972186e-01, - -5.73283670e-02, - -1.11440324e-01, - 5.20417043e-18, - 0.00000000e00, - ], - [ - 1.14119484e-01, - 8.61759621e-02, - 7.65324714e-02, - 8.54932885e-02, - 1.00807085e-02, - 1.38777878e-17, - 0.00000000e00, - ], - [ - 4.05916016e-01, - 3.51404343e-01, - 3.90608748e-01, - -5.18727125e-02, - 1.98301371e-01, - 4.51028104e-17, - 0.00000000e00, - ], - [ - 2.09458434e-02, - 1.10706199e-01, - 1.48046549e-01, - 6.33715782e-01, - 1.35244491e-01, - 6.37462344e-01, - 0.00000000e00, - ], - [ - -7.58497864e-01, - 6.41861667e-01, - -7.65372332e-01, - 1.86919743e-01, - -9.81898349e-01, - 1.83758244e-01, - 0.00000000e00, - ], - [ - 6.32539630e-18, - 1.49560791e-01, - 1.47790395e-01, - 7.43986450e-01, - 1.25919053e-01, - 7.48247732e-01, - 0.00000000e00, - ], - ], - ], - [ - [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - ], - [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - ], - [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - ], - [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - ], - [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - ], - [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - ], - [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - ], - ], + (r.hessian0(q1 + delta) - r.hessian0(q1 - delta)) / (2 * step) + for delta in step * np.eye(r.n) ] ) diff --git a/tests/test_ETS2.py b/tests/test_ETS2.py index 4d48b230c..089178a58 100644 --- a/tests/test_ETS2.py +++ b/tests/test_ETS2.py @@ -75,6 +75,33 @@ def test_empty(self): self.assertEqual(r.n, 0) self.assertEqual(r.m, 0) + def test_empty_evaluation(self) -> None: + ets = rtb.ETS2() + nt.assert_array_equal(ets.eval(), np.eye(3)) + nt.assert_array_equal(ets.fkine().A, np.eye(3)) + nt.assert_array_equal(ets.eval(np.empty((2, 0))), [np.eye(3), np.eye(3)]) + self.assertEqual(ets.jacob0([]).shape, (3, 0)) + self.assertEqual(ets.jacobe([]).shape, (3, 0)) + + def test_empty_base_and_tool(self) -> None: + ets = rtb.ETS2() + base = SE2(1, -2, 0.3) + tool = SE2(-0.5, 0.7, -0.4) + for as_matrix in (False, True): + with self.subTest(as_matrix=as_matrix): + b, t = (base.A, tool.A) if as_matrix else (base, tool) + nt.assert_allclose(ets.eval(base=b, tool=t), (base * tool).A) + nt.assert_allclose( + ets.fkine(base=b, tool=t, include_base=False).A, tool.A + ) + + def test_compile_identity_evaluates(self) -> None: + for ets in (rtb.ETS2(R(0)), tx(1) * tx(-1)): + with self.subTest(ets=ets): + compiled = ets.compile() + self.assertEqual(compiled.m, 0) + nt.assert_array_equal(compiled.fkine().A, ets.fkine().A) + def test_str(self): rx = R(1.543) ry = R(1.543) diff --git a/tests/test_ets2_ik_coordinate_order.py b/tests/test_ets2_ik_coordinate_order.py new file mode 100644 index 000000000..684af8c94 --- /dev/null +++ b/tests/test_ets2_ik_coordinate_order.py @@ -0,0 +1,115 @@ +"""Planar IK coordinates agree with the public forward-kinematics convention.""" + +import numpy as np +import numpy.testing as nt +import pytest +from spatialmath import SE2 + +from roboticstoolbox import ET2, ETS2 + +INDEX_CASES = [ + pytest.param((0, 1, 2), (0, 1, 2), id="sequential"), + pytest.param((2, 0, 1), (1, 2, 0), id="cyclic-global"), + pytest.param((1, 2, 0), (2, 0, 1), id="inverse-cyclic-global"), + pytest.param((5, 2, 4), (0, 1, 2), id="sparse-compact"), +] + + +def arm(indices: tuple[int, ...], flipped: bool = False) -> ETS2: + return ETS2( + [ + ET2.R(jindex=indices[0], qlim=[0.1, 0.6]), + ET2.tx(1), + ET2.tx(jindex=indices[1], qlim=[6.5, 7.9]), + ET2.R(jindex=indices[2], qlim=[-0.7, -0.1], flip=flipped), + ET2.tx(0.7), + ] + ) + + +def target(values: list[float], flipped: bool = False) -> SE2: + first, extension, last = values + return ( + SE2.Rot(first) + * SE2.Tx(1 + extension) + * SE2.Rot(-last if flipped else last) + * SE2.Tx(0.7) + ) + + +@pytest.mark.parametrize("indices,order", INDEX_CASES) +@pytest.mark.parametrize("flipped", [False, True]) +@pytest.mark.parametrize("exact_start", [False, True]) +def test_mixed_joint_ik_uses_consistent_coordinates( + indices: tuple[int, ...], order: tuple[int, ...], flipped: bool, exact_start: bool +) -> None: + ets = arm(indices, flipped) + values = [0.35, 7.2, -0.4] + desired = target(values, flipped) + q = np.array(values)[list(order)] + q0 = q if exact_start else np.array([0.2, 7.0, -0.3])[list(order)] + sol = ets.ikine_LM( + desired, q0=q0, slimit=1, ilimit=0 if exact_start else 80, tol=1e-12 + ) + + assert sol.success, sol.reason + nt.assert_allclose(sol.q, q, atol=5e-6) + nt.assert_allclose( + np.asarray(ets.fkine(sol.q).A, dtype=float), desired.A, atol=2e-6 + ) + nt.assert_array_equal(ets.jindices, indices) + + +@pytest.mark.parametrize("indices,order", INDEX_CASES) +def test_random_starts_obey_each_joints_limits( + indices: tuple[int, ...], order: tuple[int, ...] +) -> None: + ets = arm(indices) + values = [0.35, 7.2, -0.4] + sol = ets.ikine_LM(target(values), seed=3, slimit=8, ilimit=80, tol=1e-12) + + assert sol.success, sol.reason + nt.assert_allclose(sol.q, np.array(values)[list(order)], atol=5e-6) + + +@pytest.mark.parametrize("indices,order", INDEX_CASES) +def test_trajectory_rows_use_the_same_coordinate_order( + indices: tuple[int, ...], order: tuple[int, ...] +) -> None: + ets = arm(indices) + values = [[0.35, 7.2, -0.4], [0.42, 7.5, -0.5], [0.2, 6.8, -0.25]] + desired = SE2([target(v) for v in values]) + q0 = np.array([0.2, 7.0, -0.3])[list(order)] + sol = ets.ikine_LM(desired, q0=q0, slimit=1, ilimit=80, tol=1e-12) + + assert sol.success, sol.reason + nt.assert_allclose(sol.q, np.array(values)[:, list(order)], atol=5e-6) + + +@pytest.mark.parametrize("indices,order", INDEX_CASES) +def test_limits_reject_the_same_physical_joint( + indices: tuple[int, ...], order: tuple[int, ...] +) -> None: + ets = arm(indices) + values = [0.9, 7.2, -0.4] # first revolute joint exceeds its upper bound + q0 = np.array(values)[list(order)] + rejected = ets.ikine_LM(target(values), q0=q0, slimit=1, ilimit=0, tol=1e-12) + accepted = ets.ikine_LM( + target(values), q0=q0, slimit=1, ilimit=0, tol=1e-12, joint_limits=False + ) + + assert not rejected.success + assert accepted.success + nt.assert_allclose(accepted.q[order.index(1)], values[1], atol=1e-12) + nt.assert_allclose( + np.asarray(ets.fkine(accepted.q).A, dtype=float), target(values).A, atol=1e-12 + ) + + +def test_two_revolute_joints_with_swapped_indices_converge() -> None: + ets = ET2.R(jindex=1) * ET2.tx(1) * ET2.R(jindex=0) * ET2.tx(0.8) + desired = SE2.Rot(-0.4) * SE2.Tx(1) * SE2.Rot(0.7) * SE2.Tx(0.8) + sol = ets.ikine_LM(desired, q0=[-0.2, 0.1], slimit=1, ilimit=80, tol=1e-12) + + assert sol.success, sol.reason + nt.assert_allclose(sol.q, [0.7, -0.4], atol=5e-6) diff --git a/tests/test_ets_mutation.py b/tests/test_ets_mutation.py new file mode 100644 index 000000000..d2b87235b --- /dev/null +++ b/tests/test_ets_mutation.py @@ -0,0 +1,45 @@ +"""Kinematics must follow joint indices after list-like ETS edits.""" + +import numpy as np +import numpy.testing as nt +import pytest + +from roboticstoolbox import ET, ET2, ETS, ETS2 + + +@pytest.mark.parametrize("et, ets_type, rotation", [(ET, ETS, "Rz"), (ET2, ETS2, "R")]) +@pytest.mark.parametrize( + "operation", + ["replace", "slice", "delete", "insert", "sequence", "pop", "reverse", "data"], +) +def test_mutation_refreshes_joint_indices(et, ets_type, rotation, operation) -> None: + rotate = getattr(et, rotation) + sequence = ( + rotate(jindex=0) * et.tx(1) * rotate(jindex=2) * et.tx(2) * rotate(jindex=4) + ) + # Populate the cached index array just as the first FK call does. + sequence.fkine([0.1, 0.2, 0.3]) + + if operation == "replace": + sequence[-1] = rotate(jindex=6) + elif operation == "slice": + sequence[2:] = [et.tx(2), rotate(jindex=6)] + elif operation == "delete": + del sequence[0] + elif operation == "insert": + sequence.insert(2, rotate(jindex=6)) + elif operation == "sequence": + sequence.insert(2, ets_type([rotate(jindex=6), et.tx(0.5)])) + elif operation == "pop": + sequence.pop() + elif operation == "reverse": + sequence.reverse() + else: + sequence.data = [rotate(jindex=6), et.tx(0.5)] + + # A freshly constructed sequence has the same transforms and no stale cache. + expected = ets_type(list(sequence)) + q = np.linspace(0.1, 0.3, sequence.n) + nt.assert_array_equal(sequence.jindices, expected.jindices) + nt.assert_allclose(sequence.fkine(q).A, expected.fkine(q).A) + nt.assert_allclose(sequence.jacob0(q), expected.jacob0(q)) diff --git a/tests/test_random_q_indices.py b/tests/test_random_q_indices.py new file mode 100644 index 000000000..5dcd03a05 --- /dev/null +++ b/tests/test_random_q_indices.py @@ -0,0 +1,44 @@ +"""Random configurations obey the limits of the addressed joint.""" + +import numpy as np +import pytest + +from roboticstoolbox import ET, ET2, ETS, ETS2, Robot, Robot2 + + +@pytest.mark.parametrize("et, ets_type, rotation", [(ET, ETS, "Rz"), (ET2, ETS2, "R")]) +@pytest.mark.parametrize("indices", [[0, 1], [1, 0], [2, 5]]) +@pytest.mark.parametrize("count", [1, 8]) +def test_ets_random_q_respects_joint_indices( + et, ets_type, rotation, indices, count +) -> None: + rotate = getattr(et, rotation) + sequence = ets_type( + [ + rotate(jindex=indices[0], qlim=[1, 2]), + et.tx(1), + rotate(jindex=indices[1], qlim=[3, 4]), + ] + ) + q = sequence.random_q(count) + assert q.shape == ((2,) if count == 1 else (count, 2)) + # Interpret exactly the vector returned to FK, including compact subchains. + resolved = sequence._resolve_q(q, allow_trajectory=count != 1) + for joint in sequence.joints(): + assert np.all(resolved[..., joint.jindex] >= joint.qlim[0]) + assert np.all(resolved[..., joint.jindex] <= joint.qlim[1]) + + +@pytest.mark.parametrize( + "et, robot_type, rotation", [(ET, Robot, "Rz"), (ET2, Robot2, "R")] +) +def test_robot_random_q_respects_joint_indices(et, robot_type, rotation) -> None: + rotate = getattr(et, rotation) + robot = robot_type( + rotate(jindex=1, qlim=[1, 2]) * et.tx(1) * rotate(jindex=0, qlim=[3, 4]) + ) + q = robot.random_q() + assert q.shape == (2,) + for link in robot.links: + if link.isjoint: + assert link.qlim[0] <= q[link.jindex] <= link.qlim[1] diff --git a/tests/test_serial_kinematic_partials.py b/tests/test_serial_kinematic_partials.py new file mode 100644 index 000000000..2246c3a11 --- /dev/null +++ b/tests/test_serial_kinematic_partials.py @@ -0,0 +1,134 @@ +"""Higher derivatives must retain the dependency order of a serial chain.""" + +from itertools import product + +import numpy as np +import pytest +from numpy.testing import assert_allclose +from spatialmath import SE3 + +import roboticstoolbox as rtb +from roboticstoolbox import ET + + +@pytest.mark.parametrize("order", [3, 4, 5]) +@pytest.mark.parametrize("flip", [False, True]) +@pytest.mark.parametrize("placed", [False, True]) +@pytest.mark.parametrize("indices", [(0, 1, 2), (5, 2, 4)]) +def test_planar_rpr_partials_match_closed_form(order, flip, placed, indices): + base = SE3(0.2, -0.3, 0.6) * SE3.RPY(0.4, -0.6, 0.2) if placed else SE3() + signs = np.array([-1, -1, -1] if flip else [1, 1, 1]) + offsets = np.array([0.13, 0.07, -0.21]) + q = np.array([0.3, 0.2, -0.7]) + theta, displacement, wrist = signs * q + offsets + joints = [ + ET.Rz(jindex=indices[0], flip=flip), + ET.tx(jindex=indices[1], flip=flip), + ET.Rz(jindex=indices[2], flip=flip), + ] + for joint, offset in zip(joints, offsets): + joint.offset = offset + ets = ( + ET.SE3(base) + * joints[0] + * ET.tx(0.8) + * joints[1] + * joints[2] + * ET.tx(0.5) + * ET.SE3(SE3.Tx(0.2) * SE3.Rx(0.4)) + ) + global_q = np.zeros(max(indices) + 1) + global_q[list(indices)] = q + actual = ets.partial_fkine0(global_q, order) + expected = np.zeros((3,) * (order - 1) + (6, 3)) + + # p = (0.8 + d) [cos(theta), sin(theta)] + # + 0.7 [cos(theta + wrist), sin(theta + wrist)]. + # Differentiate these scalar expressions directly, including mixed R/P terms. + for joints in product(range(3), repeat=order): + nr, np_, nw = (joints.count(j) for j in range(3)) + value = np.zeros(3) + if nw == 0 and np_ <= 1: + length = 0.8 + displacement if np_ == 0 else signs[1] + angle = theta + nr * np.pi / 2 + value[:2] += ( + length * signs[0] ** nr * np.array([np.cos(angle), np.sin(angle)]) + ) + if np_ == 0: + angle = theta + wrist + (nr + nw) * np.pi / 2 + value[:2] += ( + 0.7 + * signs[0] ** nr + * signs[2] ** nw + * np.array([np.cos(angle), np.sin(angle)]) + ) + expected[joints[:-1] + (slice(0, 3), joints[-1])] = base.R @ value + + assert actual.shape == expected.shape + assert_allclose(actual, expected, atol=2e-12) + + +@pytest.mark.parametrize("order", [3, 4, 5]) +@pytest.mark.parametrize("q", [(0.3, -0.7), (-0.6, 0.4)]) +def test_spatial_partials_match_closed_form(order, q): + # Position: ((a+b*cos(q1))*cos(q0), (a+b*cos(q1))*sin(q0), -b*sin(q1)). + # Angular Jacobian: (ez, Rz(q0) ey), so only the second column varies. + a, b = 0.8, 0.5 + ets = ET.Rz() * ET.tx(a) * ET.Ry() * ET.tx(b) + actual = ets.partial_fkine0(q, order) + expected = np.zeros((2,) * (order - 1) + (6, 2)) + for joints in product(range(2), repeat=order): + nz, ny = joints.count(0), joints.count(1) + radius = b * np.cos(q[1] + ny * np.pi / 2) + (a if ny == 0 else 0) + angle = q[0] + nz * np.pi / 2 + expected[joints[:-1] + (slice(0, 3), joints[-1])] = [ + radius * np.cos(angle), + radius * np.sin(angle), + -b * np.sin(q[1] + ny * np.pi / 2) if nz == 0 else 0, + ] + if joints[-1] == 1 and all(j == 0 for j in joints[:-1]): + angle = q[0] + (order - 1) * np.pi / 2 + expected[joints[:-1] + (slice(3, 6), 1)] = [ + -np.sin(angle), + np.cos(angle), + 0, + ] + + assert_allclose(actual, expected, atol=2e-12) + + +@pytest.mark.parametrize("model", [rtb.models.DH.Puma560, rtb.models.DH.Panda]) +@pytest.mark.parametrize("shift", [0.0, 0.13]) +def test_robot_third_partials_match_hessian_differences(model, shift): + robot = model() + robot.base = SE3(0.2, -0.3, 0.5) * SE3.RPY(0.4, -0.2, 0.3) + robot.tool = SE3(0.07, -0.05, 0.1) * SE3.RPY(-0.1, 0.2, 0.4) + q = robot.qr + shift + ets = robot.ets() + actual = ets.partial_fkine0(q, 3) + step = 1e-5 + expected = np.stack( + [ + (ets.hessian0(q + delta) - ets.hessian0(q - delta)) / (2 * step) + for delta in step * np.eye(robot.n) + ] + ) + assert_allclose(actual, expected, atol=2e-9) + + +def test_third_partials_predict_cartesian_jerk(): + ets = ET.Rz() * ET.tx(0.8) * ET.Rz() * ET.tx(0.5) + q = np.array([0.3, -0.7]) + qd = np.array([0.6, -0.2]) + third = ets.partial_fkine0(q, 3)[:, :, :3, :] + jerk = np.einsum("abij,a,b,j->i", third, qd, qd, qd) + expected = np.zeros(3) + for length, angle, rate in [(0.8, q[0], qd[0]), (0.5, q.sum(), qd.sum())]: + expected[:2] += length * rate**3 * np.array([np.sin(angle), -np.cos(angle)]) + assert_allclose(jerk, expected, atol=2e-12) + + +@pytest.mark.parametrize("order", [3, 4, 5]) +def test_prismatic_chain_has_no_higher_derivatives(order): + ets = ET.tx() * ET.Rz(0.4) * ET.ty() * ET.Ry(0.3) * ET.tz() + assert_allclose(ets.partial_fkine0([0.2, -0.3, 0.4], order), 0, atol=1e-14)