Beispiel #1
0
def get_world(host: str = "localhost", port: int = 2000, timeout: int = 10):
    """Get a handle to the world running inside the simulation.

    Args:
        host (:obj:`str`): The host where the simulator is running.
        port (:obj:`int`): The port to connect to at the given host.
        timeout (:obj:`int`): The timeout of the connection (in seconds).

    Returns:
        A tuple of `(client, world)` where the `client` is a connection to the
        simulator and `world` is a handle to the world running inside the
        simulation at the host:port.
    """
    try:
        from carla import Client
        client = Client(host, port)
        client_version = client.get_client_version()
        server_version = client.get_server_version()
        err_msg = 'Simulator client {} does not match server {}'.format(
            client_version, server_version)
        assert client_version == server_version, err_msg
        client.set_timeout(timeout)
        world = client.get_world()
    except RuntimeError as r:
        raise Exception("Received an error while connecting to the "
                        "simulator: {}".format(r))
    except ImportError:
        raise Exception('Error importing CARLA.')
    return (client, world)
Beispiel #2
0
from carla import Client, Transform, Rotation, Location, Waypoint
from carla import LaneMarking

import carla

import random
import time
import math
import sys

# starting proper work now

print('attempting to connect...')  # DEBUG
client = Client('localhost', 2000, worker_threads=12)
client.set_timeout(10.0)

client.load_world('/Game/Carla/Maps/single_left_bend')
print('connected!')  # DEBUG

world = client.get_world()
# ##################################################
# Change weather for data collection
# ClearNoon, ClearSunset, WetSunset, WetNoon
world.set_weather(carla.WeatherParameters.WetSunset)

# ##################################################
# bp of all actors
blueprint_lib = world.get_blueprint_library()

vehicle_bp = blueprint_lib.find('vehicle.audi.tt')
lane_invasion_sensor_bp = blueprint_lib.find('sensor.other.lane_invasion')