pyoscx / scenariogeneration

Python library to generate linked OpenDRIVE and OpenSCENARIO files
Mozilla Public License 2.0
256 stars 81 forks source link

[bug] Roads linked by DirectJunctionCreator lack successor/predecessor. #228

Open throusea opened 2 months ago

throusea commented 2 months ago

I tried code example in user documentation and run locally with version 0.14.3.

from scenariogeneration import xodr
junction_id = 100
direct_junction = xodr.DirectJunctionCreator(junction_id,'my_direct_junction')

first_road = xodr.create_road([xodr.Line(300)],
            id= 1,
            left_lanes=3,
            right_lanes=4)

continuation_road = xodr.create_road([xodr.Line(300)],
            id= 2,
            left_lanes=3,
            right_lanes=3)

off_ramp = xodr.create_road([xodr.Spiral(-0.00001,-0.02,length=150)],
            id= 3,
            left_lanes=0,
            right_lanes=1)

first_road.add_successor(xodr.ElementType.junction, junction_id)
continuation_road.add_predecessor(xodr.ElementType.junction, junction_id)
off_ramp.add_predecessor(xodr.ElementType.junction, junction_id)

direct_junction.add_connection(
            incoming_road = first_road,
            linked_road = continuation_road)
direct_junction.add_connection(
            incoming_road = first_road,
            linked_road = off_ramp,
            incoming_lane_ids=-4,
            linked_lane_ids = -1)
odr = xodr.OpenDrive('myroad')

odr.add_road(first_road)
odr.add_road(continuation_road)
odr.add_road(off_ramp)

odr.add_junction_creator(direct_junction)
odr.adjust_roads_and_lanes()
xodr.printToFile(odr, "demo7.xodr")

It generated a file named demo7.xodr and I tried to import it into carla. It shows error like "next_lane != nullptr". Then I preview it by online OpenDrive Viewer https://odrviewer.io/ and compared with its example road network. I found that the road lacks sucessor/predecessor with linked road. Or the connections between two roads by DirectJunctionCreator failed.

image

Maybe I ignore the step and have another code to fix it.