Skip to content

Commit 45e48aa

Browse files
committed
Changes to allow RVC 3.3.3 to run as printed
1 parent 05d5dee commit 45e48aa

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

roboticstoolbox/tools/plot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
33

4+
45
def xplot(
56
x,
67
y=None,
@@ -101,7 +102,7 @@ def xplot(
101102
plt.grid(grid)
102103
ax.set_xlabel("Time (s)")
103104
ax.set_ylabel("Joint coordinates (rad,m)")
104-
ax.set_xlim(t[0], t[-1])
105+
# ax.set_xlim(t[0], t[-1]) fails with RVC3 Sec 3.3.3
105106

106107
plt.show(block=block)
107108

roboticstoolbox/tools/trajectory.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def __init__(self, name, t, s, sd=None, sdd=None, istime=False):
5757
self.istime = istime
5858

5959
def __str__(self):
60-
s = f"Trajectory created by {self.name}: {len(self)} time steps x {self.naxes} axes"
60+
s = (
61+
f"Trajectory created by {self.name}: {len(self)} time steps x"
62+
f" {self.naxes} axes"
63+
)
6164
return s
6265

6366
def __repr__(self):
@@ -162,11 +165,15 @@ def plot(self, block=False, plotargs=None, textargs=None):
162165
if textargs is not None:
163166
textopts = {**textopts, **textargs}
164167

168+
nplots = 3
169+
if self.name == "mstraj":
170+
nplots = 1
171+
165172
plt.figure()
166-
ax = plt.subplot(3, 1, 1)
173+
ax = plt.subplot(nplots, 1, 1)
167174

168175
# plot position
169-
if self.name == "quintic":
176+
if self.name in "quintic":
170177
ax.plot(self.t, self.s, **plotopts)
171178

172179
elif self.name == "trapezoidal":
@@ -214,29 +221,30 @@ def plot(self, block=False, plotargs=None, textargs=None):
214221
else:
215222
ax.set_ylabel("$q(k)$", **textopts)
216223

217-
# plot velocity
218-
ax = plt.subplot(3, 1, 2)
219-
ax.plot(self.t, self.sd, **plotopts)
220-
ax.grid(True)
221-
ax.set_xlim(0, max(self.t))
224+
if nplots > 1:
225+
# plot velocity
226+
ax = plt.subplot(3, 1, 2)
227+
ax.plot(self.t, self.sd, **plotopts)
228+
ax.grid(True)
229+
ax.set_xlim(0, max(self.t))
222230

223-
if self.istime:
224-
ax.set_ylabel("$\dot{{q}}(t)$", **textopts)
225-
else:
226-
ax.set_ylabel("$dq/dk$", **textopts)
231+
if self.istime:
232+
ax.set_ylabel("$\dot{{q}}(t)$", **textopts)
233+
else:
234+
ax.set_ylabel("$dq/dk$", **textopts)
227235

228-
# plot acceleration
229-
ax = plt.subplot(3, 1, 3)
230-
ax.plot(self.t, self.sdd, **plotopts)
231-
ax.grid(True)
232-
ax.set_xlim(0, max(self.t))
236+
# plot acceleration
237+
ax = plt.subplot(3, 1, 3)
238+
ax.plot(self.t, self.sdd, **plotopts)
239+
ax.grid(True)
240+
ax.set_xlim(0, max(self.t))
233241

234-
if self.istime:
235-
ax.set_ylabel(f"$\ddot{{q}}(t)$", **textopts)
236-
ax.set_xlabel("t (seconds)")
237-
else:
238-
ax.set_ylabel("$d^2q/dk^2$", **textopts)
239-
ax.set_xlabel("k (step)")
242+
if self.istime:
243+
ax.set_ylabel(f"$\ddot{{q}}(t)$", **textopts)
244+
ax.set_xlabel("t (seconds)")
245+
else:
246+
ax.set_ylabel("$d^2q/dk^2$", **textopts)
247+
ax.set_xlabel("k (step)")
240248

241249
plt.show(block=block)
242250

@@ -970,10 +978,13 @@ def mrange(start, stop, step):
970978
qd = dq / tseg
971979

972980
# add the blend polynomial
973-
qb = jtraj(q0, q_prev + tacc2 * qd, mrange(0, taccx, dt), qd0=qd_prev, qd1=qd).s
974-
if verbose: # pragma nocover
975-
print(qb)
976-
tg = np.vstack([tg, qb[1:, :]])
981+
if taccx > 0:
982+
qb = jtraj(
983+
q0, q_prev + tacc2 * qd, mrange(0, taccx, dt), qd0=qd_prev, qd1=qd
984+
).s
985+
if verbose: # pragma nocover
986+
print(qb)
987+
tg = np.vstack([tg, qb[1:, :]])
977988

978989
clock = clock + taccx # update the clock
979990

@@ -990,8 +1001,9 @@ def mrange(start, stop, step):
9901001
qd_prev = qd
9911002

9921003
# add the final blend
993-
qb = jtraj(q0, q_next, mrange(0, tacc2, dt), qd0=qd_prev, qd1=qdf).s
994-
tg = np.vstack([tg, qb[1:, :]])
1004+
if tacc2 > 0:
1005+
qb = jtraj(q0, q_next, mrange(0, tacc2, dt), qd0=qd_prev, qd1=qdf).s
1006+
tg = np.vstack([tg, qb[1:, :]])
9951007

9961008
infolist.append(info(None, tseg, clock))
9971009

@@ -1020,8 +1032,14 @@ def mrange(start, stop, step):
10201032
# t.plot(block=True)
10211033

10221034
from roboticstoolbox import *
1035+
from spatialmath import SO2
1036+
1037+
# puma = models.DH.Puma560()
10231038

1024-
puma = models.DH.Puma560()
1039+
# traj = jtraj(puma.qz, puma.qr, 100)
1040+
# traj.plot(block=True)
10251041

1026-
traj = jtraj(puma.qz, puma.qr, 100)
1027-
traj.plot(block=True)
1042+
via = SO2(30, unit="deg") * np.array([[-1, 1, 1, -1, -1], [1, 1, -1, -1, 1]])
1043+
traj0 = mstraj(via.T, dt=0.2, tacc=0.5, qdmax=[2, 1])
1044+
xplot(traj0.q[:, 0], traj0.q[:, 1], color="red")
1045+
traj0.plot(block=True)

0 commit comments

Comments
 (0)