Skip to content

Commit 95ffb01

Browse files
committed
Adjust for str parent
1 parent e6ab71b commit 95ffb01

File tree

2 files changed

+57
-38
lines changed

2 files changed

+57
-38
lines changed

roboticstoolbox/robot/ELink.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def ets(self):
267267
:rtype: ETS or ETS2 instance
268268
269269
The sequence:
270-
270+
271271
- has at least one element
272272
- may include zero or more constant transforms
273273
- no more than one variable transform, which if present will
@@ -453,6 +453,10 @@ def _get_fknm(self):
453453
return isflip, axis, jindex, parent, shape_base, shape_wT, shape_sT
454454

455455
def _init_fknm(self):
456+
if isinstance(self.parent, str):
457+
# Initialise later
458+
return
459+
456460
isflip, axis, jindex, parent, \
457461
shape_base, shape_wT, shape_sT = self._get_fknm()
458462

@@ -467,6 +471,7 @@ def _update_fknm(self):
467471
# Check if not initialized yet
468472
try:
469473
if self._fknm is None:
474+
self._init_fknm()
470475
return
471476
except AttributeError:
472477
return
@@ -751,5 +756,5 @@ def A(self, q=0.0, **kwargs):
751756
return SE2(T, check=False)
752757

753758

754-
l0 = ELink(qlim=[-1, 1])
755-
print(l0.qlim)
759+
# l0 = ELink(qlim=[-1, 1])
760+
# print(l0.qlim)

roboticstoolbox/robot/ERobot.py

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ def __init__(
146146
for link in links:
147147
if isinstance(link.parent, str):
148148
link._parent = self._linkdict[link.parent]
149+
# Update the fast kinematics object
150+
if isinstance(self, ERobot):
151+
link._init_fknm()
149152

150153
if all([link.parent is None for link in links]):
151154
# no parent links were given, assume they are sequential
@@ -1039,6 +1042,8 @@ def URDF(cls, file_path, gripper=None):
10391042

10401043
return cls(links, name=name, gripper_links=gripper)
10411044

1045+
# --------------------------------------------------------------------- #
1046+
10421047
def _reset_cache(self):
10431048
self._path_cache = {}
10441049
self._path_cache_fknm = {}
@@ -1080,9 +1085,9 @@ def _reset_cache(self):
10801085
# path.reverse()
10811086
# return path
10821087

1083-
def to_dict(self, show_robot=True, show_collision=False):
1088+
def _to_dict(self, show_robot=True, show_collision=False):
10841089

1085-
self.fkine_links(self.q)
1090+
self._set_link_fk(self.q)
10861091

10871092
ob = []
10881093

@@ -1108,7 +1113,7 @@ def to_dict(self, show_robot=True, show_collision=False):
11081113

11091114
return ob
11101115

1111-
def fk_dict(self, show_robot=True, show_collision=False):
1116+
def _fk_dict(self, show_robot=True, show_collision=False):
11121117
ob = []
11131118

11141119
# Do the robot
@@ -1133,6 +1138,47 @@ def fk_dict(self, show_robot=True, show_collision=False):
11331138

11341139
return ob
11351140

1141+
def _set_link_fk(self, q):
1142+
'''
1143+
robot._set_link_fk(q) evaluates fkine for each link within a
1144+
robot and stores that pose in a private variable within the link.
1145+
1146+
This method is not for general use.
1147+
1148+
:param q: The joint angles/configuration of the robot
1149+
:type q: float ndarray(n)
1150+
1151+
.. note::
1152+
1153+
- The robot's base transform, if present, are incorporated
1154+
into the result.
1155+
1156+
:references:
1157+
- Kinematic Derivatives using the Elementary Transform
1158+
Sequence, J. Haviland and P. Corke
1159+
1160+
'''
1161+
1162+
if self._base is None:
1163+
base = self._eye_fknm
1164+
else:
1165+
base = self._base.A
1166+
1167+
fknm.fkine_all(
1168+
self._cache_m,
1169+
self._cache_links_fknm,
1170+
q,
1171+
base)
1172+
1173+
for i in range(len(self._cache_grippers)):
1174+
fknm.fkine_all(
1175+
len(self._cache_grippers[i]),
1176+
self._cache_grippers[i],
1177+
self.grippers[i].q,
1178+
base)
1179+
1180+
# --------------------------------------------------------------------- #
1181+
11361182
@staticmethod
11371183
def URDF_read(file_path, tld=None):
11381184
"""
@@ -1279,38 +1325,6 @@ def fkine(
12791325

12801326
return T
12811327

1282-
# def fkine_links(self, q):
1283-
# '''
1284-
# robot.fkine_links(q) evaluates fkine for each link within a
1285-
# robot and stores that pose within the link.
1286-
1287-
# :param q: The joint angles/configuration of the robot
1288-
# :type q: float ndarray(n)
1289-
1290-
# .. note::
1291-
1292-
# - The robot's base transform, if present, are incorporated
1293-
# into the result.
1294-
1295-
# :references:
1296-
# - Kinematic Derivatives using the Elementary Transform
1297-
# Sequence, J. Haviland and P. Corke
1298-
1299-
# '''
1300-
1301-
# fknm.fkine_all(
1302-
# self._cache_m,
1303-
# self._cache_links_fknm,
1304-
# q,
1305-
# self._base.A)
1306-
1307-
# for i in range(len(self._cache_grippers)):
1308-
# fknm.fkine_all(
1309-
# len(self._cache_grippers[i]),
1310-
# self._cache_grippers[i],
1311-
# self.grippers[i].q,
1312-
# self._base.A)
1313-
13141328
def get_path(self, end=None, start=None, _fknm=False):
13151329
"""
13161330
Find a path from start to end. The end must come after

0 commit comments

Comments
 (0)