Skip to content

Commit d860c9d

Browse files
committed
remove some magic .q
fix tests to suit
1 parent 50f81f7 commit d860c9d

File tree

2 files changed

+20
-48
lines changed

2 files changed

+20
-48
lines changed

roboticstoolbox/backend/PyPlot/functions.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
import roboticstoolbox as rp
88
import numpy as np
9-
from spatialmath.base.argcheck import getvector, verifymatrix
9+
from spatialmath.base.argcheck import getvector, getmatrix
1010
from roboticstoolbox.backend.PyPlot.EllipsePlot import EllipsePlot
1111
from matplotlib.widgets import Slider
1212
try:
@@ -24,20 +24,11 @@ def _plot(
2424
# Make an empty 3D figure
2525
env = rp.backend.PyPlot()
2626

27-
trajn = 1
27+
q = getmatrix(q, (None, robot.n))
2828

29-
if q is None:
30-
q = robot.q
31-
32-
try:
33-
q = getvector(q, robot.n, 'col')
34-
robot.q = q
35-
except ValueError:
36-
trajn = q.shape[1]
37-
verifymatrix(q, (robot.n, trajn))
3829

3930
# Add the robot to the figure in readonly mode
40-
if trajn == 1:
31+
if q.shape[0] == 1:
4132
env.launch(robot.name + ' Plot', limits)
4233
else:
4334
env.launch(robot.name + ' Trajectory Plot', limits)
@@ -63,9 +54,8 @@ def _plot(
6354
env.ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
6455
env.ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
6556

66-
if trajn != 1:
67-
for i in range(trajn):
68-
robot.q = q[:, i]
57+
for qk in q:
58+
robot.q = qk
6959
env.step()
7060
#time.sleep(dt/1000)
7161

@@ -97,20 +87,10 @@ def _plot2(
9787
# Make an empty 2D figure
9888
env = rp.backend.PyPlot2()
9989

100-
trajn = 1
101-
102-
if q is None:
103-
q = robot.q
104-
105-
try:
106-
q = getvector(q, robot.n, 'col')
107-
robot.q = q
108-
except ValueError:
109-
trajn = q.shape[1]
110-
verifymatrix(q, (robot.n, trajn))
90+
q = getmatrix(q, (None, robot.n))
11191

11292
# Add the robot to the figure in readonly mode
113-
if trajn == 1:
93+
if q.shape[0] == 1:
11494
env.launch(robot.name + ' Plot', limits)
11595
else:
11696
env.launch(robot.name + ' Trajectory Plot', limits)
@@ -127,11 +107,10 @@ def _plot2(
127107
fell = robot.fellipse(centre='ee')
128108
env.add(fell)
129109

130-
if trajn != 1:
131-
for i in range(trajn):
132-
robot.q = q[:, i]
133-
env.step()
134-
time.sleep(dt/1000)
110+
for qk in q:
111+
robot.q = qk
112+
env.step()
113+
time.sleep(dt/1000)
135114

136115
# Keep the plot open
137116
if block: # pragma: no cover

tests/test_DHRobot.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,7 @@ def test_teach_withq(self):
12631263

12641264
def test_plot(self):
12651265
panda = rp.models.DH.Panda()
1266-
panda.q = panda.qr
1267-
e = panda.plot(block=False)
1266+
e = panda.plot(panda.qr, block=False)
12681267
e.close()
12691268

12701269
def test_teach_basic(self):
@@ -1276,7 +1275,7 @@ def test_teach_basic(self):
12761275

12771276
def test_plot_traj(self):
12781277
panda = rp.models.DH.Panda()
1279-
q = np.random.rand(7, 3)
1278+
q = np.random.rand(3, 7)
12801279
e = panda.plot(block=False, q=q, dt=0)
12811280
e.close()
12821281

@@ -1326,25 +1325,22 @@ def test_plot_fellipse(self):
13261325

13271326
def test_plot_with_vellipse(self):
13281327
panda = rp.models.DH.Panda()
1329-
panda.q = panda.qr
1330-
e = panda.plot(block=False, vellipse=True)
1328+
e = panda.plot(panda.qr, block=False, vellipse=True)
13311329
e.close()
13321330

13331331
def test_plot_with_fellipse(self):
13341332
panda = rp.models.DH.Panda()
1335-
panda.q = panda.qr
1336-
e = panda.plot(block=False, fellipse=True)
1333+
e = panda.plot(panda.qr, block=False, fellipse=True)
13371334
e.close()
13381335

13391336
def test_plot2(self):
13401337
panda = rp.models.DH.Panda()
1341-
panda.q = panda.qr
1342-
e = panda.plot2(block=False, name=True)
1338+
e = panda.plot2(panda.qr, block=False, name=True)
13431339
e.close()
13441340

13451341
def test_plot2_traj(self):
13461342
panda = rp.models.DH.Panda()
1347-
q = np.random.rand(7, 3)
1343+
q = np.random.rand(3, 7)
13481344
e = panda.plot2(block=False, q=q, dt=0)
13491345
e.close()
13501346

@@ -1357,24 +1353,21 @@ def test_teach2_basic(self):
13571353

13581354
def test_teach2(self):
13591355
panda = rp.models.DH.Panda()
1360-
panda.q = panda.qr
1361-
e = panda.teach(block=False)
1356+
e = panda.teach(panda.qr, block=False)
13621357
e.close()
13631358

13641359
e2 = panda.teach2(block=False, q=panda.qr)
13651360
e2.close()
13661361

13671362
def test_plot_with_vellipse2(self):
13681363
panda = rp.models.DH.Panda()
1369-
panda.q = panda.qr
1370-
e = panda.plot2(block=False, vellipse=True, limits=[1, 2, 1, 2])
1364+
e = panda.plot2(panda.qr, block=False, vellipse=True, limits=[1, 2, 1, 2])
13711365
e.step()
13721366
e.close()
13731367

13741368
def test_plot_with_fellipse2(self):
13751369
panda = rp.models.DH.Panda()
1376-
panda.q = panda.qr
1377-
e = panda.plot2(block=False, fellipse=True)
1370+
e = panda.plot2(panda.qr, block=False, fellipse=True)
13781371
e.close()
13791372

13801373
def test_plot_with_vellipse2_fail(self):

0 commit comments

Comments
 (0)