コード例 #1
0
def main():
    beamng = BeamNGpy('localhost', 64256)

    scenario = Scenario('GridMap', 'road_test')
    road_a = Road('track_editor_C_center', looped=True)
    nodes = [
        (-25, 300, 0, 5),
        (25, 300, 0, 6),
        (25, 350, 0, 4),
        (-25, 350, 0, 5),
    ]
    road_a.nodes.extend(nodes)
    scenario.add_road(road_a)

    road_b = Road('track_editor_C_center')
    nodes = [
        (0, 325, 0, 5),
        (50, 375, 0, 5),
    ]
    road_b.nodes.extend(nodes)
    scenario.add_road(road_b)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        input('Press enter when done...')
    finally:
        bng.close()
コード例 #2
0
def main():
    beamng = BeamNGpy('localhost',
                      64256,
                      home='C:/Users/merie/Documents/BeamNG.research.v1.7.0.0')

    scenario = Scenario('GridMap', 'road_test')
    road_a = Road('track_editor_C_center', rid='circle_road', looped=True)
    nodes = [
        (-25, 300, 0, 5),
        (25, 300, 0, 6),
        (25, 350, 0, 4),
        (-25, 350, 0, 5),
    ]
    road_a.nodes.extend(nodes)
    scenario.add_road(road_a)

    road_b = Road('track_editor_C_center', rid='center_road')
    nodes = [
        (0, 325, 0, 5),
        (50, 375, 0, 5),
    ]
    road_b.nodes.extend(nodes)
    scenario.add_road(road_b)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        input('Press enter when done...')
    finally:
        bng.close()
コード例 #3
0
def getStrangeScenario():
    beamNGPAth = getBeamngDirectory()
    beamng = BeamNGpy(
        'localhost', 64256,
        home=beamNGPAth)  # This is the host & port used to communicate over
    wallCrashScenario = Scenario('smallgrid', 'road_test')
    wall = StaticObject(
        name="Crash_Test_Wall",
        pos=(10, 0, 0),
        rot=(0, 0, 0),
        scale=(1, 10, 1),
        shape='/levels/smallgrid/art/shapes/misc/gm_alpha_barrier.dae')
    testRoad = Road('track_editor_A_center', rid='Test_Road')
    roadNode = [(-10, 0, 0, 7), (20, 0, 62)]
    testRoad.nodes.extend(roadNode)
    testVehicle = Vehicle('Test_Vehicule',
                          model='etkc',
                          licence='LIFLAB',
                          colour='Blue')
    wallCrashScenario.add_road(testRoad)
    wallCrashScenario.add_object(wall)
    wallCrashScenario.add_vehicle(testVehicle,
                                  pos=(0, 0, 0),
                                  rot=(0, 180, -90))
    scenarioDict = {
        'beamng': beamng,
        'scenario': wallCrashScenario,
        'vehicule': testVehicle
    }
    return scenarioDict
コード例 #4
0
def main():
    beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN')

    scenario = Scenario('GridMap', 'road_test')
    road_a = Road('custom_track_center', looped=False)
    nodes = [
        (0, 0, 0, 4),
        (0, 400, 0, 4),
    ]
    road_a.nodes.extend(nodes)
    scenario.add_road(road_a)

    vehicle = Vehicle('ego', model='etk800', licence='PYTHON', colour='Black')
    scenario.add_vehicle(vehicle,  pos = ( 0, 0, 0.163609) , rot=(0,0,180)) # 0.163609 ,
    scenario.make(beamng)

    script = list()

    node0 = {
        'x': 0,
        'y': 2,
        'z': 0.163609,
        't': 0.01,
    }

    node1 = {
        'x': 0,
        'y': 3,
        'z': 0.163609,
        't': 0.01,
    }

    node2 = {
        'x': 0,
        'y': 350,
        'z': 0.163609,
        't': 15,
    }

    node3 = {
        'x': 0,
        'y': 400,
        'z': 0.163609,
        't': 5,
    }

    script.append(node0)
    script.append(node1)
    script.append(node2)
    script.append(node3)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        vehicle.ai_set_script(script)

        input('Press enter when done...')
    finally:
        bng.close()
コード例 #5
0
ファイル: SquareRoadScenario.py プロジェクト: liflab/brpc2020
def getSquareRoadScenario():
    beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory()
                      )  # This is the host & port used to communicate over
    squareRoadScenario = Scenario('smallgrid', 'Straight_Foward_Test')

    testRoad = Road('track_editor_C_center', rid='Test_Road', looped=True)
    roadNode = [(0, 0, 0, 7), (250, 0, 0, 7), (250, 250, 0, 7), (0, 250, 0, 7)]
    testRoad.nodes.extend(roadNode)

    testVehicle = Vehicle('Test_Vehicule',
                          model='etkc',
                          licence='LIFLAB',
                          colour='Blue')

    # Create an Electrics sensor and attach it to the vehicle
    electrics = Electrics()
    testVehicle.attach_sensor('electrics', electrics)

    # Create a Damage sensor and attach it to the vehicle if module is selected
    damage = Damage()
    testVehicle.attach_sensor('damage', damage)

    # Create a Gforce sensor and attach it to the vehicle if module is selected
    gForce = GForces()
    testVehicle.attach_sensor('GForces', gForce)

    squareRoadScenario.add_road(testRoad)
    squareRoadScenario.add_vehicle(testVehicle, pos=(0, 0, 0), rot=(0, 0, -90))
    scenarioDict = {
        'beamng': beamng,
        'scenario': squareRoadScenario,
        'vehicule': testVehicle
    }

    return scenarioDict
