Skip to content

Commit 7a3560b

Browse files
committed
Link tests finished
1 parent 57672b9 commit 7a3560b

File tree

2 files changed

+122
-3
lines changed

2 files changed

+122
-3
lines changed

tests/test_ELink.py

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import spatialgeometry as gm
1111
import unittest
1212
import spatialmath as sm
13+
from roboticstoolbox.robot.Link import BaseLink
1314

1415

1516
class TestLink(unittest.TestCase):
@@ -86,6 +87,13 @@ def test_Tc(self):
8687
nt.assert_array_almost_equal(l1.Tc, Tc1)
8788
nt.assert_array_almost_equal(l2.Tc, Tc2)
8889

90+
def test_B(self):
91+
l0 = rtb.Link(B=1.0)
92+
l1 = rtb.Link(B=None)
93+
94+
nt.assert_array_almost_equal(l0.B, 1.0)
95+
nt.assert_array_almost_equal(l1.B, 0.0)
96+
8997
def test_I(self):
9098
l0 = rtb.Link(I=[1, 2, 3])
9199
l1 = rtb.Link(I=[0, 1, 2, 3, 4, 5])
@@ -147,7 +155,7 @@ def test_dyn(self):
147155
B = 0
148156
Tc = 0.4(+) -0.43(-)
149157
G = -63
150-
qlim = -2.8 to 2.8""",
158+
qlim = -2.8 to 2.8""", # noqa
151159
)
152160

153161
def test_properties(self):
@@ -231,6 +239,117 @@ def test_collided(self):
231239
self.assertTrue(c0)
232240
self.assertFalse(c1)
233241

242+
def test_init_ets2(self):
243+
e1 = rtb.ET2.R()
244+
link = BaseLink(e1)
245+
246+
nt.assert_almost_equal(link.Ts, np.eye(4))
247+
248+
def test_get_ets(self):
249+
e1 = rtb.ETS(rtb.ET.Ry())
250+
link = rtb.Link(e1)
251+
252+
self.assertEqual(link.ets, e1)
253+
254+
def test_set_ets_fail(self):
255+
e1 = rtb.ETS(rtb.ET.Ry())
256+
e2 = rtb.ET.Ry() * rtb.ET.Rx(1.0)
257+
link = rtb.Link(e1)
258+
259+
with self.assertRaises(ValueError):
260+
link.ets = e2
261+
262+
def test_set_robot(self):
263+
e1 = rtb.ETS(rtb.ET.Ry())
264+
link = rtb.Link(e1)
265+
266+
robot = rtb.models.Panda()
267+
268+
link.robot = robot
269+
270+
self.assertEqual(link.robot, robot)
271+
272+
def test_set_qlim_fail(self):
273+
e1 = rtb.ETS(rtb.ET.Ry(1.0))
274+
link = rtb.Link(e1)
275+
276+
with self.assertRaises(ValueError):
277+
link.qlim = [1.0, 2.0]
278+
279+
def test_set_collision(self):
280+
e1 = rtb.ETS(rtb.ET.Ry())
281+
link = rtb.Link(e1)
282+
283+
s1 = gm.Cuboid([1.0, 1.0, 1.0])
284+
285+
link.collision = s1
286+
287+
self.assertEqual(link.collision[0], s1)
288+
289+
def test_set_collision2(self):
290+
e1 = rtb.ETS(rtb.ET.Ry())
291+
link = rtb.Link(e1)
292+
293+
s1 = gm.Cuboid([1.0, 1.0, 1.0])
294+
295+
sg = gm.SceneGroup()
296+
sg.append(s1)
297+
298+
link.collision = sg
299+
300+
self.assertEqual(link.collision[0], sg[0])
301+
302+
def test_set_geometry(self):
303+
e1 = rtb.ETS(rtb.ET.Ry())
304+
link = rtb.Link(e1)
305+
306+
s1 = gm.Cuboid([1.0, 1.0, 1.0])
307+
308+
link.geometry = s1
309+
310+
self.assertEqual(link.geometry[0], s1)
311+
312+
def test_set_geometry2(self):
313+
e1 = rtb.ETS(rtb.ET.Ry())
314+
link = rtb.Link(e1)
315+
316+
s1 = gm.Cuboid([1.0, 1.0, 1.0])
317+
318+
sg = gm.SceneGroup()
319+
sg.append(s1)
320+
321+
link.geometry = sg
322+
323+
self.assertEqual(link.geometry[0], sg[0])
324+
325+
def test_dyn2list(self):
326+
l1 = rtb.Link(I=[0, 1, 2, 3, 4, 5])
327+
328+
s = l1._dyn2list()
329+
330+
print(s)
331+
332+
ans = [" 0", " 0, 0, 0", " 0, 1, 2, 3, 5, 4", " 0", " 0", " 0, 0", " 0"]
333+
334+
self.assertEqual(s, ans)
335+
336+
def test_init_fail4(self):
337+
338+
with self.assertRaises(TypeError):
339+
rtb.Link(2.0) # type: ignore
340+
341+
def test_ets2_A(self):
342+
e1 = rtb.ETS2(rtb.ET2.R())
343+
link = rtb.Link2(e1)
344+
345+
nt.assert_almost_equal(link.A(1.0).A, sm.SE2(0.0, 0.0, 1.0).A)
346+
347+
def test_ets2_A2(self):
348+
e1 = rtb.ETS2(rtb.ET2.R(1.0))
349+
link = rtb.Link2(e1)
350+
351+
nt.assert_almost_equal(link.A().A, sm.SE2(0.0, 0.0, 1.0).A)
352+
234353

235354
if __name__ == "__main__":
236355

tests/test_Link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def test_dyn(self):
142142
B = 0.0015
143143
Tc = 0.4(+) -0.43(-)
144144
G = -63
145-
qlim = -2.8 to 2.8""",
146-
) # noqa
145+
qlim = -2.8 to 2.8""", # noqa
146+
)
147147

148148
puma.links[0].dyn(indent=2)
149149

0 commit comments

Comments
 (0)