8000 constructors allows list of links with either no parents listed, or p… · oridong/robotics-toolbox-python@39bb7ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 39bb7ff

Browse files
committed
constructors allows list of links with either no parents listed, or parents as strings
1 parent ea3dbc5 commit 39bb7ff

File tree

1 file changed

+25
-63
lines changed

1 file changed

+25
-63
lines changed

roboticstoolbox/robot/ERobot.py

Lines changed: 25 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ class BaseERobot(Robot):
123123
:references:
124124
- Kinematic Derivatives using the Elementary Transform Sequence,
125125
J. Haviland and P. Corke
126-
"""
126+
""" # noqa E501
127127

128128
def __init__(
129129
self,
130-
arg,
130+
links,
131131
base_link=None,
132132
gripper_links=None,
133133
checkjindex=True,
@@ -144,72 +144,34 @@ def __init__(
144144
# search order
145145
orlinks = []
146146

147-
if isinstance(arg, DHRobot):
148-
# we're passed a DHRobot object
149-
# TODO handle dynamic parameters if given
150-
args = args.ets()
151-
152-
link_number = 0
153-
if isinstance(arg, ETS):
154-
# we're passed an ETS string
155-
ets = arg
156-
links = []
157147

158-
# chop it up into segments, a link frame after every joint
159-
start = 0
160-
for j, k in enumerate(ets.joints()):
161-
ets_j = ets[start:k + 1]
162-
start = k + 1
163-
if j == 0:
164-
parent = None
165-
else:
166-
parent = links[-1]
167-
elink = ELink(ets_j, parent=parent, name=f"link{j:d}")
168-
links.append(elink)
169-
170-
n = len(ets.joints())
171-
172-
tool = ets[start:]
173-
if len(tool) > 0:
174-
links.append(ELink(tool, parent=links[-1], name="ee"))
175-
176-
elif isinstance(arg, list):
177-
# we're passed a list of ELinks
148+
# check all the incoming ELink objects
149+
n = 0
150+
for link in links:
151+
# if link has no name, give it one
152+
if link.name is None:
153+
link.name = f"link-{link_number}"
154+
link_number += 1
178155

179-
# check all the incoming ELink objects
180-
n = 0
181-
ndims = None
182-
links = arg
183-
for link in links:
184-
if isinstance(link, ELink):
185-
# if link has no name, give it one
186-
if link.name is None:
187-
link.name = f"link-{link_number}"
188-
link_number += 1
189-
190-
# put it in the link dictionary, check for duplicates
191-
if link.name in self._linkdict:
192-
raise ValueError(
193-
f'link name {link.name} is not unique')
194-
self._linkdict[link.name] = link
195-
else:
196-
raise TypeError("Input can be only ELink")
197-
if link.isjoint:
198-
n += 1
156+
# put it in the link dictionary, check for duplicates
157+
if link.name in self._linkdict:
158+
raise ValueError(
159+
f'link name {link.name} is not unique')
160+
self._linkdict[link.name] = link
199161

200-
# resolve parents given by name, within the context of
201-
# this set of links
202-
for link in links:
203-
if isinstance(link.parent, str):
204-
link._parent = self._linkdict[link.parent]
162+
if link.isjoint:
163+
n += 1
205164

206-
if all([link.parent is None for link in links]):
207-
# no parent links were given, assume they are sequential
208-
for i in range(len(links) - 1):
209-
links[i + 1]._parent = links[i]
165+
# resolve parents given by name, within the context of
166+
# this set of links
167+
for link in links:
168+
if isinstance(link.parent, str):
169+
link._parent = self._linkdict[link.parent]
210170

211-
else:
212-
raise TypeError('elinks must be a list of ELinks or an ETS')
171+
if all([link.parent is None for link in links]):
172+
# no parent links were given, assume they are sequential
173+
for i in range(len(links) - 1):
174+
links[i + 1]._parent = links[i]
213175

214176
self._n = n
215177

0 commit comments

Comments
 (0)
0