2.2.6.3 OSI trace file example

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
# generate_osi_messages.py from osi3.osi_sensorview_pb2 import SensorView import struct NANO_INCREMENT = 10000000 MOVING_OBJECT_LENGTH = 5 MOVING_OBJECT_WIDTH = 2 MOVING_OBJECT_HEIGHT = 1 def main(): """Initialize SensorView""" f = open("sv_330_361_1000_movingobject.osi", "ab") sensorview = SensorView() sv_ground_truth = sensorview.global_ground_truth sv_ground_truth.version.version_major = 3 sv_ground_truth.version.version_minor = 5 sv_ground_truth.version.version_patch = 0 sv_ground_truth.timestamp.seconds = 0 sv_ground_truth.timestamp.nanos = 0 moving_object = sv_ground_truth.moving_object.add() moving_object.id.value = 42 # Generate 1000 OSI messages for a duration of 10 seconds for i in range(1000): # Increment the time if sv_ground_truth.timestamp.nanos > 1000000000: sv_ground_truth.timestamp.seconds += 1 sv_ground_truth.timestamp.nanos = 0 sv_ground_truth.timestamp.nanos += NANO_INCREMENT moving_object.vehicle_classification.type = 2 moving_object.base.dimension.length = MOVING_OBJECT_LENGTH moving_object.base.dimension.width = MOVING_OBJECT_WIDTH moving_object.base.dimension.height = MOVING_OBJECT_HEIGHT moving_object.base.position.x += 0.5 moving_object.base.position.y = 0.0 moving_object.base.position.z = 0.0 moving_object.base.orientation.roll = 0.0 moving_object.base.orientation.pitch = 0.0 moving_object.base.orientation.yaw = 0.0 """Serialize""" bytes_buffer = sensorview.SerializeToString() f.write(struct.pack("<L", len(bytes_buffer))) f.write(bytes_buffer) f.close() if __name__ == "__main__": main()
python

To run the script execute the following command in the terminal:

1
python3 generate_osi_messages.py
bash

This will output an osi file (sv_330_361_1000_movingobject.osi) which can be visualized and played back by the osi-visualizer.

See Google’s documentation for more tutorials on how to use protocol buffers with Python or C++.