def createBeamNGLanes():

    beamng = BeamNGpy('localhost',
                      64256,
                      home='F:\Softwares\BeamNG_Research_SVN')
    scenario = Scenario('GridMap', 'road_test')

    graph_edges = graph.edges

    for sample in graph_edges:
        road_a = Road('track_editor_C_border', looped=False)
        road_b = Road('track_editor_C_border', looped=False)

        point1 = list(beamng_dict[sample[0]])
        point2 = list(beamng_dict[sample[1]])

        lane_marking_points = getRoadEndLaneMarking(point1, point2, 4)

        nodes0 = [
            (lane_marking_points[0], lane_marking_points[1], -0.05, 0.05),
            (lane_marking_points[4], lane_marking_points[5], -0.05, 0.05)
        ]

        nodes1 = [
            (lane_marking_points[2], lane_marking_points[3], -0.05, 0.05),
            (lane_marking_points[6], lane_marking_points[7], -0.05, 0.05)
        ]

        road_a.nodes.extend(nodes0)
        road_b.nodes.extend(nodes1)
        scenario.add_road(road_a)
        scenario.add_road(road_b)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()

        input('Press enter when done...')

    finally:
        bng.close()
コード例 #7
0
    def __init__(self, prefab):
        """
        :param prefab: (str) Path to a prefab file.
        """
        training_road = read_prefab(prefab)
        self.road_line = None

        self.asphalt = Road(material='a_asphalt_01_a',
                            rid='asphalt',
                            texture_length=2.5,
                            break_angle=180)
        self.asphalt.nodes.extend(training_road['asphalt'])
        self.mid_nodes = [RoadPoint(node[:3]) for node in self.asphalt.nodes]

        self.mid_line = Road(material='line_yellow',
                             rid='mid_lane',
                             texture_length=16,
                             break_angle=180,
                             drivability=-1)
        self.mid_line.nodes.extend(training_road['mid'])
        self.mid_line_nodes = [
            RoadPoint(node[:3]) for node in self.mid_line.nodes
        ]

        self.left_line = Road(material='line_white',
                              rid='left_line',
                              texture_length=16,
                              break_angle=180,
                              drivability=-1)
        self.left_line.nodes.extend(training_road['left'])
        self.left_nodes = [
            RoadPoint(node[:3]) for node in self.left_line.nodes
        ]

        self.right_line = Road(material='line_white',
                               rid='right_line',
                               texture_length=16,
                               break_angle=180,
                               drivability=-1)
        self.right_line.nodes.extend(training_road['right'])
        self.right_nodes = [
            RoadPoint(node[:3]) for node in self.right_line.nodes
        ]
コード例 #8
0
def main():
    beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN')

    scenario = Scenario('GridMap', 'road_test')
    road_a = Road('custom_track_center', looped=False)
    nodes = [
        (0, 0, 0, 8),
        (125, 0, 0, 8),
        (250, -10, 0, 12)
    ]
    road_a.nodes.extend(nodes)
    scenario.add_road(road_a)

    road_b = Road('custom_track_center', looped=False)
    nodes = [
        (125, 0, 0,12 ),
        (250, -10, 0, 12)
    ]
    road_b.nodes.extend(nodes)
    scenario.add_road(road_b)

    road_c = Road('custom_track_center', looped=False)
    nodes = [
        (125, 125, 0, 8),
        (125, 0, 0, 8),
    ]
    road_c.nodes.extend(nodes)
    scenario.add_road(road_c)

    vehicle = Vehicle('ego', model='etk800', licence='PYTHON', colour='Black')
    scenario.add_vehicle(vehicle, pos=(0, 0, 0.163609), rot=(0, 0, 180))  # 0.163609 ,

    scenario.make(beamng)
    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()



        input('Press enter when done...')
    finally:
        bng.close()
コード例 #9
0
ファイル: RoadTest.py プロジェクト: liflab/brpc2020
def main():
    path='C:/Users/marc/Desktop/BeamNG'
    beamng = BeamNGpy('localhost', 64256,path)


    scenario = Scenario('GridMap', 'vehicle_bbox_example')
    road = Road('track_editor_C_center', rid='main_road', texture_length=5)
    orig = (-107, 70, 0)
    goal = (-300, 70, 0)
    road.nodes = [
        (*orig, 7),
        (*goal, 7),
    ]
    scenario.add_road(road)
    script = [{'x': orig[0], 'y': orig[1], 'z': .3, 't': 0}]
    h=0
    i = 0.2
    while script[h]['x'] > goal[0]:
        node = {
            'x': -10 * i + orig[0],
            'y': 8 * np.sin(i) + orig[1],
            'z': 0.3,
            't': 1.5 * i,
        }
        script.append(node)
        i += 0.2
        h+=1

    print(script)

    vehicle = Vehicle('ego_vehicle', model='etkc', licence='PYTHON')
    scenario.add_vehicle(vehicle, pos=orig)

    scenario.make(beamng)
    bng = beamng.open()
    bng.load_scenario(scenario)
    bng.start_scenario()

    vehicle.ai_set_script(script)
    bng.pause()
    bng.step(1)
