forked from stepjam/PyRep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mobiles_and_configuration_paths.py
96 lines (81 loc) · 3.12 KB
/
test_mobiles_and_configuration_paths.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import unittest
from tests.core import TestCore
from pyrep import PyRep
from pyrep.objects.dummy import Dummy
import numpy as np
from os import path
from pyrep.robots.mobiles.youbot import YouBot
from pyrep.robots.mobiles.turtlebot import TurtleBot
from pyrep.robots.mobiles.line_tracer import LineTracer
ASSET_DIR = path.join(path.dirname(path.abspath(__file__)), 'assets')
# TODO: Extract out youbot to 'test_mobiles_with_arms.py'
MOBILES = [
('YouBot', YouBot),
('LineTracer', LineTracer),
('turtlebot', TurtleBot),
]
class TestMobilesAndConfigurationPaths(TestCore):
def setUp(self):
self.pyrep = PyRep()
self.pyrep.launch(path.join(
ASSET_DIR, 'test_scene_mobiles.ttt'), headless=True)
self.pyrep.step()
self.pyrep.start()
# It is enough to only test the constructor of each mobile (in there we make
# assumptions about the structure of the mobile model). All other tests
# can be run on one mobile.
def test_get_mobile(self):
for mobile_name, mobile_type in MOBILES:
with self.subTest(mobile=mobile_name):
mobile = mobile_type()
self.assertIsInstance(mobile, mobile_type)
def test_get_linear_path(self):
mobile = YouBot()
waypoint = Dummy('youBot_waypoint')
path = mobile.get_linear_path(
waypoint.get_position(), waypoint.get_orientation()[-1])
self.assertIsNotNone(path)
def test_get_nonlinear_path(self):
mobile = YouBot()
waypoint = Dummy('youBot_waypoint')
path = mobile.get_nonlinear_path(
waypoint.get_position(), waypoint.get_orientation()[-1])
self.assertIsNotNone(path)
def test_get_linear_path_and_step(self):
mobile = YouBot()
waypoint = Dummy('youBot_waypoint')
path = mobile.get_linear_path(
waypoint.get_position(), waypoint.get_orientation()[-1])
self.assertIsNotNone(path)
done = False
while not done:
done = path.step()
self.pyrep.step()
self.assertTrue(np.allclose(
mobile.get_position()[:2], waypoint.get_position()[:2],
atol=0.001))
def test_get_linear_path_and_get_end(self):
mobile = YouBot()
waypoint = Dummy('youBot_waypoint')
path = mobile.get_linear_path(
waypoint.get_position(), waypoint.get_orientation()[-1])
path.set_to_end()
self.assertTrue(np.allclose(
mobile.get_position()[:2], waypoint.get_position()[:2],
atol=0.001))
def test_get_linear_path_visualize(self):
mobile = YouBot()
waypoint = Dummy('youBot_waypoint')
path = mobile.get_linear_path(
waypoint.get_position(), waypoint.get_orientation()[-1])
# Check that it does not error
path.visualize()
def test_get_duplicate_mobile(self):
mobile = YouBot(1)
self.assertIsInstance(mobile, YouBot)
def test_copy_mobile(self):
mobile = LineTracer()
new_mobile = mobile.copy()
self.assertNotEqual(mobile, new_mobile)
if __name__ == '__main__':
unittest.main()