Skip to content

Commit af72665

Browse files
committed
Add HostVehicleData support to OSITrace
Closes #817. Signed-off-by: Pierre R. Mai <[email protected]>
1 parent f9f0bf0 commit af72665

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

doc/architecture/architecture_overview.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ OSI contains an object-based environment description that uses the message forma
88
Google developed and maintains the Protocol Buffer library.
99
OSI defines top-level messages that are used to exchange data between separate models.
1010
Top-level messages define the `GroundTruth` interface, the `SensorData` interface, and – since OSI version 3.0.0 – the interfaces `SensorView` and `SensorViewConfiguration`.
11-
Further top-level messages that were added in later versions of OSI are `TrafficCommand`, `TrafficCommandUpdate`, `TrafficUpdate`, `MotionRequest`, and `StreamingUpdate`.
11+
Further top-level messages that were added in later versions of OSI are `HostVehicleData`, `TrafficCommand`, `TrafficCommandUpdate`, `TrafficUpdate`, `MotionRequest`, and `StreamingUpdate`.
1212

1313
The following figure shows the interfaces and models involved in modeling a sensor.
1414

osi3trace/osi_trace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from osi3.osi_sensorview_pb2 import SensorView
99
from osi3.osi_groundtruth_pb2 import GroundTruth
10+
from osi3.osi_hostvehicledata_pb2 import HostVehicleData
1011
from osi3.osi_sensordata_pb2 import SensorData
1112
from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration
1213
from osi3.osi_trafficupdate_pb2 import TrafficUpdate
@@ -19,6 +20,7 @@
1920
MESSAGES_TYPE = {
2021
"SensorView": SensorView,
2122
"GroundTruth": GroundTruth,
23+
"HostVehicleData": HostVehicleData,
2224
"SensorData": SensorData,
2325
"SensorViewConfiguration": SensorViewConfiguration,
2426
"TrafficUpdate": TrafficUpdate,

tests/test_osi_trace.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from osi3trace.osi_trace import OSITrace
66
from osi3.osi_sensorview_pb2 import SensorView
77
from osi3.osi_groundtruth_pb2 import GroundTruth
8+
from osi3.osi_hostvehicledata_pb2 import HostVehicleData
89
from osi3.osi_sensordata_pb2 import SensorData
910
from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration
1011
from osi3.osi_trafficupdate_pb2 import TrafficUpdate
@@ -51,6 +52,23 @@ def test_osi_trace_gt(self):
5152

5253
self.assertTrue(os.path.exists(path_output))
5354

55+
def test_osi_trace_hvd(self):
56+
with tempfile.TemporaryDirectory() as tmpdirname:
57+
path_output = os.path.join(tmpdirname, "output_hvd.txth")
58+
path_input = os.path.join(tmpdirname, "input_hvd.osi")
59+
create_sample_hvd(path_input)
60+
61+
trace = OSITrace(path_input, "HostVehicleData")
62+
with open(path_output, "wt") as f:
63+
for message in trace:
64+
self.assertIsInstance(message, HostVehicleData)
65+
f.write(str(message))
66+
67+
self.assertEqual(len(trace.retrieve_offsets()), 10)
68+
trace.close()
69+
70+
self.assertTrue(os.path.exists(path_output))
71+
5472
def test_osi_trace_sd(self):
5573
with tempfile.TemporaryDirectory() as tmpdirname:
5674
path_output = os.path.join(tmpdirname, "output_sd.txth")
@@ -280,6 +298,44 @@ def create_sample_gt(path):
280298
f.close()
281299

282300

301+
def create_sample_hvd(path):
302+
f = open(path, "ab")
303+
hostvehicledata = HostVehicleData()
304+
305+
hostvehicledata.version.version_major = 3
306+
hostvehicledata.version.version_minor = 0
307+
hostvehicledata.version.version_patch = 0
308+
309+
hostvehicledata.timestamp.seconds = 0
310+
hostvehicledata.timestamp.nanos = 0
311+
312+
hostvehicledata.host_vehicle_id.value = 114
313+
314+
# Generate 10 OSI messages for 9 seconds
315+
for i in range(10):
316+
# Increment the time
317+
hostvehicledata.timestamp.seconds += 1
318+
hostvehicledata.timestamp.nanos += 100000
319+
320+
hostvehicledata.location.dimension.length = 5
321+
hostvehicledata.location.dimension.width = 2
322+
hostvehicledata.location.dimension.height = 1
323+
324+
hostvehicledata.location.position.x = 0.0 + i
325+
hostvehicledata.location.position.y = 0.0
326+
hostvehicledata.location.position.z = 0.0
327+
328+
hostvehicledata.location.orientation.roll = 0.0
329+
hostvehicledata.location.orientation.pitch = 0.0
330+
hostvehicledata.location.orientation.yaw = 0.0
331+
332+
"""Serialize"""
333+
bytes_buffer = hostvehicledata.SerializeToString()
334+
f.write(struct.pack("<L", len(bytes_buffer)) + bytes_buffer)
335+
336+
f.close()
337+
338+
283339
def create_sample_sd(path):
284340
f = open(path, "ab")
285341
sensordata = SensorData()

0 commit comments

Comments
 (0)