8000 add method to validate ikine config strings · hanm2019/robotics-toolbox-python@2c11715 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c11715

Browse files
committed
add method to validate ikine config strings
1 parent 146342f commit 2c11715

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

roboticstoolbox/models/DH/Puma560.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ def ikine_a(self, T, config="lun"):
230230
"""
231231
def ik3(robot, T, config='lun'):
232232

233+
config = self.config_validate(config, ('lr', 'ud', 'nf'))
234+
233235
# solve for the first three joints
234236

235237
a2 = robot.links[1].a

roboticstoolbox/robot/DHRobot.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,49 @@ def ikine_6s(self, T, config, ikfunc):
16511651
else:
16521652
return solutions
16531653

1654+
def config_validate(self, config, allowables):
1655+
"""
1656+
Validate a configuration string
1657+
1658+
:param config: a configuration string
1659+
:type config: str
1660+
:param allowable: [description]
1661+
:type allowable: tuple of str
1662+
:raises ValueError: bad character in configuration string
1663+
:return: configuration string
1664+
:rtype: str
1665+
1666+
For analytic inverse kinematics the Toolbox uses a stri 10000 ng whose
1667+
letters indicate particular solutions, eg. for the Puma 560
1668+
1669+
========= ===================
1670+
Character Meaning
1671+
========= ===================
1672+
'l' lefty
1673+
'r' righty
1674+
'u' elbow up
1675+
'd' elbow down
1676+
'n' wrist not flipped
1677+
'f' wrist flipped
1678+
========= ===================
16541679
1680+
This method checks that the configuration string is valid and adds
1681+
default values for missing characters. For example:
1682+
1683+
config = self.config_validate(config, ('lr', 'ud', 'nf'))
1684+
1685+
indicates the valid characters, and the first character in each
1686+
string is the default, ie. if neither 'l' or 'r' is given then
1687+
'l' will be added to the string.
1688+
1689+
"""
1690+
for c in config:
1691+
if not any([c in allowable for allowable in allowables]):
1692+
raise ValueError(f"bad config specifier <{c}>")
1693+
for allowable in allowables:
1694+
if all([a not in config for a in allowable]):
1695+
config += allowable[0]
1696+
return config
16551697
class SerialLink(DHRobot):
16561698
def __init__(self, *args, **kwargs):
16571699
print('SerialLink is deprecated, use DHRobot instead')

tests/test_DHRobot.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,15 @@ def test_ikine_a(self):
867867

868868
T = puma.fkine(puma.qn)
869869

870+
# test configuration validation
871+
config = puma.config_validate('l', ('lr', 'ud', 'nf'))
872+
self.assertEqual(len(config), 3)
873+
self.assertTrue('l' in config)
874+
self.assertTrue('u' in config)
875+
self.assertTrue('n' in config)
876+
with self.assertRaises(ValueError):
877+
config = puma.config_validate('lux', ('lr', 'ud', 'nf'))
878+
870879
# analytic solution
871880
sol = puma.ikine_a(T)
872881
self.assertTrue(sol.success)

0 commit comments

Comments
 (0)
0