pyoscx / scenariogeneration

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

How to link one lane between the roads #189

Closed jiaoL06 closed 8 months ago

jiaoL06 commented 8 months ago

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]),

image image

mander76 commented 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?

jiaoL06 commented 8 months ago

What does the laneoffset mean? image image

mander76 commented 8 months ago

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

jiaoL06 commented 8 months ago

image Referencing this method to generate link connecting_road lanes, but not take effect,the connecting_road not lane link

mander76 commented 8 months ago

can you post your example, or a simplistic example that replicates the issue?

jiaoL06 commented 8 months ago

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"))
jiaoL06 commented 8 months ago

Why does this function in here(xodr.create_lane_links) not generate lane link for road. @mander76

mander76 commented 8 months ago

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.

jiaoL06 commented 8 months ago

image 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: image

mander76 commented 8 months ago

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

jiaoL06 commented 8 months ago

we won't be able to connect and cut off the intersection like this: image

jiaoL06 commented 8 months ago

image After this modification, it's all right。

mander76 commented 8 months ago

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

jiaoL06 commented 8 months ago

From standard, this is not mandatory

mander76 commented 8 months ago

Yeah, cannot find anything about it. Can you do a pull-request of this change? :)

jiaoL06 commented 8 months ago

My pleasure。

jiaoL06 commented 8 months ago

image I found that the code on Github is already correct, is it because the version I installed is older? image

mander76 commented 8 months ago

Well, that might be a solution aswell :P There has been some updates like this over the past months

mander76 commented 8 months ago

But yes, try upgrading to the latest version of scenariogeneration then. what is in github now should be in the latest release aswell.

jiaoL06 commented 8 months ago

OK, thank you for your reply.