コード例 #10
0
ファイル: WallCrashScenario.py プロジェクト: liflab/brpc2020
def getWallCrashScenario(testName):
    beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory()
                      )  # This is the host & port used to communicate over
    wallCrashScenario = Scenario('smallgrid', str(testName))

    wall = StaticObject(
        name="Crash_Test_Wall",
        pos=(420, 0, 0),
        rot=(0, 0, 0),
        scale=(1, 10, 75),
        shape='/levels/smallgrid/art/shapes/misc/gm_alpha_barrier.dae')

    testRoad = Road('track_editor_B_center', rid='Test_Road')
    roadNode = [(-2, 0, 0, 7), (420, 0, 0, 7)]
    testRoad.nodes.extend(roadNode)

    testVehicle = Vehicle('Test_Vehicule',
                          model=SelectCar(),
                          licence='LIFLAB',
                          colour='Blue')

    # Create an Electrics sensor and attach it to the vehicle
    electrics = Electrics()
    testVehicle.attach_sensor('electrics', electrics)

    # Create a Damage sensor and attach it to the vehicle if module is selected
    damage = Damage()
    testVehicle.attach_sensor('damage', damage)

    # Create a Gforce sensor and attach it to the vehicle if module is selected
    gForce = GForces()
    testVehicle.attach_sensor('GForces', gForce)

    wallCrashScenario.add_road(testRoad)
    wallCrashScenario.add_object(wall)
    wallCrashScenario.add_vehicle(testVehicle, pos=(0, 0, 0), rot=(0, 0, -90))
    scenarioDict = {
        'beamng': beamng,
        'scenario': wallCrashScenario,
        'vehicule': testVehicle
    }

    return scenarioDict
コード例 #11
0
def createBeamNGLanes():

    beamng = BeamNGpy('localhost',
                      64256,
                      home='F:\Softwares\BeamNG_Research_SVN')
    scenario = Scenario('GridMap', 'road_test')

    graph_edges = graph.edges

    for sample in graph_edges:

        point1 = list(beamng_dict[sample[0]])
        point2 = list(beamng_dict[sample[1]])
        print(point1)
        print(point2)

        lane_marking_points = getRoadLaneMarking(point1, point2, 10, 3)

        # for loop iterate to put polylines.

        for polyline in lane_marking_points:
            print(polyline)
            road_a = Road('track_editor_C_border', looped=False)

            nodes0 = [(polyline[0], polyline[1], -0.05, 0.05),
                      (polyline[2], polyline[3], -0.05, 0.05)]

            road_a.nodes.extend(nodes0)
            scenario.add_road(road_a)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()

        input('Press enter when done...')

    finally:
        bng.close()
def createBeamNGRoads():

    print(graph.edges)

    graph_edges = graph.edges
    print(len(graph_edges))

    sample_list = []
    for sample in graph_edges:
        road_a = Road('track_editor_C_center', looped=False)
        point1 = list(beamng_dict[sample[0]])
        point2 = list(beamng_dict[sample[1]])

        nodes0 = [
            (point1[0], point1[1], -4, 4),
            (point2[0], point2[1], -4, 4)
        ]

        road_a.nodes.extend(nodes0)
        scenario.add_road(road_a)

        sample_list.append(point1)
        sample_list.append(point2)
コード例 #13
0
def createBeamNGRoads():

    beamng = BeamNGpy('localhost',
                      64256,
                      home='F:\Softwares\BeamNG_Research_SVN')
    scenario = Scenario('GridMap', 'road_test')

    print(graph.edges)

    graph_edges = graph.edges
    print(len(graph_edges))

    sample_list = []
    for sample in graph_edges:
        road_a = Road('track_editor_C_center', looped=False)
        point1 = list(beamng_dict[sample[0]])
        point2 = list(beamng_dict[sample[1]])

        nodes0 = [(point1[0], point1[1], -4, 4), (point2[0], point2[1], -4, 4)]

        road_a.nodes.extend(nodes0)
        scenario.add_road(road_a)

        sample_list.append(point1)
        sample_list.append(point2)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()

        input('Press enter when done...')

    finally:
        bng.close()
コード例 #14
0
ファイル: roadTest.py プロジェクト: liflab/brpc2020
def main():


    beamng = BeamNGpy('localhost', 64256,getBeamngDirectory())

    scenario = Scenario('smallgrid', 'road_test')
    vehicle = Vehicle('LIF_Mobile', model='etkc', licence='LIFLAB', colour='Blue')
    ramp = StaticObject(name='pyramp', pos=(250,0, 0), rot=(0, 0, 90), scale=(0.5, 0.5, 0.5),
                        shape='/levels/west_coast_usa/art/shapes/objects/ramp_massive.dae')
    ring = ProceduralRing(name='pyring', pos=(380, 0, 60), rot=(0, 0, 0), radius=5, thickness=2.5)

    wall= StaticObject(name="trumps_wall",pos=(420,0,0),rot=(0,0,0), scale=(1,10,75),
                       shape='/levels/smallgrid/art/shapes/misc/gm_alpha_barrier.dae')
    road_c = Road('track_editor_B_center', rid='jump_road')
    roadC_Nodes=[(-2,0,0,10),(420,0,0,7)]
    road_c.nodes.extend(roadC_Nodes)
    scenario.add_road(road_c)



    scenario.add_procedural_mesh(ring)
    scenario.add_object(ramp)
    scenario.add_object(wall)

    scenario.add_vehicle(vehicle,(0,0,0),(0,0,-90))



    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        input('Press enter when done...')
    finally:
        bng.close()
