Adding Intersections to xml files

Hello,

I am working on adding intersections to my scenarios and writing them to .xml files. However, when I tried to open the file after I had written it, this error message occurred:

left_of = int(left_of_ref.get('ref'))
ValueError: invalid literal for int() with base 10: '{50195}'
{50195} is a lanelet_id in my scenario.

The problem seems to originate in the file_reader (IntersectionFactory or IntersectionIncomingFactory, where the conversion to int cant be performed. This is what the xml file looks like, after I added the intersection and saved it:

intersection

Then I looked into file_writer: is there a reason why in IntersectionXMLNode the function create_node handles left_of differently than all other successors?
What can I do to write the isLeftOf parameter into my xml file as an int/str and not a set?

Hi,

left_of is of type int: https://commonroad.in.tum.de/static/docs/commonroad-io/api/scenario.html#commonroad.scenario.intersection.IntersectionIncomingElement.left_of.
left_of refers to the left IntersectionIncomingElement, not to a lanelet.

Therefore, the creation of your IntersectionIncomingElement is probably wrong.
Here an example how to create an intersection:

intersection = \
            Intersection(intersection_id=301,
                         incomings=[IntersectionIncomingElement(incoming_id=302, incoming_lanelets={13},
                                                                successors_right={26},
                                                                successors_straight={22},
                                                                successors_left={20}, left_of=304),
                                    IntersectionIncomingElement(incoming_id=303, incoming_lanelets={14},
                                                                successors_right={30}, successors_straight={24},
                                                                successors_left={28}, left_of=302),
                                    IntersectionIncomingElement(incoming_id=304, incoming_lanelets={17},
                                                                successors_right={27}, successors_straight={23},
                                                                successors_left={31}, left_of=305),
                                    IntersectionIncomingElement(incoming_id=305, incoming_lanelets={18},
                                                                successors_right={29}, successors_straight={21},
                                                                successors_left={25}, left_of=305)])

We will update the commonroad-io documentation for the next release to clarify the meaning of left_of. Currently, the meaning of left_of is only documented in the scenario documentation.

Best,
Sebastian

1 Like