Skip to content

Commit ad8505a

Browse files
committed
Gripper tests
1 parent 58c75ea commit ad8505a

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

roboticstoolbox/robot/Gripper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def __init__(
2020
if link.isjoint:
2121
self._n += 1
2222

23+
print(self.n)
24+
2325
self.q = np.zeros(self.n)
2426
self._links = elinks
2527

@@ -46,8 +48,8 @@ def visit_link(link, jindex):
4648
raise ValueError(
4749
'gripper joint index {link.jindex} was '
4850
'repeated or out of range')
49-
jset -= set(link.jindex)
50-
if len(jset) > 0:
51+
jset -= set([link.jindex])
52+
if len(jset) > 0: # pragma nocover # is impossible
5153
raise ValueError('gripper joints {jset} were not assigned')
5254
else:
5355
# must be a mixture of ELinks with/without jindex

tests/test_Gripper.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
@author: Jesse Haviland
3+
"""
4+
5+
import roboticstoolbox as rtb
6+
import unittest
7+
8+
9+
class TestGripper(unittest.TestCase):
10+
11+
def test_jindex_1(self):
12+
e1 = rtb.ELink(rtb.ETS.rz(), jindex=0)
13+
e2 = rtb.ELink(rtb.ETS.rz(), jindex=1, parent=e1)
14+
e3 = rtb.ELink(rtb.ETS.rz(), jindex=2, parent=e2)
15+
e5 = rtb.ELink(rtb.ETS.rz(), jindex=0, parent=e3)
16+
e7 = rtb.ELink(rtb.ETS.rz(), jindex=1, parent=e5)
17+
18+
rtb.ERobot([e1, e2, e3, e5, e7], gripper_links=e5)
19+
20+
def test_jindex_2(self):
21+
e1 = rtb.ELink(rtb.ETS.rz(), jindex=0)
22+
e2 = rtb.ELink(rtb.ETS.rz(), jindex=1, parent=e1)
23+
e3 = rtb.ELink(rtb.ETS.rz(), jindex=2, parent=e2)
24+
e4 = rtb.ELink(rtb.ETS.rz(), jindex=1, parent=e3)
25+
26+
with self.assertRaises(ValueError):
27+
rtb.ERobot([e1, e2, e3, e4], gripper_links=e4)
28+
29+
def test_jindex_3(self):
30+
e1 = rtb.ELink(rtb.ETS.rz(), jindex=0)
31+
e2 = rtb.ELink(rtb.ETS.rz(), jindex=1, parent=e1)
32+
e3 = rtb.ELink(rtb.ETS.rz(), jindex=2, parent=e2)
33+
e4 = rtb.ELink(rtb.ETS.rz(), jindex=0, parent=e3)
34+
e5 = rtb.ELink(rtb.ETS.rz(), parent=e4)
35+
36+
with self.assertRaises(ValueError):
37+
rtb.ERobot([e1, e2, e3, e4, e5], gripper_links=e4)
38+
39+
def test_jindex_4(self):
40+
e1 = rtb.ELink(rtb.ETS.rz())
41+
e2 = rtb.ELink(rtb.ETS.rz(), parent=e1)
42+
e3 = rtb.ELink(rtb.ETS.rz(), parent=e2)
43+
e4 = rtb.ELink(rtb.ETS.rz(), parent=e3)
44+
e5 = rtb.ELink(rtb.ETS.rz(), parent=e4)
45+
e6 = rtb.ELink(rtb.ETS.rz(), parent=e5)
46+
e7 = rtb.ELink(rtb.ETS.rz(), parent=e6)
47+
48+
rtb.ERobot([e1, e2, e3, e4, e5, e6, e7], gripper_links=e3)

0 commit comments

Comments
 (0)