def test_arc():
    arc = pyodrx.Arc(1,length = 1)
    
    p = arc.get_element()
    prettyprint(p)

    arc = pyodrx.Arc(1,angle = 1)
    
    p = arc.get_element()
    prettyprint(p)
def test_arc_calc_angle(data,expdata):
    arc = pyodrx.Arc(data[4],angle=data[0])
    x,y,h,l = arc.get_end_data(data[1],data[2],data[3])
    assert pytest.approx(x,0.000001) == expdata[0]
    assert pytest.approx(y,0.000001) == expdata[1]
    assert pytest.approx(h,0.000001) == expdata[2]
    assert pytest.approx(l,0.000001) == expdata[3]
Example #3
0
    def road(self, **kwargs):

        road = xodr.create_road([
            xodr.Spiral(0.0000000001, kwargs['road_curvature'], 100),
            xodr.Arc(kwargs['road_curvature'], 50),
            xodr.Spiral(kwargs['road_curvature'], 0.0000000001, 100),
            xodr.Line(100)
        ],
                                id=0,
                                left_lanes=2,
                                right_lanes=2)
        odr = xodr.OpenDrive('myroad')
        odr.add_road(road)
        odr.adjust_roads_and_lanes()
        return odr
def test_inverted_Arc(data):
    
    arc = pyodrx.Arc(data[0],angle=data[1])

    end_x,end_y,end_h,end_l = arc.get_end_data(data[2],data[3],data[4])

    end_h += np.pi 

    start_x,start_y,start_h,start_l = arc.get_start_data(end_x,end_y,end_h)

    start_h -= np.pi

    assert pytest.approx(start_x, 0.000001) == data[2]
    assert pytest.approx(start_y, 0.000001) == data[3]
    assert pytest.approx(start_h, 0.00001) == data[4] 
Example #5
0
def test_create_lane_links_normalroad1():

    planview = []
    lanec = []
    lanel = []
    laner = []
    lanesec = []
    lanes = []

    rm = pyodrx.RoadMark(pyodrx.RoadMarkType.solid,
                         0.2,
                         rule=pyodrx.MarkRule.no_passing)

    geom = []
    geom.append(pyodrx.Line(50))
    geom.append(pyodrx.Arc(0.01, angle=np.pi / 2))
    geom.append(pyodrx.Line(50))

    # create planviews
    for i in range(len(geom)):
        planview.append(pyodrx.PlanView())
        planview[i].add_geometry(geom[i])
    # create centerlanes
    for i in range(len(geom)):
        lanec.append(pyodrx.Lane(a=3))
        lanel.append(pyodrx.Lane(a=3))
        laner.append(pyodrx.Lane(a=3))
    #add roadmarks
    for i in range(len(geom)):
        lanec[i].add_roadmark(rm)
        lanel[i].add_roadmark(rm)
        laner[i].add_roadmark(rm)
    # create lanesections
    for i in range(len(geom)):
        lanesec.append(pyodrx.LaneSection(0, lanec[i]))
        lanesec[i].add_right_lane(lanel[i])
        lanesec[i].add_left_lane(laner[i])
    #create lanes
    for i in range(len(geom)):
        lanes.append(pyodrx.Lanes())
        lanes[i].add_lanesection(lanesec[i])

    #create roads
    road1 = pyodrx.Road(1, planview[0], lanes[0])
    road1.add_successor(pyodrx.ElementType.road, 2, pyodrx.ContactPoint.start)

    road2 = pyodrx.Road(2, planview[1], lanes[1])
    road2.add_predecessor(pyodrx.ElementType.road, 1, pyodrx.ContactPoint.end)
    road2.add_successor(pyodrx.ElementType.road, 3, pyodrx.ContactPoint.start)

    road3 = pyodrx.Road(3, planview[2], lanes[2])
    road3.add_predecessor(pyodrx.ElementType.road, 2, pyodrx.ContactPoint.end)

    # create the opendrive and add roads
    odr = pyodrx.OpenDrive('myroad')
    odr.add_road(road1)
    odr.add_road(road2)
    odr.add_road(road3)

    odr.adjust_roads_and_lanes()

    assert road1.lanes.lanesections[0].rightlanes[0].links.get_predecessor_id(
    ) == None
    assert int(road1.lanes.lanesections[0].rightlanes[0].links.
               get_successor_id()) == -1
    assert road1.lanes.lanesections[0].leftlanes[0].links.get_predecessor_id(
    ) == None
    assert int(
        road1.lanes.lanesections[0].leftlanes[0].links.get_successor_id()) == 1

    assert int(road2.lanes.lanesections[0].rightlanes[0].links.
               get_predecessor_id()) == -1
    assert int(road2.lanes.lanesections[0].rightlanes[0].links.
               get_successor_id()) == -1
    assert int(road2.lanes.lanesections[0].leftlanes[0].links.
               get_predecessor_id()) == 1
    assert int(
        road2.lanes.lanesections[0].leftlanes[0].links.get_successor_id()) == 1

    assert int(road3.lanes.lanesections[0].rightlanes[0].links.
               get_predecessor_id()) == -1
    assert road3.lanes.lanesections[0].rightlanes[0].links.get_successor_id(
    ) == None
    assert int(road3.lanes.lanesections[0].leftlanes[0].links.
               get_predecessor_id()) == 1
    assert road3.lanes.lanesections[0].leftlanes[0].links.get_successor_id(
    ) == None
