Skip to content

Commit 79c2271

Browse files
committed
changes to common graphics code
1 parent e8c594e commit 79c2271

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

roboticstoolbox/robot/Robot.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,10 @@ def base(self):
708708
is an identity matrix.
709709
"""
710710
if self._base is None:
711-
self._base = SE3()
711+
if isinstance(self, ERobot2):
712+
self._base = SE2()
713+
else:
714+
self._base = SE3()
712715

713716
return self._base
714717

@@ -881,6 +884,35 @@ def control_type(self, cn):
881884

882885
# --------------------------------------------------------------------- #
883886

887+
# TODO probably should be a static method
888+
def _get_graphical_backend(self, backend):
889+
#
890+
# find the right backend, modules are imported here on an as needs basis
891+
if backend.lower() == 'swift': # pragma nocover
892+
if isinstance(self, rtb.DHRobot):
893+
raise NotImplementedError(
894+
'Plotting in Swift is not implemented for DHRobots yet')
895+
896+
from roboticstoolbox.backends.Swift import Swift
897+
env = Swift()
898+
899+
elif backend.lower() == 'pyplot':
900+
from roboticstoolbox.backends.PyPlot import PyPlot
901+
env = PyPlot()
902+
903+
elif backend.lower() == 'pyplot2':
904+
from roboticstoolbox.backends.PyPlot import PyPlot2
905+
env = PyPlot2()
906+
907+
elif backend.lower() == 'vpython':
908+
from roboticstoolbox.backends.VPython import VPython
909+
env = VPython()
910+
911+
else:
912+
raise ValueError('unknown backend', backend)
913+
914+
return env
915+
884916
def plot(
885917
self, q, backend=None, block=False, dt=0.050,
886918
limits=None, vellipse=False, fellipse=False,
@@ -1457,12 +1489,8 @@ def teach(
14571489
occurs.
14581490
"""
14591491

1460-
if isinstance(self, rtb.ERobot): # pragma nocover
1461-
raise NotImplementedError(
1462-
"2D Plotting of ERobot's not implemented yet")
1463-
1464-
if q is not None:
1465-
self.q = q
1492+
if q is None:
1493+
q = np.zeros((self.n,))
14661494

14671495
# Make an empty 3D figure
14681496
env = self._get_graphical_backend(backend)
@@ -1473,7 +1501,7 @@ def teach(
14731501
self, readonly=True,
14741502
jointaxes=jointaxes, eeframe=eeframe, shadow=shadow, name=name)
14751503

1476-
env._add_teach_panel(self)
1504+
env._add_teach_panel(self, q)
14771505

14781506
# Keep the plot open
14791507
if block: # pragma: no cover

0 commit comments

Comments
 (0)