File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -126,9 +126,9 @@ def __getitem__(self, i):
126
126
"""
127
127
Get link (Robot superclass)
128
128
129
- :param i: link number
130
- :type i: int
131
- :return: i'th link of robot
129
+ :param i: link number or name
130
+ :type i: int or str
131
+ :return: i'th link or named link
132
132
:rtype: Link subclass
133
133
134
134
This also supports iterating over each link in the robot object,
@@ -141,8 +141,18 @@ def __getitem__(self, i):
141
141
>>> print(robot[1]) # print the 2nd link
142
142
>>> print([link.a for link in robot]) # print all the a_j values
143
143
144
+ .. note:: ``ERobot`` supports link lookup by name,
145
+ eg. ``robot['link1']``
144
146
"""
145
- return self ._links [i ]
147
+ if isinstance (i , str ):
148
+ try :
149
+ return self .link_dict [i ]
150
+ except KeyError :
151
+ raise KeyError (f"link { i } not in link dictionary" )
152
+ except AttributeError :
153
+ raise AttributeError (f"robot has no link dictionary" )
154
+ else :
155
+ return self ._links [i ]
146
156
147
157
# URDF Parser Attempt
148
158
# @staticmethod
You can’t perform that action at this time.
0 commit comments