text: # ==============================================================================
  # -- find carla module ---------------------------------------------------------
  # ==============================================================================
  
  
  import glob
  import os
  import sys
  
  try:
      sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
          sys.version_info.major,
          sys.version_info.minor,
          'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
  except IndexError:
      pass
  
  
  # ==============================================================================
  # -- imports -------------------------------------------------------------------
  # ==============================================================================
  
  
  import carla
  
  from carla import ColorConverter as cc
  
  import signal
  import argparse
  import collections
  import datetime
  import logging
  import math
  import random
  import re
  import weakref
  from Controller import Controller
  from CANNode import ColoredConsoleHandler
  from logging.handlers import TimedRotatingFileHandler
  
  try:
      import pygame
      from pygame.locals import KMOD_CTRL
      from pygame.locals import KMOD_SHIFT
      from pygame.locals import K_0
      from pygame.locals import K_9
      from pygame.locals import K_BACKQUOTE
      from pygame.locals import K_BACKSPACE
      from pygame.locals import K_COMMA
      from pygame.locals import K_DOWN
      from pygame.locals import K_ESCAPE
      from pygame.locals import K_F1
      from pygame.locals import K_LEFT
      from pygame.locals import K_PERIOD
      from pygame.locals import K_RIGHT
      from pygame.locals import K_SLASH
      from pygame.locals import K_SPACE
      from pygame.locals import K_TAB
      from pygame.locals import K_UP
      from pygame.locals import K_a
      from pygame.locals import K_b
      from pygame.locals import K_c
      from pygame.locals import K_d
      from pygame.locals import K_g
      from pygame.locals import K_h
      from pygame.locals import K_i
      from pygame.locals import K_l
      from pygame.locals import K_m
      from pygame.locals import K_n
      from pygame.locals import K_p
      from pygame.locals import K_q
      from pygame.locals import K_r
      from pygame.locals import K_s
      from pygame.locals import K_v
      from pygame.locals import K_w
      from pygame.locals import K_x
      from pygame.locals import K_z
      from pygame.locals import K_MINUS
      from pygame.locals import K_EQUALS
  except ImportError:
      raise RuntimeError('cannot import pygame, make sure pygame package is installed')
  
  try:
      import numpy as np
  except ImportError:
      raise RuntimeError('cannot import numpy, make sure numpy package is installed')
  
  
  # ==============================================================================
  # -- Global functions ----------------------------------------------------------
  # ==============================================================================
  
  
  def find_weather_presets():
      rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)')
      name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x))
      presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)]
      return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets]
  
  
  def get_actor_display_name(actor, truncate=250):
      name = ' '.join(actor.type_id.replace('_', '.').title().split('.')[1:])
      return (name[:truncate - 1] + u'\u2026') if len(name) > truncate else name
  
  
  # ==============================================================================
  # -- GnssSensor ----------------------------------------------------------------
  # ==============================================================================
  
  
  class GnssSensor(object):
      def __init__(self, parent_actor):
          self.sensor = None
          self._parent = parent_actor
          self.lat = 0.0
          self.lon = 0.0
          world = self._parent.get_world()
          bp = world.get_blueprint_library().find('sensor.other.gnss')
          self.sensor = world.spawn_actor(bp, carla.Transform(carla.Location(x=1.0, z=2.8)), attach_to=self._parent)
          # We need to pass the lambda a weak reference to self to avoid circular
          # reference.
          weak_self = weakref.ref(self)
          self.sensor.listen(lambda event: GnssSensor._on_gnss_event(weak_self, event))
  
      @staticmethod
      def _on_gnss_event(weak_self, event):
          self = weak_self()
          if not self:
              return
          self.lat = event.latitude
          self.lon = event.longitude