예제 #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()
way_points = [((-277.08,-15.39),20),
              ((-30.08,-15.39),10),
              ((-12.0,-12.0),10),
              (( -9, 0.0),20),
              (( -9, 50),0)
              ]
'''

start = (-277.08, -15.39)
end = (-9, 50)
constant_speed = 20

try:

    throttles, speed, reference_speed = pure_pursuit_control_wrapper(
        env, start, end, model_uniquename, constant_speed)

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

    #plt.subplot(3,1,1)
    a[0].plot(reference_speed)
    a[0].set_title('reference speed')
    #plt.subplot(3,1,2)
    a[1].plot(throttles)
    a[1].set_title('throttle applied')
    a[2].plot(speed)
    a[2].set_title('measured speed')

finally:
    env.destroy_actors()