2.2.6.3 OSI trace file example
# 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()
To run the script execute the following command in the terminal:
python3 generate_osi_messages.py
This will output an osi file (sv_330_361_1000_movingobject.osi
) which can be visualized and played back by the osi-visualizer.