Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/roboticstoolbox/backends/PyPlot/PyPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

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
from roboticstoolbox.backends.Connector import Connector
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
Expand Down
2 changes: 1 addition & 1 deletion src/roboticstoolbox/backends/PyPlot/PyPlot2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/roboticstoolbox/mobile/Vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/roboticstoolbox/robot/RobotKinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
27 changes: 0 additions & 27 deletions src/roboticstoolbox/tools/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {
Expand Down
27 changes: 27 additions & 0 deletions tests/test_IK.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions tests/test_pyplot_backend_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import importlib
import unittest
import unittest.mock as mock
from types import SimpleNamespace

import matplotlib

Expand All @@ -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


Expand All @@ -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):
Expand Down
Loading