MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / HUD

Class HUD

PythonAPI/examples/manual_control_steeringwheel.py:382–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380
381
382class HUD(object):
383 def __init__(self, width, height):
384 self.dim = (width, height)
385 font = pygame.font.Font(pygame.font.get_default_font(), 20)
386 font_name = 'courier' if os.name == 'nt' else 'mono'
387 fonts = [x for x in pygame.font.get_fonts() if font_name in x]
388 default_font = 'ubuntumono'
389 mono = default_font if default_font in fonts else fonts[0]
390 mono = pygame.font.match_font(mono)
391 self._font_mono = pygame.font.Font(mono, 12 if os.name == 'nt' else 14)
392 self._notifications = FadingText(font, (width, 40), (0, height - 40))
393 self.help = HelpText(pygame.font.Font(mono, 24), width, height)
394 self.server_fps = 0
395 self.frame = 0
396 self.simulation_time = 0
397 self._show_info = True
398 self._info_text = []
399 self._server_clock = pygame.time.Clock()
400
401 def on_world_tick(self, timestamp):
402 self._server_clock.tick()
403 self.server_fps = self._server_clock.get_fps()
404 self.frame = timestamp.frame
405 self.simulation_time = timestamp.elapsed_seconds
406
407 def tick(self, world, clock):
408 self._notifications.tick(world, clock)
409 if not self._show_info:
410 return
411 t = world.player.get_transform()
412 v = world.player.get_velocity()
413 c = world.player.get_control()
414 heading = 'N' if abs(t.rotation.yaw) < 89.5 else ''
415 heading += 'S' if abs(t.rotation.yaw) > 90.5 else ''
416 heading += 'E' if 179.5 > t.rotation.yaw > 0.5 else ''
417 heading += 'W' if -0.5 > t.rotation.yaw > -179.5 else ''
418 colhist = world.collision_sensor.get_collision_history()
419 collision = [colhist[x + self.frame - 200] for x in range(0, 200)]
420 max_col = max(1.0, max(collision))
421 collision = [x / max_col for x in collision]
422 vehicles = world.world.get_actors().filter('vehicle.*')
423 self._info_text = [
424 'Server: % 16.0f FPS' % self.server_fps,
425 'Client: % 16.0f FPS' % clock.get_fps(),
426 '',
427 'Vehicle: % 20s' % get_actor_display_name(world.player, truncate=20),
428 'Map: % 20s' % world.world.map_name,
429 'Simulation time: % 12s' % datetime.timedelta(seconds=int(self.simulation_time)),
430 '',
431 'Speed: % 15.0f km/h' % (3.6 * math.sqrt(v.x**2 + v.y**2 + v.z**2)),
432 u'Heading:% 16.0f\N{DEGREE SIGN} % 2s' % (t.rotation.yaw, heading),
433 'Location:% 20s' % ('(% 5.1f, % 5.1f)' % (t.location.x, t.location.y)),
434 'GNSS:% 24s' % ('(% 2.6f, % 3.6f)' % (world.gnss_sensor.lat, world.gnss_sensor.lon)),
435 'Height: % 18.0f m' % t.location.z,
436 '']
437 if isinstance(c, carla.VehicleControl):
438 self._info_text += [
439 ('Throttle:', c.throttle, 0.0, 1.0),

Callers 1

game_loopFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected