Skip to content

Commit 57377e0

Browse files
committed
ETS Tests finished
1 parent a681196 commit 57377e0

File tree

2 files changed

+110
-7
lines changed

2 files changed

+110
-7
lines changed

roboticstoolbox/robot/ETS.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __str__(self, q: Union[str, None] = None):
163163
elif et.istranslation:
164164
try:
165165
s = f"{et.axis}({et.eta:.4g})"
166-
except TypeError:
166+
except TypeError: # pragma: nocover
167167
s = f"{et.axis}({et.eta})"
168168

169169
elif not et.iselementary:
@@ -198,7 +198,7 @@ def _repr_pretty_(self, p, cycle):
198198
199199
"""
200200

201-
print(self.__str__())
201+
print(self.__str__()) # pragma: nocover
202202

203203
def joint_idx(self) -> List[int]:
204204
"""
@@ -302,8 +302,6 @@ def qlim(self):
302302
ValueError
303303
unset limits for a prismatic joint
304304
305-
306-
307305
Examples
308306
--------
309307
.. runblock:: pycon
@@ -327,7 +325,7 @@ def qlim(self):
327325
else:
328326
v = et.qlim
329327
else:
330-
raise ValueError("Undefined Joint Type")
328+
raise ValueError("Undefined Joint Type") # pragma: nocover
331329
limits[:, i] = v
332330

333331
return limits
@@ -784,7 +782,7 @@ def __init__(
784782
raise ValueError(
785783
"You can not have some jindices set for the ET's in arg. It must be all"
786784
" or none"
787-
)
785+
) # pragma: nocover
788786
elif jindices == 0 and self.n > 0:
789787
# Set them ourself
790788
for j, joint in enumerate(joints):
@@ -3154,7 +3152,7 @@ def __init__(
31543152
raise ValueError(
31553153
"You can not have some jindices set for the ET's in arg. It must be all"
31563154
" or none"
3157-
)
3155+
) # pragma: nocover
31583156
elif jindices == 0 and self.n > 0:
31593157
# Set them ourself
31603158
for j, joint in enumerate(joints):

tests/test_ETS.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,6 +4235,111 @@ def test_partial_fkine(self):
42354235
nt.assert_almost_equal(fk, ans)
42364236
nt.assert_almost_equal(fk2, ans)
42374237

4238+
def test_qlim1(self):
4239+
rx = rtb.ETS(rtb.ET.Rx())
4240+
4241+
q = rx.qlim
4242+
nt.assert_equal(q, np.array([[-np.pi], [np.pi]]))
4243+
4244+
def test_qlim2(self):
4245+
rx = rtb.ETS(rtb.ET.Rx(qlim=[-1, 1]))
4246+
4247+
q = rx.qlim
4248+
nt.assert_equal(q, np.array([[-1], [1]]))
4249+
4250+
def test_qlim3(self):
4251+
rx = rtb.ETS(rtb.ET.tx(qlim=[-1, 1]))
4252+
4253+
q = rx.qlim
4254+
nt.assert_equal(q, np.array([[-1], [1]]))
4255+
4256+
def test_qlim4(self):
4257+
rx = rtb.ETS(rtb.ET.tx())
4258+
4259+
with self.assertRaises(ValueError):
4260+
rx.qlim
4261+
4262+
def test_random_q(self):
4263+
rx = rtb.ETS(rtb.ET.Rx(qlim=[-1, 1]))
4264+
4265+
q = rx.random_q()
4266+
self.assertTrue(-1 <= q <= 1)
4267+
4268+
def test_random_q2(self):
4269+
rx = rtb.ETS([rtb.ET.Rx(qlim=[-1, 1]), rtb.ET.Rx(qlim=[1, 2])])
4270+
4271+
q = rx.random_q(10)
4272+
4273+
self.assertTrue(np.all(-1 <= q[:, 0]) and np.all(q[:, 0] <= 1))
4274+
self.assertTrue(np.all(1 <= q[:, 1]) and np.all(q[:, 1] <= 2))
4275+
4276+
def test_manip(self):
4277+
r = rtb.models.Panda()
4278+
ets = r.ets()
4279+
q = r.qr
4280+
4281+
m1 = ets.manipulability(q)
4282+
m2 = ets.manipulability(q, axes="trans")
4283+
m3 = ets.manipulability(q, axes="rot")
4284+
4285+
nt.assert_almost_equal(m1, 0.0837, decimal=4)
4286+
nt.assert_almost_equal(m2, 0.1438, decimal=4)
4287+
nt.assert_almost_equal(m3, 2.7455, decimal=4)
4288+
4289+
def test_yoshi(self):
4290+
puma = rtb.models.Puma560()
4291+
ets = puma.ets()
4292+
q = puma.qn # type: ignore
4293+
4294+
m1 = ets.manipulability(q, axes=[True, True, True, True, True, True])
4295+
m2 = ets.manipulability(np.c_[q, q].T)
4296+
m3 = ets.manipulability(q, axes="trans")
4297+
m4 = ets.manipulability(q, axes="rot")
4298+
4299+
a0 = 0.0805
4300+
a2 = 0.1354
4301+
a3 = 2.44949
4302+
4303+
nt.assert_almost_equal(m1, a0, decimal=4)
4304+
nt.assert_almost_equal(m2[0], a0, decimal=4) # type: ignore
4305+
nt.assert_almost_equal(m2[1], a0, decimal=4) # type: ignore
4306+
nt.assert_almost_equal(m3, a2, decimal=4)
4307+
nt.assert_almost_equal(m4, a3, decimal=4)
4308+
4309+
with self.assertRaises(ValueError):
4310+
puma.manipulability(axes="abcdef") # type: ignore
4311+
4312+
def test_cond(self):
4313+
r = rtb.models.Panda()
4314+
ets = r.ets()
4315+
4316+
m = ets.manipulability(r.qr, method="invcondition")
4317+
4318+
self.assertAlmostEqual(m, 0.11222, places=4) # type: ignore
4319+
4320+
def test_minsingular(self):
4321+
r = rtb.models.Panda()
4322+
ets = r.ets()
4323+
4324+
m = ets.manipulability(r.qr, method="minsingular")
4325+
4326+
self.assertAlmostEqual(m, 0.209013, places=4) # type: ignore
4327+
4328+
def test_manipulability_fail(self):
4329+
puma = rtb.models.Puma560()
4330+
ets = puma.ets()
4331+
4332+
with self.assertRaises(ValueError):
4333+
ets.manipulability(q=[1, 2, 3.0], method="notamethod") # type: ignore
4334+
4335+
def test_manip_fail2(self):
4336+
r = rtb.models.Panda()
4337+
ets = r.ets()
4338+
q = r.qr
4339+
4340+
with self.assertRaises(ValueError):
4341+
ets.manipulability(q, axes="abcdef") # type: ignore
4342+
42384343

42394344
if __name__ == "__main__":
42404345

0 commit comments

Comments
 (0)