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

Class HUD

PythonAPI/examples/manual_control_rss.py:411–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409
410
411class HUD(object):
412 def __init__(self, width, height):
413 self.dim = (width, height)
414 font = pygame.font.Font(pygame.font.get_default_font(), 20)
415 fonts = [x for x in pygame.font.get_fonts() if 'mono' in x]
416 default_font = 'ubuntumono'
417 mono = default_font if default_font in fonts else fonts[0]
418 mono = pygame.font.match_font(mono)
419 self._font_mono = pygame.font.Font(mono, 14)
420 self._notifications = FadingText(font, (width, 40), (0, height - 40))
421 self.help = HelpText(pygame.font.Font(mono, 24), width, height)
422 self.server_fps = 0
423 self.frame = 0
424 self.simulation_time = 0
425 self.original_vehicle_control = None
426 self.restricted_vehicle_control = None
427 self._show_info = True
428 self._info_text = []
429 self._server_clock = pygame.time.Clock()
430
431 def on_world_tick(self, timestamp):
432 self._server_clock.tick()
433 self.server_fps = self._server_clock.get_fps()
434 self.frame = timestamp.frame
435 self.simulation_time = timestamp.elapsed_seconds
436
437 def tick(self, world, clock):
438 self._notifications.tick(world, clock)
439 if not self._show_info:
440 return
441 t = world.player.get_transform()
442 v = world.player.get_velocity()
443 c = world.player.get_control()
444 heading = 'N' if abs(t.rotation.yaw) < 89.5 else ''
445 heading += 'S' if abs(t.rotation.yaw) > 90.5 else ''
446 heading += 'E' if 179.5 > t.rotation.yaw > 0.5 else ''
447 heading += 'W' if -0.5 > t.rotation.yaw > -179.5 else ''
448 colhist = world.collision_sensor.get_collision_history()
449 collision = [colhist[x + self.frame - 200] for x in range(0, 200)]
450 max_col = max(1.0, max(collision))
451 collision = [x / max_col for x in collision]
452 vehicles = world.world.get_actors().filter('vehicle.*')
453 self._info_text = [
454 'Server: % 16.0f FPS' % self.server_fps,
455 'Client: % 16.0f FPS' % clock.get_fps(),
456 '',
457 'Vehicle: % 20s' % get_actor_display_name(world.player, truncate=20),
458 'Map: % 20s' % world.map.name,
459 'Simulation time: % 12s' % datetime.timedelta(seconds=int(self.simulation_time)),
460 '',
461 'Speed: % 15.0f km/h' % (3.6 * math.sqrt(v.x**2 + v.y**2 + v.z**2)),
462 u'Heading:% 16.0f\N{DEGREE SIGN} % 2s' % (t.rotation.yaw, heading),
463 'Location:% 20s' % ('(% 5.1f, % 5.1f)' % (t.location.x, t.location.y)),
464 'GNSS:% 24s' % ('(% 2.6f, % 3.6f)' % (world.gnss_sensor.lat, world.gnss_sensor.lon)),
465 'Height: % 18.0f m' % t.location.z,
466 '']
467 if isinstance(c, carla.VehicleControl):
468 if isinstance(self.original_vehicle_control, carla.VehicleControl):

Callers 1

game_loopFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected