Skip to content

Commit a9e6a71

Browse files
authored
Readme update for generating a scenario (#485)
Signed-off-by: Viktor Kreschenski <viktor.kreschenski@altran.com>
1 parent 7097103 commit a9e6a71

File tree

1 file changed

+55
-48
lines changed

1 file changed

+55
-48
lines changed

README.md

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,74 @@ For more information on OSI see the [official documentation](https://opensimulat
1515
[1] Hanke, T., Hirsenkorn, N., van-Driesten, C., Garcia-Ramos, P., Schiementz, M., Schneider, S. & Biebl, E. (2017, February 03). *A generic interface for the environment perception of automated driving functions in virtual scenarios.* Retrieved January 25, 2020, from https://www.hot.ei.tum.de/forschung/automotive-veroeffentlichungen/
1616

1717
## Usage
18-
##### Example of writing and reading an OSI message in `Python`
18+
##### Example of generating OSI messages in `Python`
1919
```python
20+
# generate_osi_messages.py
2021
from osi3.osi_sensorview_pb2 import SensorView
21-
from osi3.osi_sensordata_pb2 import SensorData
22+
import struct
23+
24+
NANO_INCREMENT = 10000000
25+
MOVING_OBJECT_LENGTH = 5
26+
MOVING_OBJECT_WIDTH = 2
27+
MOVING_OBJECT_HEIGHT = 1
2228

2329
def main():
24-
"""Initialize SensorView and SensorData"""
30+
"""Initialize SensorView"""
31+
f = open("sv_330_361_1000_movingobject.osi", "ab")
2532
sensorview = SensorView()
26-
sensordata = SensorData()
27-
28-
"""Clear SensorData"""
29-
sensordata.Clear()
3033

31-
"""Get boundary line attributes from SensorView"""
3234
sv_ground_truth = sensorview.global_ground_truth
33-
sv_lane_boundary = sv_ground_truth.lane_boundary.add()
34-
sv_boundary_line = sv_lane_boundary.boundary_line.add()
35-
sv_boundary_line.position.x = 1699.20
36-
sv_boundary_line.position.y = 100.16
37-
sv_boundary_line.position.z = 0.0
38-
sv_boundary_line.width = 0.13
39-
sv_boundary_line.height = 0.0
40-
41-
"""Set boundary line attributes to SensorData"""
42-
sd_lane_boundary = sensordata.lane_boundary.add()
43-
sd_boundary_line = sd_lane_boundary.boundary_line.add()
44-
sd_boundary_line.position.x = sv_boundary_line.position.x
45-
sd_boundary_line.position.y = sv_boundary_line.position.y
46-
sd_boundary_line.position.z = sv_boundary_line.position.z
47-
sd_boundary_line.width = sv_boundary_line.width
48-
sd_boundary_line.height = sv_boundary_line.height
49-
50-
"""Serialize SensorData which can be send"""
51-
string_buffer = sensordata.SerializeToString()
52-
53-
"""Clear SensorData to show parsing from string"""
54-
sensordata.Clear()
55-
56-
"""The received string buffer can now be parsed"""
57-
sensordata.ParseFromString(string_buffer)
58-
59-
"""Print SensorData"""
60-
print(sensordata)
35+
sv_ground_truth.version.version_major = 3
36+
sv_ground_truth.version.version_minor = 3
37+
sv_ground_truth.version.version_patch = 0
38+
39+
sv_ground_truth.timestamp.seconds = 0
40+
sv_ground_truth.timestamp.nanos = 0
41+
42+
moving_object = sv_ground_truth.moving_object.add()
43+
moving_object.id.value = 42
44+
45+
# Generate 1000 OSI messages for a duration of 10 seconds
46+
for i in range(1000):
47+
48+
# Increment the time
49+
if sv_ground_truth.timestamp.nanos > 1000000000:
50+
sv_ground_truth.timestamp.seconds += 1
51+
sv_ground_truth.timestamp.nanos = 0
52+
sv_ground_truth.timestamp.nanos += NANO_INCREMENT
53+
54+
moving_object.vehicle_classification.type = 2
55+
56+
moving_object.base.dimension.length = MOVING_OBJECT_LENGTH
57+
moving_object.base.dimension.width = MOVING_OBJECT_WIDTH
58+
moving_object.base.dimension.height = MOVING_OBJECT_HEIGHT
59+
60+
moving_object.base.position.x += 0.5
61+
moving_object.base.position.y = 0.0
62+
moving_object.base.position.z = 0.0
63+
64+
moving_object.base.orientation.roll = 0.0
65+
moving_object.base.orientation.pitch = 0.0
66+
moving_object.base.orientation.yaw = 0.0
67+
68+
"""Serialize"""
69+
bytes_buffer = sensorview.SerializeToString()
70+
f.write(struct.pack("<L", len(bytes_buffer)))
71+
f.write(bytes_buffer)
72+
73+
f.close()
6174

6275
if __name__ == "__main__":
6376
main()
6477
```
65-
**Output**:
78+
79+
To run the script execute the following command in the terminal:
6680
```bash
67-
lane_boundary {
68-
boundary_line {
69-
position {
70-
x: 1699.2
71-
y: 100.16
72-
z: 0.0
73-
}
74-
width: 0.13
75-
height: 0.0
76-
}
77-
}
81+
python3 generate_osi_messages.py
7882
```
83+
84+
This will output an osi file (`sv_330_361_1000_movingobject.osi`) which can be visualized and played back by the [osi-visualizer](https://github.com/OpenSimulationInterface/osi-visualizer).
85+
7986
See Google's documentation for more tutorials on how to use protocol buffers with [Python](https://developers.google.com/protocol-buffers/docs/pythontutorial) or [C++](https://developers.google.com/protocol-buffers/docs/cpptutorial).
8087
## Installation
8188
##### Dependencies

0 commit comments

Comments
 (0)