Basic tutorial how extract GNSS and IMU data

Hi, could you provide with a small tutorial or commented code about extracting GNSS and IMU data from a vehicle?

Hi @rparada! Have you looked at the example program manual_control.py? When you install Carla, you will find it under Carla/PythonAPI/examples

Hi @thomasfermi, the script you mentioned does show data on screen, however, I want to save it in a CSV or SQL system. Any clue? thx

Hi @rparada: You will have to modify the manual_control.py script. Have a look at the function _on_gnss_event(). It gets called every time the GNSS sensor gets new data. You could modify the function to store the current latitude and longitude in a list. At the end, i.e., in the world.destroy() function, you could write that list to a file.

If you want to write GNSS and IMU data into a file and you want them to be synchronized (you want to know which IMU measurement corresponds to which GNSS measurement), you might want to look at the example script synchronous_mode.py. But there you will need to do more changes, so maybe playing with manual_control.py is a good start.

Hi @thomasfermi the script manual_control.py provides data from the main vehicle (the one your are driving), however, I need to collect the data from the rest of vehicles simulated. How can I do it?

Hi @rparada. If you study the code in manual_control.py you will find that the GNNS sensor is “attached” to the main vehicle. For each additional vehicle you create, you can attach a separate GNSS sensor, if you want. Let’s say you have a vehicle object called vehicle7, then you do something along this line

bp = world.get_blueprint_library().find('sensor.other.gnss')
transform = vehicle7.get_transform()
gnss_sensor7 = world.spawn_actor(bp, transform, attach_to=vehicle7)
gnss_sensor7.listen(function_you_wrote_to_store_data_for_sensor7)

Hi @thomasfermi, how can I contact you directly, maybe create a specific room on Discord from CARLA channel? My username is rparada.

Thanks