Closed jiaoL06 closed 8 months ago
There is a long discussion about linking here: https://github.com/pyoscx/scenariogeneration/issues/172
https://github.com/pyoscx/scenariogeneration/issues/172#issuecomment-1704645695 this one might help?
What does the laneoffset mean?
basically how many lanes you want to move your connection, so as it looks in your case, that should be 0 (since -1 goes to -1), If you had -1 -> -2 the offset would be -1 and 1
Referencing this method to generate link connecting_road lanes, but not take effect,the connecting_road not lane link
can you post your example, or a simplistic example that replicates the issue?
Road generation methods are different:
from scenariogeneration import xodr
import numpy as np
import os
roads = []
# Create junction
junction = xodr.Junction("junction_id_3", 3)
# Create road0
planview = xodr.PlanView()
planview.add_fixed_geometry(xodr.Line(100), 0.0,0.0, np.pi)
planview.adjust_geometries()
centerlane = xodr.Lane(a=2)
lanesec = xodr.LaneSection(0, centerlane)
for i in range(3):
lane = xodr.Lane(a=3)
lanesec.add_left_lane(lane)
lanes = xodr.Lanes()
lanes.add_lanesection(lanesec)
incoming_road = xodr.Road(0, planview, lanes)
roads.append(incoming_road)
##Create road2
planview = xodr.PlanView()
planview.add_fixed_geometry(xodr.Arc(1/13.0,angle=np.pi/2), 0.0,-6.0, .0)
planview.adjust_geometries()
centerlane = xodr.Lane(a=2)
lanesec = xodr.LaneSection(0, centerlane)
for i in range(1):
lane = xodr.Lane(a=3)
lanesec.add_right_lane(lane)
lanes = xodr.Lanes()
lanes.add_lanesection(lanesec)
connecting_road = xodr.Road(2, planview, lanes)
roads.append(connecting_road)
# Successors and predecessors on road level
incoming_road.add_predecessor(xodr.ElementType.junction, 3)
connecting_road.add_predecessor(xodr.ElementType.road, 0, xodr.ContactPoint.start,2) # change offset here
# Incoming junction connection
connection_1 = xodr.Connection(0, 2, xodr.ContactPoint.start)
connection_1.add_lanelink(3, -1)
junction.add_connection(connection_1)
xodr.create_lane_links(incoming_road, connecting_road) # change here
# Create the OpenDRIVE
odr = xodr.OpenDrive("myroadnetwork")
odr.add_road(incoming_road)
odr.add_road(connecting_road)
odr.add_junction(junction)
# Write the OpenDRIVE file as xodr using current script name
odr.write_xml(os.path.basename(__file__).replace(".py", ".xodr"))
Why does this function in here(xodr.create_lane_links) not generate lane link for road. @mander76
There is but one little thing to add
connecting_road = xodr.Road(2, planview, lanes,road_type=3)
(I know the naming convention is bad)
But this will connect the road to the junction and then it knows how to do the links properly.
I found a problem in links.py.if the connected_road doesn't have the predecessor,it will be error。
If the order of these two conditions is swapped, the above example will report an error:
Hmm, well yes, but a connecting road needs both a successor and a predecessor, if a road has no connection it should be a normal road
we won't be able to connect and cut off the intersection like this:
After this modification, it's all right。
Need to check the standard, but don't know if it's allowed to cut an intersection like that.. Otherwise That's an easy fix
From standard, this is not mandatory
Yeah, cannot find anything about it. Can you do a pull-request of this change? :)
My pleasure。
I found that the code on Github is already correct, is it because the version I installed is older?
Well, that might be a solution aswell :P There has been some updates like this over the past months
But yes, try upgrading to the latest version of scenariogeneration then. what is in github now should be in the latest release aswell.
OK, thank you for your reply.
How to connect the front and back relationships of the current blue road,the road can connect by function road1.add_successor(xodr.ElementType.road, road2_id, xodr.ContactPoint.start), but the lanes can not connect by xodr.create_lane_links_from_ids(road1,road2,[-1],[-1]),