Skip to content

Commit 0e610c8

Browse files
committed
factor out _getlink
1 parent a9ceb09 commit 0e610c8

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

roboticstoolbox/robot/ERobot.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -918,28 +918,49 @@ def _get_limit_links(self, endlink=None, startlink=None):
918918
raise ValueError('Must specify which end-effector')
919919
else:
920920
# end effector is specified
921-
if isinstance(endlink, str):
922-
endlink = self.link_dict[endlink]
923-
elif isinstance(endlink, ELink):
924-
if endlink not in self.links:
925-
raise ValueError('endlink not in robot links')
926-
else:
927-
raise TypeError('unknown endlink type')
921+
endlink = self._getlink(endlink)
928922

929923
if startlink is None:
930924
startlink = self.base_link
931925
else:
932-
# end effector is specified
933-
if isinstance(startlink, str):
934-
startlink = self.link_dict[startlink]
935-
elif isinstance(startlink, ELink):
936-
if startlink not in self.links:
937-
raise ValueError('startlink not in robot links')
938-
else:
939-
raise TypeError('unknown endlink type')
926+
# start effector is specified
927+
startlink = self._getlink(startlink)
940928

941929
return endlink, startlink
942930

931+
def _getlink(self, link, default=None):
932+
"""
933+
Validate reference to ELink
934+
935+
:param link: link
936+
:type link: ELink or str
937+
:raises ValueError: link does not belong to this ERobot
938+
:raises TypeError: bad argument
939+
:return: link reference
940+
:rtype: ELink
941+
942+
``robot._getlink(link)`` is a validated reference to an ELink within
943+
the ERobot ``robot``. If ``link`` is:
944+
945+
- an ``ELink`` reference it is validated as belonging to
946+
``robot``.
947+
- a string, then it looked up in the robot's link name dictionary, and
948+
an ELink reference returned.
949+
"""
950+
if link is None:
951+
link = default
952+
953+
if isinstance(link, str):
954+
if link not in self.link_dict:
955+
raise ValueError(f'no link named {link}')
956+
return self.link_dict[link]
957+
elif isinstance(link, ELink):
958+
if link not in self.links:
959+
raise ValueError('link not in robot links')
960+
return link
961+
else:
962+
raise TypeError('unknown argument')
963+
943964
def jacob0(self, q, endlink=None, startlink=None, offset=None, T=None):
944965
"""
945966
Manipulator geometric Jacobian in the base frame

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy