예제 #1
0
    def test_createMShapeRightLanes(self):

        roads = []
        roads.append(pyodrx.create_straight_road(0, 10))
        roads.append(
            self.roadBuilder.createMShape(
                1,
                1,
                -np.pi / 1.5,
                10,
                laneSides=junctions.LaneSides.RIGHT,
                direction=CircularDirection.COUNTERCLOCK_WISE))
        roads.append(pyodrx.create_straight_road(2, 10))

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

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

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

        junction = self.junctionBuilder.createJunctionForASeriesOfRoads(roads)

        odrName = "test_connectionRoad"
        odr = extensions.createOdr(odrName, roads, [junction])

        extensions.view_road(
            odr, os.path.join('..', self.configuration.get("esminipath")))
예제 #2
0
    def test_createMShape(self):

        roads = []
        roads.append(pyodrx.create_straight_road(0, 10))
        roads.append(self.roadBuilder.createMShape(1, 1, np.pi / 1.5, 10))
        roads.append(pyodrx.create_straight_road(2, 10))

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

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

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

        junction = self.junctionBuilder.createJunctionForASeriesOfRoads(roads)

        odrName = "test_connectionRoad"
        odr = extensions.createOdr(odrName, roads, [junction])

        extensions.view_road(
            odr, os.path.join('..', self.configuration.get("esminipath")))

        xmlPath = f"output/m-shape.xodr"
        odr.write_xml(xmlPath)

        extensions.saveRoadImageFromFile(xmlPath, self.esminiPath)
예제 #3
0
    def test_buildSimpleRoundAboutAndCheckInternalConnection(self):

        numRoads = 3
        odr = self.junctionBuilder.buildSimpleRoundAbout(
            odrId=0, numRoads=numRoads, radius=10, cp1=pyodrx.ContactPoint.end)
        xmlPath = f"output/test-SimpleRoundAbout-{numRoads}.xodr"
        odr.write_xml(xmlPath)

        extensions.printRoadPositions(odr)
        extensions.saveRoadImageFromFile(xmlPath, self.esminiPath)
        extensions.view_road(odr, os.path.join('..', self.esminiPath))

        # what's the problem with internal connections?

        internalConnection = odr.roads['12'].shallowCopy()
        internalConnection.clearRoadLinks()

        odr = extensions.createOdr("12 only", [internalConnection], [])

        xmlPath = f"output/test-SimpleRoundAbout-{numRoads}-road-12.xodr"
        odr.write_xml(xmlPath)

        extensions.printRoadPositions(odr)
        extensions.saveRoadImageFromFile(xmlPath, self.esminiPath)
        extensions.view_road(odr, os.path.join('..', self.esminiPath))
예제 #4
0
    def test_getCurvatureForAngleAndLength(self):
        numberofLanes = 10
        laneOffset = 3
        # angle = 120
        # curve, angle = AngleCurvatureMap.getCurvatureForNonOverlappingRoads(angle, numberofLanes, laneOffset)

        angle = np.pi * 1.2
        length = 20
        # curve, angle = AngleCurvatureMap.getCurvatureForNonOverlappingRoads(angle, numberofLanes, laneOffset)
        maxCurve = AngleCurvatureMap.getMaxCurvatureAgainstMaxRoadWidth(
            angle, numberofLanes * laneOffset)
        curve = AngleCurvatureMap.getCurvatureForAngleAndLength(angle, length)

        print(f"max curve {maxCurve}, current curve {curve}")
        roads = []
        roads.append(
            pyodrx.create_straight_road(0,
                                        50,
                                        n_lanes=numberofLanes,
                                        lane_offset=laneOffset))
        roads.append(
            self.roadBuilder.
            createSimpleCurveWithLongArcWithLaneNumberandOffset(
                1,
                angle,
                False,
                curvature=curve,
                _n_lanes=numberofLanes,
                _lane_offset=laneOffset))
        roads.append(
            pyodrx.create_straight_road(2,
                                        50,
                                        n_lanes=numberofLanes,
                                        lane_offset=laneOffset))

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

        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.road, 1,
                                 pyodrx.ContactPoint.end)

        odrName = "curve_test"
        odr = extensions.createOdr(odrName, roads, [])
        extensions.view_road(odr, self.esminiPath)