from scenariogeneration import xodr, prettyprint
import numpy as np
import os

## EXAMPLE 1
## Multiple geometries in one only road.

##1. Create the planview
planview = xodr.PlanView()

##2. Create some geometries and add them to the planview
line1 = xodr.Line(100)
arc1 = xodr.Arc(0.05, angle=np.pi / 2)
line2 = xodr.Line(100)
cloth1 = xodr.Spiral(0.05, -0.1, 30)
line3 = xodr.Line(100)

planview.add_geometry(line1)
planview.add_geometry(arc1)
planview.add_geometry(line2)
planview.add_geometry(cloth1)
planview.add_geometry(line3)

##3. Create a solid roadmark
rm = xodr.RoadMark(xodr.RoadMarkType.solid, 0.2)

##4. Create centerlane
centerlane = xodr.Lane(a=2)
centerlane.add_roadmark(rm)

##5. Create lane section form the centerlane
Example #7
0
import os
from scenariogeneration import xodr, xosc, esmini, prettyprint, ScenarioGenerator

planview = xodr.PlanView()

# add two geometries based on exact position
planview.add_fixed_geometry(xodr.Line(100), 0, 0, 0)
planview.add_fixed_geometry(xodr.Arc(0.01, length=100), 100, 0, 0)

# create simple lanes
lanes = xodr.Lanes()
lanesection1 = xodr.LaneSection(0, xodr.standard_lane())
lanesection1.add_left_lane(xodr.standard_lane(rm=xodr.STD_ROADMARK_SOLID))
lanesection1.add_right_lane(xodr.standard_lane(rm=xodr.STD_ROADMARK_SOLID))
lanes.add_lanesection(lanesection1)

road1 = xodr.Road(0, planview, lanes)

# create a simple second road for connection
road2 = xodr.create_road(xodr.Line(100), 1)

# connect the roads with successor/predecessor
road1.add_successor(xodr.ElementType.road, 1, xodr.ContactPoint.start)
road2.add_predecessor(xodr.ElementType.road, 0, xodr.ContactPoint.end)

odr = xodr.OpenDrive('my_road')
odr.add_road(road1)
odr.add_road(road2)

# will adjust the second road and the lanes and lane links correctly
odr.adjust_roads_and_lanes()
Example #8
0
from scenariogeneration import xodr
import os

# create some simple roads
roads = []
# start road
roads.append(
    xodr.create_road([
        xodr.Spiral(-0.004, 0.00001, 100),
        xodr.Spiral(0.00001, 0.005, 50),
        xodr.Arc(0.005, 50)
    ],
                     id=0,
                     left_lanes=3,
                     right_lanes=4))
# intermittent road
roads.append(
    xodr.create_road(
        [xodr.Spiral(0.0001, 0.003, 65),
         xodr.Spiral(0.003, 0.00001, 50)],
        id=1,
        left_lanes=3,
        right_lanes=3))

#exit road
roads.append(xodr.create_road(xodr.Line(50), id=2, left_lanes=0,
                              right_lanes=1))
# junctions for exit
roads.append(
    xodr.create_road(xodr.Spiral(0.005, 0.0001, 50),
                     id=3,