|
10 | 10 | import spatialgeometry as gm |
11 | 11 | import unittest |
12 | 12 | import spatialmath as sm |
| 13 | +from roboticstoolbox.robot.Link import BaseLink |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class TestLink(unittest.TestCase): |
@@ -86,6 +87,13 @@ def test_Tc(self): |
86 | 87 | nt.assert_array_almost_equal(l1.Tc, Tc1) |
87 | 88 | nt.assert_array_almost_equal(l2.Tc, Tc2) |
88 | 89 |
|
| 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 | + |
89 | 97 | def test_I(self): |
90 | 98 | l0 = rtb.Link(I=[1, 2, 3]) |
91 | 99 | l1 = rtb.Link(I=[0, 1, 2, 3, 4, 5]) |
@@ -147,7 +155,7 @@ def test_dyn(self): |
147 | 155 | B = 0 |
148 | 156 | Tc = 0.4(+) -0.43(-) |
149 | 157 | G = -63 |
150 | | -qlim = -2.8 to 2.8""", |
| 158 | +qlim = -2.8 to 2.8""", # noqa |
151 | 159 | ) |
152 | 160 |
|
153 | 161 | def test_properties(self): |
@@ -231,6 +239,117 @@ def test_collided(self): |
231 | 239 | self.assertTrue(c0) |
232 | 240 | self.assertFalse(c1) |
233 | 241 |
|
| 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 | + |
234 | 353 |
|
235 | 354 | if __name__ == "__main__": |
236 | 355 |
|
|
0 commit comments