예제 #5
0
    def test_getConnectionRoadBetween(self):
        # test scenario for connection road

        roads = []
        roads.append(pyodrx.create_straight_road(0, 10))
        roads.append(
            self.roadBuilder.curveBuilder.createSimple(1,
                                                       np.pi / 4,
                                                       True,
                                                       curvature=0.2))
        roads.append(pyodrx.create_straight_road(2, 10))
        roads.append(
            self.roadBuilder.curveBuilder.createSimple(3,
                                                       np.pi / 3,
                                                       True,
                                                       curvature=0.2))
        roads.append(pyodrx.create_straight_road(4, 10))
        roads.append(
            self.roadBuilder.curveBuilder.createSimple(5,
                                                       np.pi / 2,
                                                       True,
                                                       curvature=0.2))
        roads.append(pyodrx.create_straight_road(6, 10))

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

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

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

        roads[3].add_predecessor(pyodrx.ElementType.road, 2,
                                 pyodrx.ContactPoint.start)
        roads[3].add_successor(pyodrx.ElementType.road, 4,
                               pyodrx.ContactPoint.start)

        roads[4].add_predecessor(pyodrx.ElementType.junction, 3)
        roads[4].add_successor(pyodrx.ElementType.junction, 5)

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

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

        junction = self.junctionBuilder.createJunctionForASeriesOfRoads(roads)

        odrName = "test_connectionRoad"
        odr = extensions.createOdr(odrName, roads, [junction])

        lastConnection = self.harvester.junctionBuilder.createLastConnectionForLastAndFirstRoad(
            7, roads, junction, cp1=pyodrx.ContactPoint.start)
        roads.append(lastConnection)
        odr.add_road(lastConnection)

        # randConnection = self.harvester.junctionBuilder.createConnectionFor2Roads(8, roads[0], roads[4], junction, cp1=pyodrx.ContactPoint.start)
        # roads.append(randConnection)
        # odr.add_road(randConnection)

        # randConnection2 = self.harvester.junctionBuilder.createConnectionFor2Roads(9, roads[2], roads[6], junction, cp1=pyodrx.ContactPoint.start)
        # roads.append(randConnection2)
        # odr.add_road(randConnection2)

        # odr.reset()
        # odr.add_road(lastConnection)
        # odr.adjust_roads_and_lanes()

        odr.resetAndReadjust()

        # pyodrx.prettyprint(odr.get_element())

        odr.write_xml(f"output/test_connectionRoad.xodr")

        # extensions.printRoadPositions(odr)

        extensions.view_road(
            odr, os.path.join('..', self.configuration.get("esminipath")))
        pass
예제 #6
0
    def test_AdjustStartPointsForAnyRoadCombinations(self):
        # test scenario for connection road

        roads = []
        roads.append(pyodrx.create_straight_road(0, 10))
        roads.append(
            self.roadBuilder.curveBuilder.createSimpleCurveWithLongArc(
                1, np.pi / 4, False, curvature=0.2))
        roads.append(pyodrx.create_straight_road(2, 10))
        roads.append(
            self.roadBuilder.curveBuilder.createSimpleCurveWithLongArc(
                3, np.pi / 3, True, curvature=0.2))
        roads.append(pyodrx.create_straight_road(4, 10))
        roads.append(
            self.roadBuilder.curveBuilder.createSimpleCurveWithLongArc(
                5, np.pi / 2, True, curvature=0.2))
        roads.append(pyodrx.create_straight_road(6, 10))

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

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

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

        roads[3].add_predecessor(pyodrx.ElementType.road, 2,
                                 pyodrx.ContactPoint.start)
        roads[3].add_successor(pyodrx.ElementType.road, 4,
                               pyodrx.ContactPoint.start)

        roads[4].add_predecessor(pyodrx.ElementType.junction, 3)
        roads[4].add_successor(pyodrx.ElementType.junction, 5)

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

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

        junction = self.junctionBuilder.createJunctionForASeriesOfRoads(roads)

        odrName = "test_connectionRoad"
        odr = extensions.createOdr(odrName, roads, [junction])

        lastConnection = self.harvester.junctionBuilder.createLastConnectionForLastAndFirstRoad(
            7, roads, junction, cp1=pyodrx.ContactPoint.start)
        roads.append(lastConnection)
        odr.add_road(lastConnection)

        # randConnection = self.harvester.junctionBuilder.createConnectionFor2Roads(8, roads[0], roads[4], junction, cp1=pyodrx.ContactPoint.start)
        # roads.append(randConnection)
        # odr.add_road(randConnection)

        # randConnection2 = self.harvester.junctionBuilder.createConnectionFor2Roads(9, roads[2], roads[6], junction, cp1=pyodrx.ContactPoint.start)
        # roads.append(randConnection2)
        # odr.add_road(randConnection2)

        odr.resetAndReadjust()

        extensions.printRoadPositions(odr)

        extensions.view_road(
            odr, os.path.join('..', self.configuration.get("esminipath")))
        pass
예제 #7
0
    def createOdr(self, name, roads, junctions):

        return extensions.createOdr(name, roads, junctions)