Esempio n. 1
0
    def createConnectionFor2Roads(self,
                                  nextRoadId,
                                  road1,
                                  road2,
                                  junction,
                                  cp1,
                                  cp2,
                                  n_lanes=1,
                                  lane_offset=3,
                                  laneSides=LaneSides.BOTH):
        """Does not modify predecessor or successor of the given roads.

        Args:
            junction: the junction object to add links.

        Returns:
            [type]: connection road with first road as the predecessor and second road as the successor
        """

        newConnectionId = nextRoadId
        newConnectionRoad = self.roadBuilder.getConnectionRoadBetween(
            newConnectionId,
            road1,
            road2,
            cp1,
            cp2,
            isJunction=True,
            n_lanes=n_lanes,
            lane_offset=lane_offset,
            laneSides=laneSides)

        RoadLinker.createExtendedPredSuc(predRoad=road1,
                                         predCp=cp1,
                                         sucRoad=newConnectionRoad,
                                         sucCP=pyodrx.ContactPoint.start)
        RoadLinker.createExtendedPredSuc(predRoad=newConnectionRoad,
                                         predCp=pyodrx.ContactPoint.end,
                                         sucRoad=road2,
                                         sucCP=cp2)

        if junction is not None:
            if laneSides == LaneSides.LEFT or laneSides == LaneSides.BOTH:
                connectionL = pyodrx.Connection(road2.id, newConnectionId,
                                                pyodrx.ContactPoint.end)
                connectionL.add_lanelink(-1, -1)
                junction.add_connection(connectionL)
            else:
                connectionL = pyodrx.Connection(road1.id, newConnectionId,
                                                pyodrx.ContactPoint.start)
                connectionL.add_lanelink(1, 1)
                junction.add_connection(connectionL)

        return newConnectionRoad
Esempio n. 2
0
def test_connection():
    con = pyodrx.Connection(1,2,pyodrx.ContactPoint.start,5)

    con.add_lanelink(1,-1)
    con.add_lanelink(2,-2)

    pyodrx.prettyprint(con.get_element())
Esempio n. 3
0
    def test_cubicParams(self):
        roads = []
        roads.append(pyodrx.create_straight_road(0, 10))
        roads.append(self.roadBuilder.createParamPoly3(1, isJunction=True))
        roads.append(pyodrx.create_straight_road(2, 1))

        roads[0].add_successor(pyodrx.ElementType.junction, 1)

        roads[1].add_predecessor(pyodrx.ElementType.road, 0,
                                 pyodrx.ContactPoint.end)
        roads[1].add_successor(pyodrx.ElementType.road, 2,
                               pyodrx.ContactPoint.start)

        roads[2].add_predecessor(pyodrx.ElementType.junction, 1)

        con1 = pyodrx.Connection(0, 1, pyodrx.ContactPoint.start)
        con1.add_lanelink(-1, -1)

        junction = pyodrx.Junction('test', 1)
        junction.add_connection(con1)

        odr = pyodrx.OpenDrive('test')
        for r in roads:
            odr.add_road(r)
        odr.add_junction(junction)
        odr.adjust_roads_and_lanes()

        extensions.view_road(odr,
                             os.path.join('..', 'F:\\myProjects\\av\\esmini'))
Esempio n. 4
0
    def createLastConnectionForLastAndFirstRoad(self,
                                                nextRoadId,
                                                roads,
                                                junction,
                                                cp1=pyodrx.ContactPoint.end,
                                                cp2=pyodrx.ContactPoint.start):

        lastConnectionId = nextRoadId
        lastConnection = self.roadBuilder.getConnectionRoadBetween(
            lastConnectionId, roads[-1], roads[0], cp2, cp1)

        RoadLinker.createExtendedPredSuc(predRoad=roads[-1],
                                         predCp=cp2,
                                         sucRoad=lastConnection,
                                         sucCP=pyodrx.ContactPoint.start)
        RoadLinker.createExtendedPredSuc(predRoad=lastConnection,
                                         predCp=pyodrx.ContactPoint.end,
                                         sucRoad=roads[0],
                                         sucCP=cp1)

        connectionL = pyodrx.Connection(roads[-1].id, lastConnectionId,
                                        pyodrx.ContactPoint.start)
        connectionL.add_lanelink(-1, -1)
        junction.add_connection(connectionL)

        # roads.append(lastConnection) # dangerous. do not add the road

        return lastConnection