コード例 #15
0
        with open(csv_file, 'a', encoding='utf-8') as csvfile:
            writer = csv.DictWriter(csvfile,
                                    fieldnames=csv_columns,
                                    delimiter=',',
                                    lineterminator='\n')
            writer.writerow(pos_crash_dict)
    except IOError:
        print("I/O error")


# -------------------------------------------------------------------------

beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN')
scenario = Scenario('GridMap', 'crash_simulation_2')

road_a = Road('custom_track_center', looped=False)

collision_point = []
three_way = []
# 3 Way intersection
for tup in graph_degree:
    three_way_coordinate = []

    if tup[1] == 3:
        three_way_coordinate.append(node_dict[tup[0]])
        three_way_points = graph.neighbors(tup[0])
        way_geo = (tup[0], node_dict[tup[0]], lane_dict[tup[0]],
                   width_dict[tup[0]])
        print(way_geo)
        print("collision point")
        print(beamng_dict[tup[0]])
コード例 #16
0
from BeamHome import getBeamngDirectory
import matplotlib
import numpy as np
import matplotlib.pyplot as plt

from matplotlib.pyplot import imshow
from PIL import Image
from shapely.geometry import Polygon

from beamngpy import BeamNGpy, Vehicle, Scenario, Road
from beamngpy.sensors import Camera
from getAIScript import getAIScript
beamng = BeamNGpy('localhost', 64256, getBeamngDirectory())

scenario = Scenario('smallgrid', 'vehicle_bbox_example')
road = Road('track_editor_A_center', rid='main_road')
orig = (0, -2, 0)
goal = (1150, -22, 0)
nodes = [(*orig, 7), (*goal, 7)]
road.nodes.extend(nodes)
scenario.add_road(road)

vehicle = Vehicle('ego_vehicle', model='etk800', licence='PYTHON')
overhead = Camera((0, -10, 5), (0, 1, -0.75), 60, (1024, 1024))
vehicle.attach_sensor('overhead', overhead)
scenario.add_vehicle(vehicle, pos=orig, rot=(0, 0, -90))

scenario.make(beamng)
bng = beamng.open(launch=True)
try:
    bng.load_scenario(scenario)
コード例 #17
0
def main():
    beamng = BeamNGpy('localhost',
                      64256,
                      home='F:\Softwares\BeamNG_Research_SVN')

    scenario = Scenario('GridMap', 'road_test')
    road_a = Road('custom_track_center', looped=False)
    nodes = [
        (0, 0, 0, 4),
        (0, 400, 0, 4),
    ]
    road_a.nodes.extend(nodes)
    scenario.add_road(road_a)

    vehicle = Vehicle('ego', model='etk800', licence='PYTHON', colour='Black')
    scenario.add_vehicle(vehicle, pos=(0, 0, 0.163609),
                         rot=(0, 0, 180))  # 0.163609 ,
    scenario.make(beamng)

    script = list()

    node0 = {
        'pos': (0, 0, 0.163609),
        'speed': 20,
    }

    node1 = {
        'pos': (0, 100, 0.163609),
        'speed': 30,
    }

    script.append(node0)
    script.append(node1)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        vehicle.ai_set_line(script)
        # update the state of vehicle at impact.

        for _ in range(100):
            time.sleep(0.1)
            vehicle.update_vehicle(
            )  # Synchs the vehicle's "state" variable with the simulator
            sensors = bng.poll_sensors(
                vehicle
            )  # Polls the data of all sensors attached to the vehicle
            print(vehicle.state['pos'])
            if vehicle.state['pos'][1] > 99:
                print('free state')
                vehicle.control(throttle=0,
                                steering=0,
                                brake=0,
                                parkingbrake=0)
                vehicle.update_vehicle()

        bng.stop_scenario()

        for _ in range(20):
            time.sleep(0.1)

        bng.load_scenario(scenario)
        bng.start_scenario()

        node0 = {
            'pos': (0, 50, 0.163609),
            'speed': 20,
        }

        node1 = {
            'pos': (0, 100, 0.163609),
            'speed': 30,
        }

        script.append(node0)
        script.append(node1)

        vehicle.ai_set_line(script)

        input('Press enter when done...')
    finally:
        bng.close()
