-
Notifications
You must be signed in to change notification settings - Fork 45
/
lidar_tour.py
95 lines (66 loc) · 2.23 KB
/
lidar_tour.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
.. module:: lidar_tour
:platform: Windows
:synopsis: Example starting in west_coast_usa with a vehicle that has a
Lidar attached and drives around the environment using the
builtin AI. Lidar data is displayed using the OpenGL-based
Lidar visualiser.
.. moduleauthor:: Marc Müller <mmueller@beamng.gmbh>
"""
import sys
from time import sleep
import numpy as np
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from beamngpy import BeamNGpy, Scenario, Vehicle, setup_logging
from beamngpy.sensors import Lidar
from beamngpy.visualiser import LidarVisualiser
SIZE = 1024
def resize(width, height):
if height == 0:
height = 1
glViewport(0, 0, width, height)
def open_window(width, height):
glutInit()
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
glutInitWindowSize(width, height)
window = glutCreateWindow(b'Lidar Tour')
resize(width, height)
return window
def main():
setup_logging()
beamng = BeamNGpy('localhost', 64256)
scenario = Scenario('west_coast_usa', 'lidar_tour',
description='Tour through the west coast gathering '
'Lidar data')
vehicle = Vehicle('ego_vehicle', model='etk800', licence='LIDAR')
lidar = Lidar()
vehicle.attach_sensor('lidar', lidar)
scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=(0, 0, 45))
scenario.make(beamng)
bng = beamng.open(launch=True)
try:
bng.load_scenario(scenario)
window = open_window(SIZE, SIZE)
lidar_vis = LidarVisualiser(Lidar.max_points)
lidar_vis.open(SIZE, SIZE)
bng.set_steps_per_second(60)
bng.set_deterministic()
bng.hide_hud()
bng.start_scenario()
bng.pause()
vehicle.ai_set_mode('span')
def update():
sensors = bng.poll_sensors(vehicle)
points = sensors['lidar']['points']
bng.step(3, wait=False)
lidar_vis.update_points(points, vehicle.state)
glutPostRedisplay()
glutReshapeFunc(resize)
glutIdleFunc(update)
glutMainLoop()
finally:
bng.close()
if __name__ == '__main__':
main()