Esempio n. 5
0
def test_junction():
    con1 = pyodrx.Connection(1,2,pyodrx.ContactPoint.start)

    con1.add_lanelink(1,-1)
    con1.add_lanelink(2,-2)

    con2 = pyodrx.Connection(2,1,pyodrx.ContactPoint.start)

    con2.add_lanelink(1,-1)
    con2.add_lanelink(2,-2)
    con2.add_lanelink(3,-3)

    junciton = pyodrx.Junction('',1)

    junciton.add_connection(con1)
    junciton.add_connection(con2)

    pyodrx.prettyprint(junciton.get_element())
Esempio n. 6
0
    def createJunctionFor2Connections(self, roadFirstPred, connectionRoadFirst,
                                      roadFirstSuc, connectionRoadSecond):

        # TODO experiment with connecting more lanes for a single connection road.

        con1 = pyodrx.Connection(roadFirstPred.id, connectionRoadFirst.id,
                                 pyodrx.ContactPoint.start)
        con1.add_lanelink(-1, -1)

        con2 = pyodrx.Connection(roadFirstSuc.id, connectionRoadSecond.id,
                                 pyodrx.ContactPoint.start)
        con2.add_lanelink(-1, -1)

        junction = pyodrx.Junction('junc', 1)

        junction.add_connection(con1)
        junction.add_connection(con1)

        return junction
Esempio n. 7
0
    def connect2LaneRoads(self, incomingRoadId, connectionRoadId,):
        """Assumes no center lane offset.

        Args:
            incomingRoadId ([type]): [description]
            connectionRoadId ([type]): [description]
        """
        connection = pyodrx.Connection(incomingRoadId, connectionRoadId, pyodrx.ContactPoint.start)
        connection.add_lanelink(-1,-1)
        return connection
Esempio n. 8
0
    def createJunctionForASeriesOfRoads(self, roads, id=0):
        """[summary]

        Args:
            roads ([type]): even indices are roads, odd indices are connection roads  of the junction

        Returns:
            [type]: [description]
        """

        # TODO it does not support all lanes.
        # ID is wrong
        junction = pyodrx.Junction("spiderJunction", id)

        connectionId = 1

        while (connectionId < len(roads)):

            print(f"connecting roads {connectionId-1} {connectionId}")
            connectionL = pyodrx.Connection(connectionId - 1, connectionId,
                                            pyodrx.ContactPoint.start)
            connectionL.add_lanelink(-1, -1)

            # if (connectionId + 1) < len(roads):
            #     connectionR = pyodrx.Connection(connectionId+1, connectionId, pyodrx.ContactPoint.end)
            # else:
            #     connectionR = pyodrx.Connection(0, connectionId, pyodrx.ContactPoint.end)

            # connectionR.add_lanelink(1,1)

            junction.add_connection(connectionL)
            # junction.add_connection(connectionR)

            connectionId += 2

        return junction
Esempio n. 9
0
roads[4].add_predecessor(pyodrx.ElementType.junction,1)

roads[5].add_predecessor(pyodrx.ElementType.road,0,pyodrx.ContactPoint.end)
roads[5].add_successor(pyodrx.ElementType.road,6,pyodrx.ContactPoint.start)

roads[6].add_predecessor(pyodrx.ElementType.junction,1)

# create the opendrive
odr = pyodrx.OpenDrive('myroad')
for r in roads:
    odr.add_road(r)

# create junction
junction = pyodrx.Junction('test',1)
con1 = pyodrx.Connection(0,1,pyodrx.ContactPoint.start)
con1.add_lanelink(-1,-1)
con2 = pyodrx.Connection(0,3,pyodrx.ContactPoint.start)
con2.add_lanelink(-1,-1)
con3 = pyodrx.Connection(0,5,pyodrx.ContactPoint.start)
con3.add_lanelink(-1,-1)

con4 = pyodrx.Connection(2,1,pyodrx.ContactPoint.end)
con4.add_lanelink(1,1)
con5 = pyodrx.Connection(4,3,pyodrx.ContactPoint.end)
con5.add_lanelink(1,1)
con6 = pyodrx.Connection(6,5,pyodrx.ContactPoint.end)
con6.add_lanelink(1,1)

junction.add_connection(con1)
junction.add_connection(con2)