Skip to content

Commit 06e3657

Browse files
serge-mHabedank Clemens
authored andcommitted
Bugfix osi trace (#438)
* add test for OSITrace Signed-off-by: SergeM <sbmatyunin@gmail.com> * bugfix in OSITrace probably a typo Signed-off-by: SergeM <sbmatyunin@gmail.com> * Fixed relative import in the test Signed-off-by: SergeM <sbmatyunin@gmail.com> * input data for the test is generated on fly Signed-off-by: SergeM <sbmatyunin@gmail.com> * install the module on travis in order to get the dependencies Signed-off-by: SergeM <sbmatyunin@gmail.com> * Install the module on travis for deploy stage in order to get the dependencies; add python3-wheel to remove warnings Signed-off-by: SergeM <sbmatyunin@gmail.com> Signed-off-by: Habedank Clemens <qxs2704@europe.bmw.corp>
1 parent 6390bba commit 06e3657

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ addons:
6161
- doxygen-gui
6262
- graphviz
6363
- python3-setuptools
64+
- python3-pip
65+
- python3-wheel
6466

6567

6668
jobs:
@@ -78,6 +80,8 @@ jobs:
7880
- cd ..
7981
- python3 setup.py build
8082
- python3 setup.py sdist
83+
- python3 -m pip install -U pip
84+
- python3 -m pip install .
8185
- cd build
8286
- cmake --build . --target install
8387
- cd ..
@@ -103,6 +107,8 @@ jobs:
103107
- cd ..
104108
- python3 setup.py build
105109
- python3 setup.py sdist
110+
- python3 -m pip install -U pip
111+
- python3 -m pip install .
106112
- cd build
107113
- cmake --build . --target install
108114
- cd ..
@@ -128,6 +134,8 @@ jobs:
128134
- cd ..
129135
- python3 setup.py build
130136
- python3 setup.py sdist
137+
- python3 -m pip install -U pip
138+
- python3 -m pip install .
131139
- cd build
132140
- cmake --build . --target install
133141
- cd ..

format/OSITrace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def make_readable(self, name, interval=None, index=None):
236236

237237
if interval is None and index is not None:
238238
if type(index) == int:
239-
f.write(str(scenario.get_message_by_index(0)))
239+
f.write(str(self.get_message_by_index(0)))
240240
else:
241241
raise Exception("Argument 'index' needs to be of type 'int'")
242242

tests/test_osi_trace.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import tempfile
3+
import unittest
4+
5+
from format.OSITrace import OSITrace
6+
from osi3.osi_sensorview_pb2 import SensorView
7+
import struct
8+
9+
10+
class TestOSITrace(unittest.TestCase):
11+
def test_osi_trace(self):
12+
with tempfile.TemporaryDirectory() as tmpdirname:
13+
path_output = os.path.join(tmpdirname, "output.txth")
14+
path_input = os.path.join(tmpdirname, "input.osi")
15+
create_sample(path_input)
16+
17+
trace = OSITrace()
18+
trace.from_file(path=path_input)
19+
trace.make_readable(path_output, index=1)
20+
trace.scenario_file.close()
21+
22+
self.assertTrue(os.path.exists(path_output))
23+
24+
25+
def create_sample(path):
26+
f = open(path, "ab")
27+
sensorview = SensorView()
28+
29+
sv_ground_truth = sensorview.global_ground_truth
30+
sv_ground_truth.version.version_major = 3
31+
sv_ground_truth.version.version_minor = 0
32+
sv_ground_truth.version.version_patch = 0
33+
34+
sv_ground_truth.timestamp.seconds = 0
35+
sv_ground_truth.timestamp.nanos = 0
36+
37+
moving_object = sv_ground_truth.moving_object.add()
38+
moving_object.id.value = 114
39+
40+
# Generate 10 OSI messages for 9 seconds
41+
for i in range(10):
42+
# Increment the time
43+
sv_ground_truth.timestamp.seconds += 1
44+
sv_ground_truth.timestamp.nanos += 100000
45+
46+
moving_object.vehicle_classification.type = 2
47+
48+
moving_object.base.dimension.length = 5
49+
moving_object.base.dimension.width = 2
50+
moving_object.base.dimension.height = 1
51+
52+
moving_object.base.position.x = 0.0 + i
53+
moving_object.base.position.y = 0.0
54+
moving_object.base.position.z = 0.0
55+
56+
moving_object.base.orientation.roll = 0.0
57+
moving_object.base.orientation.pitch = 0.0
58+
moving_object.base.orientation.yaw = 0.0
59+
60+
"""Serialize"""
61+
bytes_buffer = sensorview.SerializeToString()
62+
f.write(struct.pack("<L", len(bytes_buffer)) + bytes_buffer)
63+
64+
f.close()

0 commit comments

Comments
 (0)