diff --git a/pyproject.toml b/pyproject.toml index b20515098..ecd8c8565 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ authors = [ dependencies = [ "numpy", - "spatialmath-python>=1.1.18", + "spatialmath-python>=1.1.19", "spatialgeometry>=1.4.0", "pgraph-python>=1.0.0", "scipy", diff --git a/src/roboticstoolbox/backends/PyPlot/PyPlot.py b/src/roboticstoolbox/backends/PyPlot/PyPlot.py index f053b88d1..9cfc33bb6 100644 --- a/src/roboticstoolbox/backends/PyPlot/PyPlot.py +++ b/src/roboticstoolbox/backends/PyPlot/PyPlot.py @@ -12,6 +12,7 @@ import numpy as np from spatialgeometry import Shape +from spatialmath.base import set_window_title from spatialmath.base.argcheck import getvector import roboticstoolbox as rp @@ -19,7 +20,7 @@ from roboticstoolbox.backends.PyPlot.EllipsePlot import EllipsePlot, ShapePlot from roboticstoolbox.backends.PyPlot.RobotPlot import RobotPlot from roboticstoolbox.tools.plot import isnotebook as _isnotebook -from roboticstoolbox.tools.plot import plane_view, set_window_title +from roboticstoolbox.tools.plot import plane_view from roboticstoolbox.tools.types import ArrayLike # from roboticstoolbox.tools import Ticker diff --git a/src/roboticstoolbox/backends/PyPlot/PyPlot2.py b/src/roboticstoolbox/backends/PyPlot/PyPlot2.py index c17aa3b5f..0112e40cc 100644 --- a/src/roboticstoolbox/backends/PyPlot/PyPlot2.py +++ b/src/roboticstoolbox/backends/PyPlot/PyPlot2.py @@ -18,7 +18,7 @@ from roboticstoolbox.backends.PyPlot.EllipsePlot import EllipsePlot from roboticstoolbox.backends.PyPlot.PyPlot import _isnotebook, _resolve_render_mode from roboticstoolbox.backends.PyPlot.RobotPlot2 import RobotPlot2 -from roboticstoolbox.tools.plot import set_window_title +from spatialmath.base import set_window_title _mpl = False _ipy_display: Any = None diff --git a/src/roboticstoolbox/mobile/Vehicle.py b/src/roboticstoolbox/mobile/Vehicle.py index 50a5ce0a3..405bfb607 100644 --- a/src/roboticstoolbox/mobile/Vehicle.py +++ b/src/roboticstoolbox/mobile/Vehicle.py @@ -28,7 +28,7 @@ from roboticstoolbox.mobile.drivers import VehicleDriverBase from roboticstoolbox.mobile.workspace import WorkspaceLike, resolve_workspace from roboticstoolbox.tools.plot import isnotebook as _isnotebook -from roboticstoolbox.tools.plot import set_window_title +from spatialmath.base import set_window_title from roboticstoolbox.tools.types import ArrayLike, NDArray # what can be given as the control for a vehicle, see VehicleBase.control diff --git a/src/roboticstoolbox/robot/RobotKinematics.py b/src/roboticstoolbox/robot/RobotKinematics.py index 8cde60735..f37c7ae72 100644 --- a/src/roboticstoolbox/robot/RobotKinematics.py +++ b/src/roboticstoolbox/robot/RobotKinematics.py @@ -24,20 +24,10 @@ def _as_se3(T: NDArray | SE3) -> SE3: :param T: an SE3, a 4x4 array, or an (N, 4, 4) array of N poses :raises ValueError: if ``T`` is an array of any other shape :returns: an SE3 object holding one or N poses - - .. note:: This is a workaround for a spatialmath (SMTB) limitation. The - ``SE3`` constructor does not accept an (N, 4, 4) array, and with - ``check=False`` it silently builds a malformed object from one. An - (N, 4, 4) array is therefore converted to a list of matrices first. - Once SMTB accepts such arrays this can go, see - https://github.com/rai-opensource/spatialmath-python/issues/236 """ if isinstance(T, np.ndarray): if T.shape != (4, 4) and not (T.ndim == 3 and T.shape[1:] == (4, 4)): raise ValueError("T must be an SE3, a 4x4 array or an (N, 4, 4) array") - if T.ndim == 3: - # SMTB workaround, see the note above - return SE3(list(T), check=False) return SE3(T, check=False) diff --git a/src/roboticstoolbox/tools/plot.py b/src/roboticstoolbox/tools/plot.py index 0a31fe695..9616e74e5 100644 --- a/src/roboticstoolbox/tools/plot.py +++ b/src/roboticstoolbox/tools/plot.py @@ -7,33 +7,6 @@ import numpy as np -try: - # spatialmath.base.set_window_title, once released (SMTB PR #263) - from spatialmath.base import set_window_title -except ImportError: # pragma: no cover - - def set_window_title(fig: Any, title: str) -> bool: - """ - Set the title of the window of a Matplotlib figure, if it has one - - :param fig: the figure - :param title: the window title - :return: True if the title was set - - A figure on a headless backend, or one that is not managed by pyplot, - has no window and the title is not set. This is the one place in RTB - that sets a window title. - - .. note:: A copy of ``spatialmath.base.set_window_title``, used until - the minimum version of Spatial Math has it. - """ - manager = getattr(fig.canvas, "manager", None) - if manager is not None and hasattr(manager, "set_window_title"): - manager.set_window_title(title) - return True - return False - - #: the view of each plane, for ``view_init``, which is exact: in each the first named #: axis points to the right and the second up, in an orthographic projection _PLANE_VIEWS: dict[str, dict[str, float]] = { diff --git a/tests/test_IK.py b/tests/test_IK.py index bb4b8c6e3..852597ade 100644 --- a/tests/test_IK.py +++ b/tests/test_IK.py @@ -653,6 +653,33 @@ def test_robot_ikine_rejects_badly_shaped_arrays(self): with self.assertRaises(ValueError): panda.ikine_LM(bad, q0=panda.qr) + def test_as_se3(self): + # the helper behind every Robot.ik_* and Robot.ikine_* method, so a + # regression in how SE3 treats an (N, 4, 4) array shows up here + from roboticstoolbox.robot.RobotKinematics import _as_se3 + + Ts = SE3.Rx([0.1, 0.2, 0.3]) * SE3(1, 2, 3) + stack = np.array(Ts.A) + self.assertEqual(stack.shape, (3, 4, 4)) + + T = _as_se3(stack) + self.assertIsInstance(T, SE3) + self.assertEqual(len(T), 3) + for i in range(3): + nt.assert_allclose(T[i].A, Ts[i].A) + + T = _as_se3(Ts[0].A) + self.assertEqual(len(T), 1) + nt.assert_allclose(T.A, Ts[0].A) + + T = _as_se3(Ts) + self.assertEqual(len(T), 3) + nt.assert_allclose(T.A, Ts.A) + + for bad in (np.eye(3), np.zeros((2, 3, 4)), np.zeros(16)): + with self.assertRaises(ValueError): + _as_se3(bad) + def test_ik_nr(self): tol = 1e-6 diff --git a/tests/test_pyplot_backend_fixes.py b/tests/test_pyplot_backend_fixes.py index 6724f5d90..89254f713 100644 --- a/tests/test_pyplot_backend_fixes.py +++ b/tests/test_pyplot_backend_fixes.py @@ -5,7 +5,6 @@ import importlib import unittest import unittest.mock as mock -from types import SimpleNamespace import matplotlib @@ -16,7 +15,6 @@ import roboticstoolbox as rtb from roboticstoolbox.backends.Connector import Connector from roboticstoolbox.backends.PyPlot import PyPlot, PyPlot2 -from roboticstoolbox.tools.plot import set_window_title from roboticstoolbox.backends.PyPlot.EllipsePlot import EllipsePlot, ShapePlot @@ -33,29 +31,6 @@ class TestWindowTitle(unittest.TestCase): def tearDown(self): plt.close("all") - @staticmethod - def figure_with(manager): - return SimpleNamespace(canvas=SimpleNamespace(manager=manager)) - - def test_sets_the_title(self): - manager = mock.Mock() - self.assertTrue(set_window_title(self.figure_with(manager), "a title")) - manager.set_window_title.assert_called_once_with("a title") - - def test_no_manager(self): - self.assertFalse(set_window_title(self.figure_with(None), "a title")) - - def test_manager_without_set_window_title(self): - class Manager: - pass - - self.assertFalse(set_window_title(self.figure_with(Manager()), "a title")) - - def test_figure_without_a_canvas_manager_attribute(self): - self.assertFalse( - set_window_title(SimpleNamespace(canvas=SimpleNamespace()), "a title") - ) - def test_both_backends_launch_headless(self): # Agg: the manager exists but is not a window for cls in (PyPlot, PyPlot2):