class_docstr: A TensorForce Environment for the [CARLA driving simulator](https://github.com/carla-simulator/carla).
   - This environment is "synchronized" with the server, meaning that the server waits for a client tick. For a
     detailed explanation of this, please refer to https://carla.readthedocs.io/en/latest/adv_synchrony_timestep/.
   - Subclass to customize the behaviour of states, actions, sensors, reward function, agent, training loop, etc.
  
  Requires, you to:
   - Install `pygame`, `opencv`
   - Install the CARLA simulator (version >= 0.9.8): https://carla.readthedocs.io/en/latest/start_quickstart
   - Install CARLA's Python bindings:
   --> Follow this [guide](https://carla.readthedocs.io/en/latest/build_system/#pythonapi), if you have trouble
       with that then follow the above steps.
   --> `cd your-path-to/CARLA_0.9.x/PythonAPI/carla/dist/`
   --> Extract `carla-0.9.x-py3.5-YOUR_OS-x86_64.egg` where `YOUR_OS` depends on your OS, i.e. `linux` or `windows`
   --> Create a `setup.py` file within the extracted folder and write the following:
     ```python
     from distutils.core import setup
  
     setup(name='carla',
           version='0.9.x',
           py_modules=['carla'])
     ```
   --> Install via pip: `pip install -e ~/CARLA_0.9.x/PythonAPI/carla/dist/carla-0.9.x-py3.5-YOUR_OS-x86_64`
   - Run the CARLA simulator from command line: `your-path-to/CARLA_0.9.x/./CarlaUE4.sh` or (CarlaUE4.exe)
   --> To use less resources add these flags: `-windowed -ResX=8 -ResY=8 --quality-level=Low`
  
   Hardware requirements (recommended):
   - GPU: dedicated, with at least 2/4 GB.
   - RAM: 16 GB suggested.
   - CPU: multicore, at least 4.
   - Note: on my hardware (i7 4700HQ 4C/8T, GT 750M 4GB, 16GB RAM) I achieve about 20 FPS in low quality mode.
  
   Example usage:
   - See [tensorforce/examples](https://github.com/tensorforce/tensorforce/tree/master/examples)
  
   Known Issues:
   - TensorForce's Runner is currently not compatible with this environment!
  
   Author:
   - Luca Anzalone (@luca96)
class_docstr_tok: ["A","TensorForce","Environment","for","the","[","CARLA","driving","simulator","]","(","https",":","\/\/github.com\/carla-simulator\/carla",")",".","-","This","environment","is","``","synchronized","''","with","the","server",",","meaning","that","the","server","waits","for","a","client","tick",".","For","a","detailed","explanation","of","this",",","please","refer","to","https",":","\/\/carla.readthedocs.io\/en\/latest\/adv_synchrony_timestep\/",".","-","Subclass","to","customize","the","behaviour","of","states",",","actions",",","sensors",",","reward","function",",","agent",",","training","loop",",","etc",".","Requires",",","you","to",":","-","Install","`","pygame","`",",","`","opencv","`","-","Install","the","CARLA","simulator","(","version",">","=","0.9.8",")",":","https",":","\/\/carla.readthedocs.io\/en\/latest\/start_quickstart","-","Install","CARLA","'s","Python","bindings",":","--",">","Follow","this","[","guide","]","(","https",":","\/\/carla.readthedocs.io\/en\/latest\/build_system\/","#","pythonapi",")",",","if","you","have","trouble","with","that","then","follow","the","above","steps",".","--",">","`","cd","your-path-to\/CARLA_0.9.x\/PythonAPI\/carla\/dist\/","`","--",">","Extract","`","carla-0.9.x-py3.5-YOUR_OS-x86_64.egg","`","where","`","YOUR_OS","`","depends","on","your","OS",",","i.e",".","`","linux","`","or","`","windows","`","--",">","Create","a","`","setup.py","`","file","within","the","extracted","folder","and","write","the","following",":","``","`","python","from","distutils.core","import","setup","setup","(","name='carla","'",",","version=","'","0.9.x","'",",","py_modules=","[","'carla","'","]",")","``","`","--",">","Install","via","pip",":","`","pip","install","-e","~\/CARLA_0.9.x\/PythonAPI\/carla\/dist\/carla-0.9.x-py3.5-YOUR_OS-x86_64","`","-","Run","the","CARLA","simulator","from","command","line",":","`","your-path-to\/CARLA_0.9.x\/.\/CarlaUE4.sh","`","or","(","CarlaUE4.exe",")","--",">","To","use","less","resources","add","these","flags",":","`","-windowed","-ResX=8","-ResY=8","--","quality-level=Low","`","Hardware","requirements","(","recommended",")",":","-","GPU",":","dedicated",",","with","at","least","2\/4","GB",".","-","RAM",":","16","GB","suggested",".","-","CPU",":","multicore",",","at","least","4",".","-","Note",":","on","my","hardware","(","i7","4700HQ","4C\/8T",",","GT","750M","4GB",",","16GB","RAM",")","I","achieve","about","20","FPS","in","low","quality","mode",".","Example","usage",":","-","See","[","tensorforce\/examples","]","(","https",":","\/\/github.com\/tensorforce\/tensorforce\/tree\/master\/examples",")","Known","Issues",":","-","TensorForce","'s","Runner","is","currently","not","compatible","with","this","environment","!","Author",":","-","Luca","Anzalone","(","@","luca96",")"]
docstr: :param address: CARLA simulator's id address. Required only if the simulator runs on a different machine.
  :param port: CARLA simulator's port.
  :param timeout: connection timeout.
  :param image_shape: shape of the images observations.
  :param window_size: pygame's window size. Meaningful only if `visualize=True`.
  :param vehicle_filter: use to spawn a particular vehicle (e.g. 'vehicle.tesla.model3') or class of vehicles
      (e.g. 'vehicle.audi.*')
  :param sensors: specifies which sensors should be equipped to the vehicle, better specified by subclassing
      `default_sensors()`.
  :param route_resolution: route planner resolution grain.
  :param fps: maximum framerate, it depends on your compiting power.
  :param render: if True a pygame window is shown.
  :param debug: enable to display some useful information about the vehicle.
docstr_tok: [":","param","address",":","CARLA","simulator","'s","id","address",".","Required","only","if","the","simulator","runs","on","a","different","machine",".",":","param","port",":","CARLA","simulator","'s","port",".",":","param","timeout",":","connection","timeout",".",":","param","image_shape",":","shape","of","the","images","observations",".",":","param","window_size",":","pygame","'s","window","size",".","Meaningful","only","if","`","visualize=True","`",".",":","param","vehicle_filter",":","use","to","spawn","a","particular","vehicle","(","e.g",".","'vehicle.tesla.model3","'",")","or","class","of","vehicles","(","e.g",".","'vehicle.audi",".","*","'",")",":","param","sensors",":","specifies","which","sensors","should","be","equipped","to","the","vehicle",",","better","specified","by","subclassing","`","default_sensors","(",")","`",".",":","param","route_resolution",":","route","planner","resolution","grain",".",":","param","fps",":","maximum","framerate",",","it","depends","on","your","compiting","power",".",":","param","render",":","if","True","a","pygame","window","is","shown",".",":","param","debug",":","enable","to","display","some","useful","information","about","the","vehicle","."]
code: def __init__(
      self,
      address="localhost",
      port=2000,
      timeout=2.0,
      image_shape=(150, 200, 3),
      window_size=(800, 600),
      vehicle_filter="vehicle.*",
      sensors: dict = None,
      route_resolution=2.0,
      fps=30.0,
      render=True,
      debug=False,
  ):
      """
      :param address: CARLA simulator's id address. Required only if the simulator runs on a different machine.
      :param port: CARLA simulator's port.
      :param timeout: connection timeout.
      :param image_shape: shape of the images observations.
      :param window_size: pygame's window size. Meaningful only if `visualize=True`.
      :param vehicle_filter: use to spawn a particular vehicle (e.g. 'vehicle.tesla.model3') or class of vehicles
          (e.g. 'vehicle.audi.*')
      :param sensors: specifies which sensors should be equipped to the vehicle, better specified by subclassing
          `default_sensors()`.
      :param route_resolution: route planner resolution grain.
      :param fps: maximum framerate, it depends on your compiting power.
      :param render: if True a pygame window is shown.
      :param debug: enable to display some useful information about the vehicle.
      """
      super().__init__()
      env_utils.init_pygame()
  
      self.timeout = timeout
      self.client = env_utils.get_client(address, port, self.timeout)
      self.world = self.client.get_world()  # type: carla.World
      self.map = self.world.get_map()  # type: carla.Map
      self.synchronous_context = None
  
      # set fix fps:
      self.world.apply_settings(
          carla.WorldSettings(
              no_rendering_mode=False,
              synchronous_mode=False,
              fixed_delta_seconds=1.0 / fps,
          )
      )
  
      # vehicle
      self.vehicle_filter = vehicle_filter
      self.vehicle = None  # type: carla.Vehicle
  
      # actions
      self.control = None  # type: carla.VehicleControl
      self.prev_actions = None
  
      # weather
      # TODO: add weather support
  
      # visualization and debugging stuff
      self.image_shape = image_shape
      self.image_size = (image_shape[1], image_shape[0])
      self.DEFAULT_IMAGE = np.zeros(
          shape=self.image_shape, dtype=np.float32
      )
      self.fps = fps
      self.tick_time = 1.0 / self.fps
      self.should_render = render
      self.should_debug = debug
      self.clock = pygame.time.Clock()
  
      if self.should_render:
          self.window_size = window_size
          self.font = env_utils.get_font(size=13)
          self.display = env_utils.get_display(window_size)
  
      # variables for reward computation
      self.collision_penalty = 0.0
  
      # vehicle sensors suite
      self.sensors_spec = (
          sensors
          if isinstance(sensors, dict)
          else self.default_sensors()
      )
      self.sensors = dict()
  
imports: import math
  import numpy
  from datetime import datetime
  from tensorforce.environments import Environment
label_desc: Use image node_id 1 to create a new CARLAEnvironment object from inherited base classes: Environment with example: obj = CARLAEnvironment(address, port, timeout, image_shape, window_size, vehicle_filter, sensors, route_resolution, fps, render, debug)