Exemple #1
0
def main():
    try:
        client = carla.Client("localhost", 2000)
        client.set_timeout(10.0)
        world = client.load_world('Town05')

        # set the weather
        weather = carla.WeatherParameters(cloudiness=10.0,
                                          precipitation=0.0,
                                          sun_altitude_angle=90.0)
        world.set_weather(weather)

        # set the spectator position for demo purpose
        spectator = world.get_spectator()
        spectator.set_transform(
            carla.Transform(
                carla.Location(x=26.6, y=1.29, z=75.0),
                carla.Rotation(pitch=-88.0, yaw=-1.85,
                               roll=1.595)))  # top view of intersection

        env = CARLA_ENV(world)
        time.sleep(2)  # sleep for 2 seconds, wait the initialization to finish

        traffic_light_list = get_traffic_lights(world.get_actors())

        intersection_list = []

        # intersection 1
        world_pos = (25.4, 0.0)

        intersection1 = Intersection(env, world_pos, traffic_light_list)
        intersection1.add_vehicle(run=True)

        intersection1.add_vehicle(command="left", run=True)
        intersection1.add_vehicle(command="right", run=True)

        intersection1.add_vehicle(gap=5, choice="left")
        intersection1.add_vehicle(gap=5, choice="left", command="right")
        intersection1.add_vehicle(gap=5, choice="left", command="left")
        intersection1.add_vehicle(choice="right")
        intersection1.add_vehicle(choice="right", command="left")
        intersection1.add_vehicle(gap=15.0, choice="right", command="right")
        intersection1.add_vehicle(choice="ahead", run=True)
        intersection1.add_vehicle(choice="ahead", command="right", run=True)
        intersection1.add_vehicle(choice="ahead", command="left", run=True)

        intersection1.start_simulation()

        intersection_list.append(intersection1)

        multiple_vehicle_control(env, intersection_list)

    finally:
        time.sleep(10)
        env.destroy_actors()
def main():
    try:
        client = carla.Client("localhost",2000)
        client.set_timeout(10.0)
        world = client.load_world('Town05')
         
        # set the weather
        weather = carla.WeatherParameters(
            cloudiness=10.0,
            precipitation=0.0,
            sun_altitude_angle=90.0)
        world.set_weather(weather)
        
        # set the spectator position for demo purpose
        spectator = world.get_spectator()
        spectator.set_transform(carla.Transform(carla.Location(x=-190, y=1.29, z=75.0), carla.Rotation(pitch=-88.0, yaw= -1.85, roll=1.595))) # top view of intersection
        
        env = CARLA_ENV(world) 
        time.sleep(2) # sleep for 2 seconds, wait the initialization to finish
        
        traffic_light_list = get_traffic_lights(world.get_actors())
        
        intersection_list = create_intersections(env, 4, traffic_light_list)
        init_intersection = intersection_list[0]
        normal_intersections = intersection_list[1:]
        init_intersection.add_ego_vehicle(safety_distance = 15.0 )
        init_intersection.add_follow_vehicle(follow_distance = 20.0)
        init_intersection.add_lead_vehicle(lead_distance = 20.0)
        init_intersection.add_vehicle(choice = "left")
        init_intersection.add_vehicle(choice = "right",command="left")
        init_intersection.add_vehicle(choice = "ahead",command="left")
        init_intersection.add_vehicle(choice = "ahead",command = "right")
        
        intersection_list[1].add_vehicle(choice = "ahead")
        intersection_list[1].add_vehicle(choice = "left",command="left")
        intersection_list[1].add_vehicle(choice = "right",command = "left")
        intersection_list[1].add_vehicle(choice = "right",command = "right")
        intersection_list[1]._shift_vehicles(-10, choice = "right",index = 0)
        
        intersection_list[2].add_vehicle(choice = "ahead")
        intersection_list[2].add_vehicle(choice = "left",command="left")
        intersection_list[2].add_vehicle(choice = "right",command = "left")
        intersection_list[2].add_vehicle(choice = "right",command = "right")
        
        intersection_list[3].add_vehicle(command = "left")
        intersection_list[3].add_vehicle()
        
        
        IntersectionBackend(env,intersection_list)
    finally:
        time.sleep(10)
        env.destroy_actors()
