carla-simulator / carla

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

Traffic light control algorithm and agent injection/deletion algorithm #8358

Open sfm-user-1 opened 2 days ago

sfm-user-1 commented 2 days ago

Thanks for the excellent work developing and sharing CARLA!

Could you all describe more about the traffic light control algorithm and agent injection/deletion algorithms you use, if any? For example, how and where are agents spawned, and when are they deleted, and why? Do you use heuristics, and could you point me to the code where they are implemented? @PabloVD @Blyron @germanros1987 could you share that with me?

Thank you in advance!

PabloVD commented 1 day ago

The traffic lights are updated cyclically. They belong to a group which contains the different traffic lights in it. Inside the group, traffic lights are differentiated by their pole index. Within a group the state of traffic lights is changed in a cyclic pattern: one index is chosen and it spends a few seconds in green, yellow and eventually red. The rest of the traffic lights remain frozen in red this whole time, meaning that there is a gap in the last seconds of the cycle where all the traffic lights are red. Independently, one can access the state of the traffic lights and set it by a different policy through the PythonAPI, see here for more information.

Spawning and deleting agents depends on the user and is done through the Python API, see here for a simple example on spawning and here for setting the autopilot mode. You can see a more detailed example of traffic generation in PythonAPI/examples/generate_traffic.py.

The behavior of the agents in autopilot mode are dictated by a specific module called Traffic Manager. You can read more information on this module here. But you can use your own policies implementing your own agents through the PythonAPI, see for instance some examples of agents here, which can be instantiated through the PythonAPI/examples/automatic_control.py.

sfm-user-1 commented 22 hours ago

Thank you for the detailed response @PabloVD!

That's very helpful. I'm most interested in the default behavior that ships out of the box for users. How long do the lights stay green, yellow, or red, and where in the code is that defined?

Why are all lights defined as red simultaneously?