コード例 #18
0
ファイル: DonutScenario.py プロジェクト: liflab/brpc2020
def getDonutScenario():
    beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory()
                      )  # This is the host & port used to communicate over
    donutScenario = Scenario('smallgrid', 'road_test')

    concreteWallSide1 = StaticObject(
        name="Crash_Test_Wall",
        pos=(20, 10, 0),
        rot=(0, 0, 0),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    concreteWallSide2 = StaticObject(
        name="Crash_Test_Wall2",
        pos=(35, -5, 0),
        rot=(0, 0, 90),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    concreteWallSide3 = StaticObject(
        name="Crash_Test_Wall3",
        pos=(20, -20, 0),
        rot=(0, 0, 0),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    concreteWallSide4 = StaticObject(
        name="Crash_Test_Wall4",
        pos=(5, -5, 0),
        rot=(0, 0, 90),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    testRoad = Road('track_editor_C_center', rid='Test_Road')
    roadNode = [(*(-25, 25, 0), 45), (*(15, 25, 0), 45)]
    testRoad.nodes.extend(roadNode)

    testVehicle = Vehicle('Test_Vehicule',
                          model='etkc',
                          licence='LIFLAB',
                          colour='Blue')

    # Create an Electrics sensor and attach it to the vehicle
    electrics = Electrics()
    testVehicle.attach_sensor('electrics', electrics)

    # Create a Damage sensor and attach it to the vehicle if module is selected
    damage = Damage()
    testVehicle.attach_sensor('damage', damage)

    # Create a Gforce sensor and attach it to the vehicle if module is selected
    gForce = GForces()
    testVehicle.attach_sensor('GForces', gForce)

    donutScenario.add_vehicle(testVehicle, pos=(20, 0, 0), rot=(0, 0, 0))

    donutScenario.add_object(concreteWallSide1)
    donutScenario.add_object(concreteWallSide2)
    donutScenario.add_object(concreteWallSide3)
    donutScenario.add_object(concreteWallSide4)

    donutScenario.add_road(testRoad)

    scenarioDict = {
        'beamng': beamng,
        'scenario': donutScenario,
        'vehicule': testVehicle
    }

    return scenarioDict
コード例 #19
0
import numpy as np
import matplotlib.pyplot as plt

from matplotlib.pyplot import imshow
from PIL import Image
from shapely.geometry import Polygon

from beamngpy import BeamNGpy, Vehicle, Scenario, Road
from beamngpy.sensors import Camera

beamng = BeamNGpy('localhost',
                  64256,
                  home='C:/Users/merie/Documents/BeamNG.research.v1.7.0.0')

scenario = Scenario('GridMap', 'vehicle_bbox_example')
road = Road('track_editor_C_center', rid='main_road', texture_length=5)
orig = (-107, 70, 0)
goal = (-300, 70, 0)
road.nodes = [
    (*orig, 7),
    (*goal, 7),
]
scenario.add_road(road)

vehicle = Vehicle('ego_vehicle', model='etk800', licence='PYTHON')
overhead = Camera((0, -10, 5), (0, 1, -0.75), 60, (1024, 1024))
vehicle.attach_sensor('overhead', overhead)
scenario.add_vehicle(vehicle, pos=orig)

scenario.make(beamng)
コード例 #20
0
ファイル: final.py プロジェクト: KarthikPradhan/userstory_sim
from fysom import *
from beamngpy import BeamNGpy, Scenario, Vehicle, log, StaticObject, Road

scenario = Scenario('GridMap', 'road_test')
road_a = Road('track_editor_C_center', rid=None, looped=False)
nodes = [
    (-25, 300, 0, 5),
    (25, 300, 0, 6),
    (25, 350, 0, 4),
    (-25, 350, 0, 5),
]
road_a.nodes.extend(nodes)
scenario.add_road(road_a)

# events_dict = [
#     {'name': 'come_in_front_of_the_AI', 'src': 'moving', 'dst': 'stopping'},
#     {'name': 'moves_far', 'src': 'stopping', 'dst': 'moving'}
# ]

events_dict = [{
    'name': 'appears_static_object',
    'src': 'moving',
    'dst': 'moving'
}, {
    'name': 'vehicle_1_comes_near',
    'src': 'moving',
    'dst': 'stopping'
}, {
    'name': 'vehicle_1_moves_far',
    'src': 'stopping',
    'dst': 'moving'
コード例 #21
0
def createCrashSimulation():
    print("Crash Simulation")

    beamng = BeamNGpy('localhost',
                      64256,
                      home='F:\Softwares\BeamNG_Research_SVN')
    scenario = Scenario('GridMap', 'road_crash_simulation')

    road_a = Road('track_editor_C_center', looped=False)
    road_b = Road('track_editor_C_center', looped=False)

    nodesa = [(30, 0, -4, 4), (0, 0, -4, 4)]

    nodesb = [(0, 30, -4, 4), (0, 0, -4, 4)]

    road_a.nodes.extend(nodesa)
    road_b.nodes.extend(nodesb)

    # Create an ETK800 with the licence plate 'PYTHON'
    vehicleA = Vehicle('ego_vehicleA', model='etk800', licence='PYTHON')
    # Add it to our scenario at this position and rotation

    damageS = Damage()
    vehicleA.attach_sensor('damagesS', damageS)

    scenario.add_vehicle(vehicleA, pos=(30, 0, 0), rot=(0, 0, 90))

    # Create an ETK800 with the licence plate 'PYTHON'
    vehicleB = Vehicle('ego_vehicleB', model='etk800', licence='PYTHON')
    # Add it to our scenario at this position and rotation

    damageV = Damage()
    vehicleB.attach_sensor('damagesV', damageV)

    scenario.add_vehicle(vehicleB, pos=(0, 30, 0), rot=(0, 0, 0))

    scenario.add_road(road_a)
    scenario.add_road(road_b)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()

        node0 = {
            'pos': (30, 0, 0),
            'speed': 0,
        }

        node1 = {
            'pos': (0, 0, 0),
            'speed': 20,
        }

        script = list()
        script.append(node0)
        script.append(node1)

        vehicleA.ai_set_line(script)

        node3 = {
            'pos': (0, 30, 0),
            'speed': 0,
        }

        node4 = {
            'pos': (0, 0, 0),
            'speed': 20,
        }

        script = list()
        script.append(node3)
        script.append(node4)

        vehicleB.ai_set_line(script)

        time.sleep(12)
        #       input('Press enter when done...')
        vehicleA.update_vehicle(
        )  # Synchs the vehicle's "state" variable with the simulator
        sensors = bng.poll_sensors(vehicleA)
        damage_striker = sensors['damagesS']
        print(sensors['damagesS'])
        print(vehicleA.state['pos'])

        vehicleB.update_vehicle(
        )  # Synchs the vehicle's "state" variable with the simulator
        sensors = bng.poll_sensors(vehicleB)
        damage_victim = sensors['damagesV']
        print(sensors['damagesV'])
        print(vehicleB.state['pos'])

        multiObjectiveFitnessFunction(123456789, damage_striker,
                                      vehicleA.state['pos'], (0, 0),
                                      damage_victim, vehicleB.state['pos'],
                                      (0, 0))
        # multiobjective fitness function.

        bng.stop_scenario()

        # bng.load_scenario(scenario)
        # bng.start_scenario()
        #
        # print("sleep")
        # time.sleep(10)
        # print("wake")
        #
        # node0 = {
        #     'pos': (30, 0, 0),
        #     'speed': 0,
        # }
        #
        # node1 = {
        #     'pos': (0, 0, 0),
        #     'speed': 30,
        # }
        #
        # script = list()
        # script.append(node0)
        # script.append(node1)
        #
        # vehicleA.ai_set_line(script)
        #
        # node0 = {
        #     'pos': (0, 30, 0),
        #     'speed': 0,
        # }
        #
        # node1 = {
        #     'pos': (0, 0, 0),
        #     'speed': 30,
        # }
        #
        # script = list()
        # script.append(node0)
        # script.append(node1)
        #
        # vehicleB.ai_set_line(script)
        #
        # input('Press enter when done...')

    finally:
        bng.close()
def IntersectionLaneMarking():

    print("Intersection Lane Marking")
    for tup in graph_degree:
        center = ''
        if tup[1] == 3:
            print(list(nx.dfs_edges(graph, source=tup[0], depth_limit=1)))
            way_3 = list(nx.dfs_edges(graph, source=tup[0], depth_limit=1))

            for sample in way_3:

                # Add end lane marking
                road_a = Road('track_editor_C_border', looped=False)
                road_b = Road('track_editor_C_border', looped=False)

                center = list(beamng_dict[sample[0]])
                point1 = list(beamng_dict[sample[1]])
                print(center)
                print(point1)
                # https://stackoverflow.com/questions/1250419/finding-points-on-a-line-with-a-given-distance
                road_width = 8/2 - 1
                real_distance = calculateDistance(center[0],center[1], point1[0], point1[1])

                t = road_width / real_distance

                point2 = (((1 - t) * center[0] + t * point1[0]), ((1 - t) * center[1] + t * point1[1]))
                print("new point")
                print(point2)

                # create new polylines and plot.
                lane_marking_points = getRoadEndLaneMarking(point1, point2, 4)

                nodes0 = [
                    (lane_marking_points[0], lane_marking_points[1], -0.05, 0.05),
                    (lane_marking_points[4], lane_marking_points[5], -0.05, 0.05)
                ]

                nodes1 = [
                    (lane_marking_points[2], lane_marking_points[3], -0.05, 0.05),
                    (lane_marking_points[6], lane_marking_points[7], -0.05, 0.05)
                ]

                road_a.nodes.extend(nodes0)
                road_b.nodes.extend(nodes1)
                scenario.add_road(road_a)
                scenario.add_road(road_b)


                # add asphalt roads
                road_c = Road('track_editor_C_center', looped=False)
                pointa = list(beamng_dict[sample[0]])
                pointb = list(beamng_dict[sample[1]])

                nodes0 = [
                    (pointa[0], pointa[1], -4, 4),
                    (pointb[0], pointb[1], -4, 4)
                ]

                road_c.nodes.extend(nodes0)
                scenario.add_road(road_c)

                # add middle lane marking

                lane_marking_points = getRoadLaneMarking(point1, point2, 8, 2)

                # for loop iterate to put polylines.

                for polyline in lane_marking_points:
                    print(polyline)
                    road_d = Road('track_editor_C_border', looped=False)

                    nodes0 = [
                        (polyline[0], polyline[1], -0.05, 0.05),
                        (polyline[2], polyline[3], -0.05, 0.05)
                    ]

                    road_d.nodes.extend(nodes0)
                    scenario.add_road(road_d)



    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()

        input('Press enter when done...')

    finally:
        bng.close()
コード例 #23
0
def createBeamNGRoads():

    beamng = BeamNGpy('localhost',
                      64256,
                      home='F:\Softwares\BeamNG_Research_SVN')
    scenario = Scenario('GridMap', 'road_test')

    print(graph.edges)

    graph_edges = graph.edges
    print(len(graph_edges))

    sample_list = []
    for sample in graph_edges:
        # road creation
        road_a = Road('track_editor_C_center', looped=False)
        point1 = list(beamng_dict[sample[0]])
        point2 = list(beamng_dict[sample[1]])

        nodes0 = [(point1[0], point1[1], -4, 4), (point2[0], point2[1], -4, 4)]

        road_a.nodes.extend(nodes0)
        scenario.add_road(road_a)

        sample_list.append(point1)
        sample_list.append(point2)

        # road edge lane marking

        road_b = Road('track_editor_C_border',
                      render_priority=10,
                      looped=False)
        road_c = Road('track_editor_C_border',
                      render_priority=10,
                      looped=False)

        point1 = list(beamng_dict[sample[0]])
        point2 = list(beamng_dict[sample[1]])

        lane_marking_points = getRoadEndLaneMarking(point1, point2, 4)

        nodes0 = [
            (lane_marking_points[0], lane_marking_points[1], -0.05, 0.05),
            (lane_marking_points[4], lane_marking_points[5], -0.05, 0.05)
        ]

        nodes1 = [
            (lane_marking_points[2], lane_marking_points[3], -0.05, 0.05),
            (lane_marking_points[6], lane_marking_points[7], -0.05, 0.05)
        ]

        road_b.nodes.extend(nodes0)
        road_c.nodes.extend(nodes1)
        scenario.add_road(road_b)
        scenario.add_road(road_c)

        # road lane marking

        lane_marking_points = getRoadLaneMarking(point1, point2, 10, 3)

        # for loop iterate to put polylines.

        for polyline in lane_marking_points:
            #print(polyline)
            road_d = Road('track_editor_C_border',
                          render_priority=10,
                          looped=False)

            nodes0 = [(polyline[0], polyline[1], -0.05, 0.05),
                      (polyline[2], polyline[3], -0.05, 0.05)]

            road_d.nodes.extend(nodes0)
            scenario.add_road(road_d)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()

        input('Press enter when done...')

    finally:
        bng.close()
コード例 #24
0
def main() -> None:
    # Read CommonRoad scenario
    cr_scenario, cr_planning_problem_set = CommonRoadFileReader(cr_scenario_path) \
        .open()
    if cr_planning_problem_set:
        for _, pp in cr_planning_problem_set.planning_problem_dict.items():
            cr_planning_problem = pp
            break  # Read only the first one
    else:
        raise Exception(
            "The given CommonRoad scenario does not define a planning problem."
        )

    # Setup BeamNG
    bng = BeamNGpy('localhost', 64256, home=home_path, user=user_path)
    bng_scenario = Scenario(
        bng_scenario_environment,
        bng_scenario_name,
        authors='Stefan Huber',
        description='Simple visualization of the CommonRoad scenario ' +
        cr_scenario_name)

    # Add lane network
    lanes = cr_scenario.lanelet_network.lanelets
    for lane in lanes:
        lane_nodes = []
        for center in lane.center_vertices:
            lane_nodes.append((center[0], center[1], 0,
                               4))  # FIXME Determine appropriate width
        road = Road(cr_road_material)
        road.nodes.extend(lane_nodes)
        bng_scenario.add_road(road)

    # Add ego vehicle
    ego_vehicle = Vehicle('ego_vehicle',
                          model='etk800',
                          licence='EGO',
                          color='Cornflowerblue')
    ego_init_state = cr_planning_problem.initial_state
    ego_init_state.position[0] = 82.8235
    ego_init_state.position[1] = 31.5786
    add_vehicle_to_bng_scenario(bng_scenario, ego_vehicle, ego_init_state,
                                etk800_z_offset)

    obstacles_to_move = dict()

    # Add truck
    semi = Vehicle('truck', model='semi', color='Red')
    semi_init_state = cr_scenario.obstacle_by_id(206).initial_state
    add_vehicle_to_bng_scenario(bng_scenario, semi, semi_init_state,
                                semi_z_offset)
    obstacles_to_move[206] = semi

    # Add truck trailer
    tanker_init_state = copy(semi_init_state)
    tanker_init_state.position += [6, 3]
    add_vehicle_to_bng_scenario(
        bng_scenario, Vehicle('truck_trailer', model='tanker', color='Red'),
        tanker_init_state, tanker_z_offset)

    # Add other traffic participant
    opponent = Vehicle('opponent',
                       model='etk800',
                       licence='VS',
                       color='Cornflowerblue')
    add_vehicle_to_bng_scenario(bng_scenario, opponent,
                                cr_scenario.obstacle_by_id(207).initial_state,
                                etk800_z_offset)
    obstacles_to_move[207] = opponent

    # Add static obstacle
    obstacle_shape: Polygon = cr_scenario.obstacle_by_id(399).obstacle_shape
    obstacle_pos = obstacle_shape.center
    obstacle_rot_deg = rad2deg(semi_init_state.orientation) + rot_offset
    obstacle_rot_rad = semi_init_state.orientation + deg2rad(rot_offset)
    for w in range(3):
        for h in range(3):
            for d in range(2):
                obstacle = Vehicle('obstacle' + str(w) + str(h) + str(d),
                                   model='haybale',
                                   color='Red')
                haybale_pos_diff = obstacle_pos \
                    + pol2cart(1.3 * d, obstacle_rot_rad + pi / 4) \
                    + pol2cart(2.2 * w, pi / 2 - obstacle_rot_rad)
                bng_scenario.add_vehicle(obstacle,
                                         pos=(haybale_pos_diff[0],
                                              haybale_pos_diff[1], h * 1),
                                         rot=(0, 0, obstacle_rot_deg))

    bng_scenario.make(bng)

    # Manually set the overObjects attribute of all roads to True (Setting this option is currently not supported)
    prefab_path = os.path.join(user_path, 'levels', bng_scenario_environment,
                               'scenarios', bng_scenario_name + '.prefab')
    lines = open(prefab_path, 'r').readlines()
    for i in range(len(lines)):
        if 'overObjects' in lines[i]:
            lines[i] = lines[i].replace('0', '1')
    open(prefab_path, 'w').writelines(lines)

    # Start simulation
    bng.open(launch=True)
    try:
        bng.load_scenario(bng_scenario)
        bng.start_scenario()
        bng.pause()

        bng.display_gui_message(
            "The scenario is fully prepared and paused. You may like to position the camera first."
        )
        delay_to_resume = 15
        input("Press enter to continue the simulation... You have " +
              str(delay_to_resume) +
              " seconds to switch back to the BeamNG window.")
        sleep(delay_to_resume)
        bng.resume()

        for id, obstacle in obstacles_to_move.items():
            obstacle.ai_drive_in_lane(False)
            obstacle.ai_set_line(
                generate_node_list(cr_scenario.obstacle_by_id(id)))

        ego_vehicle.ai_drive_in_lane(False)
        # ego_vehicle.ai_set_speed(cr_planning_problem.initial_state.velocity * 3.6, mode='limit')
        speed = 65 / 3.6
        ego_vehicle.ai_set_line([{
            'pos': ego_vehicle.state['pos']
        }, {
            'pos': (129.739, 56.907, etk800_z_offset),
            'speed': speed
        }, {
            'pos': (139.4, 62.3211, etk800_z_offset),
            'speed': speed
        }, {
            'pos': (149.442, 64.3655, etk800_z_offset),
            'speed': speed
        }, {
            'pos': (150.168, 63.3065, etk800_z_offset),
            'speed': speed
        }, {
            'pos': (188.495, 78.8517, etk800_z_offset),
            'speed': speed
        }])
        # FIXME Setting the speed does not work as expected
        # ego_vehicle.ai_set_speed(cr_planning_problem.initial_state.velocity * 3.6, mode='set')

        input("Press enter to end simulation...")
    finally:
        bng.close()
コード例 #25
0
    print(actual_striker_damage)
    print(actual_victim_damage)
    print(crash_fitness_function)
    print(distance_fitness_function)
    print(rotation_fitness_function)

# --------------------------------------------------------------------------

# beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN')
# scenario = Scenario('GridMap', 'crash_simulation_1')
setup_logging()
beamng = BeamNGpy('127.0.0.1', 64256, home=os.getenv('BNG_HOME'))
scenario = Scenario('smallgrid', 'crash_simulation_1')

road_a = Road('track_editor_C_center', looped=False)

collision_point =[]
four_way = []

# 4 Way intersection
for tup in graph_degree:
    four_way_coordinate = []

    if tup[1] == 4:
        print(tup[0],tup[1])
        four_way_coordinate.append(node_dict[tup[0]])
        four_way_points = graph.neighbors(tup[0])
        #print(four_way_points)
        print("collision point")
        print(beamng_dict[tup[0]])
コード例 #26
0
setup_logging()

bng = BeamNGpy('localhost', 64256)

scenario = Scenario('smallgrid', 'small_test')

vehicle = Vehicle('egovehicle', model='etk800', licence='313')

scenario.add_vehicle(vehicle, pos=(-1.5, -1, 0), rot=(0, 0, 0))

nodes = [(0, 0, 0, 6), (0, -20, 0, 6), (0, -100, 0, 6), (-25, -200, 0, 6),
         (25, -300, 0, 6)]

road = Road(material='a_asphalt_01_a',
            rid='main_road',
            looped=False,
            texture_length=10)
road.nodes.extend(nodes)
scenario.add_road(road)

scenario.make(bng)

for i, line in enumerate(fileinput.input(scenario.get_prefab_path(),
                                         inplace=1)):
    sys.stdout.write(line.replace('overObjects = "0";', 'overObjects = "1";'))

bng.open()
bng.load_scenario(scenario)
bng.start_scenario()
bng.set_deterministic()
bng.pause()
コード例 #27
0
def GenerateTrack(trackLength, sampleRate, show, startBeamNG):  
    populationSize = 100
    maxAcc = 1
   
    times = 20
    relNewSize = 0.6

    duplicatesThreshold = 0.05
    intersectionDelta = 0.01

    mutationProb = 0.1
    mutationDeviation = 0.01

    print("Generating Tracks")

    pop = initPop(populationSize, trackLength, maxAcc, 20)

    pop = evolve(pop, times, relNewSize, duplicatesThreshold,
           intersectionDelta, mutationProb, mutationDeviation, 10)

    print("eliminating intersecting tracks")    
    pop = elminateIntersecting(pop, intersectionDelta)

    if show:
        plotTrack(pop, 100)

    tracks = []

    nr = 0    

    first = True

    for track in pop:
        track = np.vstack((track, completeAcc(track)))
        poly = polysFromAccs(track)
        bez = bezFromPolys(poly)
        smpl = sampleBezSeries(bez, sampleRate).transpose()
        smpl = scaleTrack(smpl, 100, 100)
        smpl = np.array(smpl)
        smpl = np.vstack((smpl, [smpl[0]]))

        if(first):
            writeCriteria(smpl)
            first = False

        tracks.append(smpl)
        writeTrack(smpl, nr)
        nr += 1


    if startBeamNG:   
        nodes = []
        for p in tracks[0]: nodes.append((p[0], p[1], 0, 7))

        beamng = BeamNGpy('localhost', 64256)
        vehicle = Vehicle('ego', model='etk800', licence='PYTHON', colour='Green')
        scenario = Scenario('GridMap_v0422', 'track test')
        scenario.add_vehicle(vehicle, pos=(0, 0, -16.64), rot=(0, 0, 180))
        road = Road(material='track_editor_C_center', rid='main_road', texture_length=5, looped=True)

        road.nodes.extend(nodes)
        scenario.add_road(road)
        scenario.make(beamng)

        beamng.open()
        beamng.load_scenario(scenario)
        beamng.start_scenario()
        vehicle.ai_set_mode('span')

        while 1:
            vehicle.update_vehicle()
            print(vehicle.state['pos'])
            sleep(1)