def main():
    try:
        client = carla.Client("localhost", 2000)
        client.set_timeout(10.0)
        world = client.load_world('Town06')

        # set the weather
        world = client.get_world()
        weather = carla.WeatherParameters(cloudiness=10.0,
                                          precipitation=0.0,
                                          sun_altitude_angle=90.0)
        world.set_weather(weather)

        # set the spectator position for demo purpose
        spectator = world.get_spectator()
        spectator.set_transform(
            carla.Transform(
                carla.Location(x=-68.29, y=151.75, z=170.8),
                carla.Rotation(pitch=-31.07, yaw=-90.868,
                               roll=1.595)))  # plain ground

        env = CARLA_ENV(world)
        time.sleep(2)

        # get map
        carla_map = env.world.get_map()

        start_raw = carla.Location(x=-277.08, y=-15.39, z=4.94)
        destination_raw = carla.Location(x=-9.0, y=-50.0, z=0.0)
        start = carla_map.get_waypoint(start_raw)
        destination = carla_map.get_waypoint(destination_raw)

        trajectory = generate_path(env,
                                   start,
                                   destination,
                                   waypoint_separation=50)

    finally:
        return trajectory
# set the weather
world = client.get_world()
weather = carla.WeatherParameters(cloudiness=10.0,
                                  precipitation=0.0,
                                  sun_altitude_angle=90.0)
world.set_weather(weather)

# set the spectator position for demo purpose
spectator = world.get_spectator()
spectator.set_transform(
    carla.Transform(carla.Location(x=-68.29, y=151.75, z=170.8),
                    carla.Rotation(pitch=-31.07, yaw=-90.868,
                                   roll=1.595)))  # plain ground

env = CARLA_ENV(world)
time.sleep(2)  # sleep for 2 seconds, wait the initialization to finish

# spawn a vehicle, here I choose a Tesla model
spawn_point = carla.Transform(
    carla.Location(x=-277.08, y=-15.39, z=4.94),
    carla.Rotation(pitch=0.000000, yaw=0, roll=0.000000))
model_name = "vehicle.tesla.model3"
model_uniquename = env.spawn_vehicle(
    model_name, spawn_point
)  # spawn the model and get the uniquename, the CARLA_ENV class will store the vehicle into vehicle actor list

time.sleep(5)
'''
way_points = [((-277.08,-15.39),20),
              ((-30.08,-15.39),10),
def main():
    try:
        client = carla.Client("localhost", 2000)
        client.set_timeout(10.0)
        world = client.load_world('Town05')

        # set the weather
        world = client.get_world()
        weather = carla.WeatherParameters(cloudiness=10.0,
                                          precipitation=0.0,
                                          sun_altitude_angle=90.0)
        world.set_weather(weather)

        # set the spectator position for demo purpose
        spectator = world.get_spectator()
        spectator.set_transform(
            carla.Transform(
                carla.Location(x=0.0, y=0.0, z=20.0),
                carla.Rotation(pitch=-31.07, yaw=-90.868,
                               roll=1.595)))  # plain ground

        env = CARLA_ENV(world)
        time.sleep(2)

        # get map
        carla_map = env.world.get_map()

        start_raw = carla.Location(x=-0.19, y=6.65, z=0.0)
        destination_raw = carla.Location(x=24.18125, y=35.5, z=0.0)

        world.debug.draw_point(start_raw,
                               size=0.15,
                               color=red,
                               life_time=0.0,
                               persistent_lines=True)
        world.debug.draw_point(destination_raw,
                               size=0.15,
                               color=red,
                               life_time=0.0,
                               persistent_lines=True)

        start = carla_map.get_waypoint(start_raw)
        destination = carla_map.get_waypoint(destination_raw)

        world.debug.draw_point(start.transform.location,
                               size=0.15,
                               color=blue,
                               life_time=0.0,
                               persistent_lines=True)
        world.debug.draw_point(destination.transform.location,
                               size=0.15,
                               color=blue,
                               life_time=0.0,
                               persistent_lines=True)

        trajectory = generate_path(env,
                                   start,
                                   destination,
                                   waypoint_separation=10)

    finally:
        return trajectory
time.sleep(5)
#world = client.get_world()
spectator = world.get_spectator()
spectator.set_transform(
    carla.Transform(carla.Location(x=-68.29, y=151.75, z=170.8),
                    carla.Rotation(pitch=-31.07, yaw=-90.868,
                                   roll=1.595)))  # plain ground
#spectator.set_transform(carla.Transform(carla.Location(x=79.95, y=-13.13, z=84.69), carla.Rotation(pitch=-47.2, yaw= -90.86, roll=0.000000))) #slope
'''
weather = carla.WeatherParameters(
    cloudiness=10.0,
    precipitation=0.0,
    sun_altitude_angle=90.0)
world.set_weather(weather)
'''
env = CARLA_ENV(world)
time.sleep(2)
try:
    '''
    throttle_signal , forward_speed = get_frequency_response_data(env,10,10)
    plt.subplot(2,1,1)
    plt.plot(throttle_signal)
    plt.subplot(2,1,2)
    plt.plot(forward_speed)
    '''
    throttles, speed, reference_speed = speed_control_wrapper(env, 20)

    fig, a = plt.subplots(3, 1)

    #plt.subplot(3,1,1)
    a[0].plot(reference_speed)