carla-simulator / carla

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

How to collect the sensor data from multiple cars #5506

Open RostyslavUA opened 2 years ago

RostyslavUA commented 2 years ago

I want to collect the data from the sensors located on multiple cars in CARLA 9.13. I run the simulation in the synchronous mode. The problem happens, when I try to listen to multiple sensors i.e.

def slidar_callback(sen_id):
    print(sen_id)
for sen in world.get_actors().filter('sensor.*'):
    sen.listen(lambda pcl_data: slidar_callback(sen.id))

In this case the id of only one (out of 15) sensor gets returned. As a result, the data from only one sensor is being saved. What am I doing wrong?

UVCSzb commented 1 year ago

Did you resolve the problem?

AlaaBenZekri commented 1 year ago

This may be a bit late but it would be helpful for anyone else facing a similar issue; if you are defining spawning multiple sensors and the callback in their listen methods is using parameters having the same name (even though the value may have changed between the spawning of the different sensors), only the last definition of those parameters would be taken into consideration and it would be having the same value for different sensors. This would be the same if you are trying to collect data using multiple vehicles where the vehicles (and/or their sensors) are defined in a loop.

One way to avoid this issue is to follow the way the sensors were defined in this script.