8000 allow link parent to be a str · oridong/robotics-toolbox-python@acdb1b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit acdb1b4

Browse files
committed
allow link parent to be a str
move handling to Link class
1 parent 4b6d822 commit acdb1b4

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

roboticstoolbox/robot/ELink.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@
1212

1313
class BaseELink(Link):
1414

15-
def __init__(self, name=None, joint_name=None):
15+
def __init__(self, name=None, parent=None, joint_name=None):
1616

1717
super().__init__()
1818

1919
self._name = name
20+
21+
if parent is not None:
22+
if isinstance(parent, (str, BaseELink)):
23+
self._parent = parent
24+
else:
25+
raise ValueError('parent must be BaseELink subclass or str')
26+
else:
27+
self._parent = None
28+
2029
self._joint_name = joint_name
2130

2231
self._jindex = None
2332
self._children = []
24-
self._parent = None
2533

2634
def __repr__(self):
2735
name = self.__class__.__name__
@@ -365,7 +373,6 @@ def __init__(
365373
ets=ETS(),
366374
v=None,
367375
jindex=None,
368-
parent=None,
369376
**kwargs):
370377

371378
# process common options
@@ -385,16 +392,6 @@ def __init__(
385392
elif jindex is None and v.jindex is not None:
386393
jindex = v.jindex
387394

388-
# TODO simplify this logic, can be ELink class or None
389-
# if isinstance(parent, list):
390-
# raise TypeError(
391-
# 'Only one parent link can be present')
392-
if not isinstance(parent, (ELink, str)) and parent is not None:
393-
raise TypeError(
394-
'Parent must be of type ELink, str or None')
395-
396-
397-
398395
# Initialise the static transform representing the constant
399396
# component of the ETS
400397
self._init_Ts()
@@ -600,7 +597,6 @@ def __init__(
600597
ets=ETS2(),
601598
v=None,
602599
jindex=None,
603-
parent=None,
604600
**kwargs):
605601

606602
# process common options
@@ -620,14 +616,6 @@ def __init__(
620616
elif jindex is None and v.jindex is not None:
621617
jindex = v.jindex
622618

623-
# TODO simplify this logic, can be ELink class or None
624-
# if isinstance(parent, list):
625-
# raise TypeError(
626-
# 'Only one parent link can be present')
627-
if not isinstance(parent, (ELink2, str)) and parent is not None:
628-
raise TypeError(
629-
'Parent must be of type ELink, str or None')
630-
631619
# Initialise the static transform representing the constant
632620
# component of the ETS
633621
self._init_Ts()

0 commit comments

Comments
 (0)
0