carla-simulator / carla

Open-source simulator for autonomous driving research.
http://carla.org
MIT License
11.18k stars 3.61k forks source link

Replicate SUMO light sequence in CARLA Editor #7807

Open DanielSioldea opened 3 months ago

DanielSioldea commented 3 months ago

I am trying to find a way to link the traffic lights between SUMO and CARLA, so that the CARLA lights follow the sequence and colours in the SUMO simulation. I created a map in Roadrunner and imported it into CARLA, and I am able to run co-simulations just fine, with the vehicles following the light logic from SUMO using the --tls-manager argument. However I am just not sure how to replicate the lights in the actual CARLA editor environment so that when there is a red light in SUMO, the corresponding light in CARLA is also red, and so on and so forth. Any advice would be appreciated as I do not have any prior knowledge of Unreal Engine or CARLA. I have added some pictures of my setup so far, but if more are needed for clarity please let me know.

CARLA Unreal setup: Manually placed traffic lights, grouped together in a junction (BP_TrafficLightGroup) Screenshot 2024-06-18 154928

SUMO Setup: .net.xml file was generated using the netconvert script provided by CARLA. TLS logic was edited manually to suit my needs. .rou.xml files were created manually through Netedit's demand planner. Screenshot 2024-06-18 155402

GoodarzMehr commented 3 months ago

You can use the carla.TrafficLight class' methods (set_state in particular) to synchronize the visual appearance of each traffic light with its state in SUMO.

DanielSioldea commented 3 months ago

You can use the carla.TrafficLight class' methods (set_state in particular) to synchronize the visual appearance of each traffic light with its state in SUMO.

I'm sorry for the question, I am still learning where everything is with CARLA, but would I just include this as an argument when calling "run_syncronization.py", or is there another way to go about doing this?

GoodarzMehr commented 3 months ago

I think you have to implement this yourself, i.e. write some code that gets the state of each traffic light from SUMO and then sets the state of the corresponding traffic light in CARLA. There may be a simpler way of doing this (e.g. by passing an argument) but I'm not aware if it.

Blyron commented 3 months ago

You will need to implement youself as @GoodarzMehr suggested. If you are fine with this answer, please feel free to close the issue

DanielSioldea commented 3 months ago

You will need to implement youself as @GoodarzMehr suggested. If you are fine with this answer, please feel free to close the issue

I am able to get SUMO states through the TraCI API. I have an idea of how to link the SUMO states to the CARLA states using the code snippet from the carla.TrafficLight.set_state. However I am still a bit lost on how to link that to the lights placed in Unreal Engine. Any further information, examples, or references would be much appreciated. Thank you again.

GoodarzMehr commented 3 months ago

The carla.World object has several methods for getting traffic lights during a simulation, and if I understand your problem correctly the get_traffic_lights_in_junction() method in particular (and maybe get_traffic_light_from_opendrive_id()) can be useful in your case.