Repository navigation
Expand file tree
/
Copy pathcommon.py
More file actions
72 lines (53 loc) · 1.94 KB
/
Copy pathcommon.py
File metadata and controls
72 lines (53 loc) · 1.94 KB
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
#
# Copyright (c) 2019-2021 LG Electronics, Inc.
#
# This software contains code licensed as described in LICENSE.
#
import signal
import lgsvl
import os
class TestTimeout(Exception):
pass
class TestException(Exception):
pass
class SimConnection:
def __init__(self, seconds=30, scene=lgsvl.wise.DefaultAssets.map_borregasave, error_message=None, load_scene=True):
if error_message is None:
error_message = 'test timed out after {}s.'.format(seconds)
self.seconds = seconds
self.error_message = error_message
self.scene = scene
self.load_scene = load_scene
def handle_timeout(self, signum, frame):
raise TestTimeout(self.error_message)
def __enter__(self):
signal.signal(signal.SIGALRM, self.handle_timeout)
signal.alarm(self.seconds)
self.sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181)
if self.load_scene:
if self.sim.current_scene == self.scene:
self.sim.reset()
signal.alarm(self.seconds - 20)
else:
self.sim.load(self.scene)
return self.sim
def __exit__(self, exc_type, exc_val, exc_tb):
signal.alarm(0)
# agents = self.sim.get_agents()
# for a in agents:
# self.sim.remove_agent(a)
self.sim.close()
def spawnState(sim, index=0):
state = lgsvl.AgentState()
state.transform = sim.get_spawn()[index]
return state
def cmEqual(self, a, b, msg): # Test vectors within 1cm
self.assertAlmostEqual(a.x, b.x, 2, msg)
self.assertAlmostEqual(a.y, b.y, 2, msg)
self.assertAlmostEqual(a.z, b.z, 2, msg)
def mEqual(self, a, b, msg): # Test vectors within 1cm
self.assertAlmostEqual(a.x, b.x, delta=1.5, msg=msg)
self.assertAlmostEqual(a.y, b.y, delta=1.5, msg=msg)
self.assertAlmostEqual(a.z, b.z, delta=1.5, msg=msg)
def notAlmostEqual(a,b):
return round(a-b,7) != 0