fzi-forschungszentrum-informatik / Lanelet2

Map handling framework for automated driving
BSD 3-Clause "New" or "Revised" License
800 stars 328 forks source link

Python repr fix for RecursionError caused by circular references in lanelets with regulatory elements #372

Open johannes-fischer opened 2 weeks ago

johannes-fischer commented 2 weeks ago

This MR contains some small fixes related to calling repr and str on python lanelet objects.

For some reason this is not working as expected for RuleParameterMap, as can be seen by trying to run std::cout << trafficLightRegelem->getParameters(); here. Hence, I had to add methods for the repr of the RuleParameterMap

Example code:

import os
import lanelet2
from lanelet2.projection import UtmProjector

map_file = os.path.join("src", "lanelet2", "lanelet2_maps", "res", "mapping_example.osm")
projector = UtmProjector(lanelet2.io.Origin(49, 8.4))
loadedMap = lanelet2.io.load(map_file, projector)

ll = loadedMap.laneletLayer[45014]
print(str(ll))
print(repr(ll))

reg_els = ll.regulatoryElements
print(str(reg_els))
print(repr(reg_els))

# Right of way
reg_el = reg_els[0]
print(str(reg_el))
print(repr(reg_el))
print(str(reg_el.parameters))
print(repr(reg_el.parameters))
immel-f commented 2 weeks ago

Thanks for the contribution and for discovering that bug. Could you add some small test cases to the python unit tests for the repr functions you fixed?

johannes-fischer commented 1 day ago

I have added some python unit tests now.