carla icon indicating copy to clipboard operation
carla copied to clipboard

Set traffic lights into customized map

Open SExpert12 opened this issue 1 year ago • 3 comments

I have used RoadRunner to create a customized map and imported in CARLA. I want the vehicles to obey the traditional lights in the customized map. I have followed this link to add traffic light to the customized map

https://carla.readthedocs.io/en/latest/tuto_M_custom_add_tl/

This is my Map Screenshot from 2024-08-16 04-50-12

I want to create multiple vehicles with different route and I set the time for traffic light. So I use this code.

spawn_delay = 20 counter = spawn_delay

    start_time = 0.0
    end_time = 80.0
    delta_time = 0.05


    max_vehicles = 12

while start_time <= end_time: #print("in while") world.tick(5)

        n_vehicles = len(world.get_actors().filter('*vehicle*'))
        #print("while",n_vehicles,max_vehicles)
        vehicle_bp = random.choice(blueprints)
        # Spawn vehicle only after delay
        

        if counter == spawn_delay and n_vehicles < max_vehicles:
            #print("if loop",n_vehicles,max_vehicles)
            
            # vehicle = world.try_spawn_actor(vehicle_bp, spawn_point_1)
            vehicle = world.try_spawn_actor(vehicle_bp, random.choice(spsT))
            if vehicle:
                vehicle.set_autopilot(True)
                traffic_light=vehicle.get_traffic_light()
                # print("traffic_light:",traffic_light)
                traffic_manager.random_right_lanechange_percentage(vehicle,0)
                traffic_manager.set_path(vehicle, random.choice(routelistT))

                # traffic_manager.set_path(vehicle,route_1)
                
                traffic_manager.update_vehicle_lights(vehicle, True)
                traffic_manager.random_left_lanechange_percentage(vehicle, 0)
                traffic_manager.auto_lane_change(vehicle, False)
                traffic_manager.distance_to_leading_vehicle(vehicle, 5)

                
                traffic_manager.ignore_lights_percentage(vehicle,0)
                # traffic_manager.set_path(vehicle, route_1)
                
            counter -= 1
        elif counter > 0:
            counter -= 1
        elif counter == 0:
            counter = spawn_delay   
        world.tick(10)
      
        actor_list=world.get_actors()
        print(actor_list)
        for actor in actor_list:
            if isinstance(actor,carla.TrafficLight):
                actor.set_red_time(5.0)
                actor.set_green_time(15.0)
                actor.set_yellow_time(3.0)
                
                # actor.set_red_time(2.0)
                # actor.set_green_time(0.01)
                # actor.set_yellow_time(2.0)
                

        start_time +=0.05

But it resulted in weird behavior which I don't understand (file attached). On red signal also vehicle is crossing the junction area. I checked for actor id and traffic light does exists as actor. Uploading Screencast10Vehicles.webm…

How to resolve this? Thanks

SExpert12 avatar Aug 14 '24 11:08 SExpert12

I checked again all issues. and working fine for 1 traffic lights but not working for all traffic lights at the intersection area. How to install traffic lights in intersection area and make it work for all four approach?

Anyone can help please?

Thanks

SExpert12 avatar Aug 18 '24 11:08 SExpert12

Hi, @SExpert12 Have you added in the BP_TrafficLightGroup all the BP_TrafficLights you want to control? This can be added at the editor,

image

DnDare avatar Aug 23 '24 10:08 DnDare

Yes. I did that. I want to allow both left turn and straight-going vehicles to cross the intersection simultaneously, but the left turn vehicles stays in the intersection area. That is because the only one light is green in the traffic group. So how to allow the two movements to clear the intersection simultaneously.

Thanks for help.

SExpert12 avatar Aug 28 '24 05:08 SExpert12

I think that it is not possible to have simultaneous movements from different directions/states with one traffic light controller, at this moment. I'll try to get a confirmation.

I don't think it is the approach you want, but maybe, adding a second traffic light controller at the same place, you might be able to synchronize both movements, if they both have the same number of directions/states somehow. This would be similar to this issue you already now.

DnDare avatar Sep 06 '24 18:09 DnDare

Hi, What I want is once I allowed the vehicles to enter in the intersection area from approach number 1, it can exit from any three approach except the one from which enters which is in this case approach number 1. Are you suggesting me to add two traffic light group if I need the vehicles to exit from any two approaches and three traffic light group if vehicles exit from any three approaches?

I hope I am able to explain clearly what I want.

Thanks.

SExpert12 avatar Sep 09 '24 07:09 SExpert12

Hi, yes I think you explained clearly,

And yes that's what I'd try, to duplicate the traffic light group, as many times you want to synchronize different directions/approaches.

I'm not sure if it will desynchronize in long simulations.

And we are not sure if there are alternatives, we should review the trafficLights Blueprints in depth. Maybe we will at some point in the future,

DnDare avatar Sep 13 '24 09:09 DnDare

Okay. Thanks

SExpert12 avatar Sep 17 '24 10:09 SExpert12