Skip to content

Commit 53455dd

Browse files
committed
Allow for closest_point
1 parent 95ffb01 commit 53455dd

File tree

1 file changed

+52
-18
lines changed

1 file changed

+52
-18
lines changed

roboticstoolbox/robot/DHRobot.py

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def angle(theta, fmt=None):
190190
Column("dⱼ", headalign="^"),
191191
*qlim_columns,
192192
border="thick"
193-
)
193+
)
194194
for j, L in enumerate(self):
195195
if has_qlim:
196196
if L.isprismatic:
@@ -214,7 +214,7 @@ def angle(theta, fmt=None):
214214
Column("⍺ⱼ", headalign="^"),
215215
*qlim_columns,
216216
border="thick"
217-
)
217+
)
218218
for j, L in enumerate(self):
219219
if has_qlim:
220220
if L.isprismatic:
@@ -227,7 +227,8 @@ def angle(theta, fmt=None):
227227
table.row(
228228
angle(L.theta), qstr(j, L), f"{L.a:.4g}", angle(L.alpha), *ql)
229229
else:
230-
table.row(qstr(j, L), f"{L.d:.4g}", f"{L.a:.4g}", angle(L.alpha), *ql)
230+
table.row(qstr(j, L), f"{L.d:.4g}",
231+
f"{L.a:.4g}", angle(L.alpha), *ql)
231232

232233
s += str(table)
233234

@@ -302,6 +303,41 @@ def __add__(self, L):
302303

303304
# return new
304305

306+
# --------------------------------------------------------------------- #
307+
308+
def _set_link_fk(self, q):
309+
'''
310+
robot._set_link_fk(q) evaluates fkine for each link within a
311+
robot and stores that pose in a private variable within the link.
312+
313+
This method is not for general use.
314+
315+
:param q: The joint angles/configuration of the robot
316+
:type q: float ndarray(n)
317+
318+
.. note::
319+
320+
- The robot's base transform, if present, are incorporated
321+
into the result.
322+
'''
323+
324+
q = getvector(q, self.n)
325+
326+
t = self.base
327+
328+
tall = self.fkine_all(q, old=True)
329+
330+
for i, link in enumerate(self.links):
331+
332+
# Update the link model transforms
333+
for col in link.collision:
334+
col.wT = tall[i]
335+
336+
for gi in link.geometry:
337+
gi.wT = tall[i]
338+
339+
# --------------------------------------------------------------------- #
340+
305341
@property
306342
def mdh(self):
307343
"""
@@ -512,7 +548,7 @@ def nbranches(self):
512548
:rtype: int
513549
514550
Number of branches in this robot.
515-
551+
516552
Example:
517553
518554
.. runblock:: pycon
@@ -525,8 +561,6 @@ def nbranches(self):
525561
"""
526562
return 1
527563

528-
529-
530564
def A(self, j, q=None):
531565
"""
532566
Link forward kinematics
@@ -631,7 +665,7 @@ def isspherical(self):
631665
(L[0].alpha == alpha[0] and L[1].alpha == alpha[1])
632666
or
633667
(L[0].alpha == alpha[1] and L[1].alpha == alpha[0])
634-
) \
668+
) \
635669
and L[0].sigma == 0 \
636670
and L[1].sigma == 0 \
637671
and L[2].sigma == 0
@@ -900,7 +934,6 @@ def fkine_path(self, q, old=None):
900934

901935
return T
902936

903-
904937
def segments(self):
905938

906939
segments = [None]
@@ -1114,26 +1147,25 @@ def jacob0(self, q=None, T=None, half=None, analytical=None, start=None, end=Non
11141147
elif analytical == 'exp':
11151148
# TODO: move to SMTB.base, Horner form with skew(v)
11161149
(theta, v) = trlog(t2r(T))
1117-
A = np.eye(3,3) - (1 - math.cos(theta)) / theta * skew(v) \
1150+
A = np.eye(3, 3) - (1 - math.cos(theta)) / theta * skew(v) \
11181151
+ (theta - math.sin(theta)) / theta * skew(v)**2
11191152
else:
11201153
raise ValueError('bad order specified')
1121-
1122-
J0 = block_diag(np.eye(3,3), np.linalg.inv(A)) @ J0
1154+
1155+
J0 = block_diag(np.eye(3, 3), np.linalg.inv(A)) @ J0
11231156

11241157
# TODO optimize computation above if half matrix is returned
11251158

11261159
# return top or bottom half if asked
11271160
if half is not None:
11281161
if half == 'trans':
1129-
J0 = J0[:3,:]
1162+
J0 = J0[:3, :]
11301163
elif half == 'rot':
1131-
J0 = J0[3:,:]
1164+
J0 = J0[3:, :]
11321165
else:
11331166
raise ValueError('bad half specified')
11341167
return J0
11351168

1136-
11371169
def hessian0(self, q=None, J0=None, start=None, end=None):
11381170
r"""
11391171
Manipulator Hessian in base frame
@@ -1162,14 +1194,14 @@ def hessian0(self, q=None, J0=None, start=None, end=None):
11621194
.. math::
11631195
11641196
\dmat{J} = \mat{H} \dvec{q}
1165-
1197+
11661198
and :math:`\mat{H} \in \mathbb{R}^{6\times n \times n}` is the
11671199
Hessian tensor.
11681200
11691201
The elements of the Hessian are
11701202
11711203
.. math::
1172-
1204+
11731205
\mat{H}_{i,j,k} = \frac{d^2 u_i}{d q_j d q_k}
11741206
11751207
where :math:`u = \{t_x, t_y, t_z, r_x, r_y, r_z\}` are the elements
@@ -1178,7 +1210,7 @@ def hessian0(self, q=None, J0=None, start=None, end=None):
11781210
Similarly, we can write
11791211
11801212
.. math::
1181-
1213+
11821214
\mat{J}_{i,j} = \frac{d u_i}{d q_j}
11831215
11841216
:references:
@@ -1489,7 +1521,7 @@ def removesmall(x):
14891521
_cross(wd, pstar)
14901522
+ _cross(w, _cross(w, pstar))
14911523
+ vd
1492-
) \
1524+
) \
14931525
+ 2 * _cross(Rt @ w, z0 * qd_k[j]) \
14941526
+ z0 * qdd_k[j]
14951527
# trailing underscore means new value, update here
@@ -1734,6 +1766,8 @@ def config_validate(self, config, allowables):
17341766
if all([a not in config for a in allowable]):
17351767
config += allowable[0]
17361768
return config
1769+
1770+
17371771
class SerialLink(DHRobot):
17381772
def __init__(self, *args, **kwargs):
17391773
warnings.warn(

0 commit comments

Comments
 (0)