Exemple #1
0
def create_intersections(env, number_of_intersections, traffic_light_list,
                         navigation_speed):
    '''
    

    Parameters
    ----------
    env : CARLA_ENV
        sself-written simulation help class.
    number_of_intersections : int
        number of intersection.
    navigation_speed : float
        the navigation speed of the vehicle

    Returns
    -------
    Intersections : list of intersections, [Init_Intersection,Intersection,Intersection,...,Intersection]

    '''

    # note: due to the limit of map, number_of_intersections can be at most 4 at present
    world_pos_list = [(-190.0, 0.0), (-133.0, 0.0), (-55.0, 0.0), (25.4, 0.0)]
    number_of_intersections = min(4, number_of_intersections)
    waypoint_list = []  # way points that form the full path
    subject_traffic_light_list = [
    ]  # all subject traffic lights along the full path
    intersection_list = []

    for ii in range(1, number_of_intersections):
        normal_intersection = Intersection(env,
                                           world_pos_list[ii],
                                           traffic_light_list,
                                           navigation_speed=navigation_speed)
        waypoint_list += normal_intersection.get_subject_waypoints(
        )  # get the three points representing the path
        subject_traffic_light_list.append(
            normal_intersection.get_subject_traffic_light())
        intersection_list.append(normal_intersection)

    init_intersection = Init_Intersection(env,
                                          world_pos_list[0],
                                          traffic_light_list,
                                          waypoint_list,
                                          subject_traffic_light_list,
                                          navigation_speed=navigation_speed)
    intersection_list.insert(0, init_intersection)
    return intersection_list
Exemple #2
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=-133, 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 = (-133.0, 0.0)  #(25.4,0.0)

        intersection1 = Intersection(env, world_pos, traffic_light_list)
        intersection1.add_vehicle(obey_traffic_lights=False)

        intersection1.add_vehicle(command="left", obey_traffic_lights=False)
        intersection1.add_vehicle(command="right", obey_traffic_lights=False)

        intersection1.add_vehicle(gap=5,
                                  choice="left",
                                  obey_traffic_lights=False)
        intersection1.add_vehicle(gap=5,
                                  choice="left",
                                  command="right",
                                  obey_traffic_lights=False)
        intersection1.add_vehicle(gap=5,
                                  choice="left",
                                  command="left",
                                  obey_traffic_lights=False)
        intersection1.add_vehicle(choice="right", obey_traffic_lights=False)
        intersection1.add_vehicle(choice="right",
                                  command="left",
                                  obey_traffic_lights=False)
        intersection1.add_vehicle(gap=10.0,
                                  choice="right",
                                  command="right",
                                  obey_traffic_lights=False)
        intersection1.add_vehicle(choice="ahead", obey_traffic_lights=False)
        intersection1.add_vehicle(choice="ahead",
                                  command="right",
                                  obey_traffic_lights=False)
        intersection1.add_vehicle(choice="ahead",
                                  command="left",
                                  obey_traffic_lights=False)

        intersection1._shift_vehicles(-10, index=1)

        intersection1.start_sim = True

        intersection_list.append(intersection1)

        multiple_vehicle_control(env, intersection_list)

    finally:
        time.sleep(10)
        env.destroy_actors()