Example #1
0
from subprocess import call as terminalCall
if os.name == 'posix':  # unix
    terminalCall(['mkdir', '-p', os.path.realpath(outputFolder)])
else:
    terminalCall(['mkdir', os.path.realpath(outputFolder)], shell=True)

import pandas as pd
params = pd.read_csv(parametersFile)

# setup
roads = {
    'main': (0., 2., 1300., 2.),
    'oncoming': (1300., 5.2, 0., 5.2),
    'overtaking': (0., 5.2, 1300., 5.2)
}
roadMap = RoadMap(roads, [])


class Output:
    def __init__(self, colnames):
        self.df = None
        self.colnames = colnames

    def add(self, newrow):
        if self.df is None:
            self.df = pd.DataFrame([newrow])
        else:
            self.df = self.df.append([newrow])

    def write(self, fileName, restart=False):
        self.df.columns = self.colnames
         '2o_1':(108, 98.35, 200, 98.35),
         '1o_0':(92, 105, 0, 105),
         '1o_1':(92, 101.65, 0, 101.65),
         '4o_0':(105, 108, 105, 200),
         '4o_1':(101.65, 108, 101.65, 200),
         '3o_0':(95, 92, 95, 0),
         '3o_1':(98.35, 92, 98.35, 0)}
intersections   =    [['1i_0','3o_0'] , #['1i_0','2o_1'] ,
                      ['1i_0','2o_0'] , ['1i_1','4o_1'] ,
                      ['2i_0','4o_0'] , #['2i_0','1o_1'] ,
                      ['2i_0','1o_0'] , ['2i_1','3o_1'] ,
                      ['3i_0','2o_0'] , #['3i_0','4o_1'] ,
                      ['3i_0','4o_0'] , ['3i_1','1o_1'] ,
                      ['4i_0','1o_0'] , #['4i_0','3o_1'] ,
                      ['4i_0','3o_0'] , ['4i_1','2o_1'] ]  
roadMap = RoadMap(roads, intersections)
roadOrder = pd.DataFrame({'left':[4,3,1,2],'right':[3,4,2,1],
                          'straight':[2,1,4,3]},index=[1,2,3,4])
                          
def combineRoad(inroad, outroad):
    if any(list(inroad==i and outroad==j for i,j in intersections)):
        return inroad + '_' + outroad
    return None
    
class WriteFrame: # makes repeatedly adding to data frame easier
    def __init__(self, colnames=None):
        self.colnames = colnames
        self.restart=True
    def add(self, newrows):
        if self.restart:
            self.df = pd.DataFrame(newrows)
Example #3
0
    '2o_1': (108, 98.35, 200, 98.35),
    '1o_0': (92, 105, 0, 105),
    '1o_1': (92, 101.65, 0, 101.65),
    '4o_0': (105, 108, 105, 200),
    '4o_1': (101.65, 108, 101.65, 200),
    '3o_0': (95, 92, 95, 0),
    '3o_1': (98.35, 92, 98.35, 0)
}

# which roads connect to other roads
intersections = [['1i_0', '3o_0'], ['1i_0', '2o_0'], ['1i_1', '4o_1'],
                 ['2i_0', '4o_0'], ['2i_0', '1o_0'], ['2i_1', '3o_1'],
                 ['3i_0', '2o_0'], ['3i_0', '4o_0'], ['3i_1', '1o_1'],
                 ['4i_0', '1o_0'], ['4i_0', '3o_0'], ['4i_1', '2o_1']]

roadMap = RoadMap(roads, intersections)

Sim = Simulator(roadMap, gui=GUI, delay=SIMDELAY)
Sim.createVehicle('mycar', '1i_0', 50.)

Sim.moveVehicle('mycar', '1i_1', 50.)
for k in range(20):
    exited = Sim.moveVehicleAlong('mycar', 5., '4o_1')

    carLane, carLanePos, carPos, carAngle = Sim.getVehicleState('mycar')
    print carPos

    manual_escape = Sim.updateGUI(allowPause=True)
    if exited or manual_escape:
        break
Example #4
0
         '2o_1':(108, 98.35, 200, 98.35),
         '1o_0':(92, 105, 0, 105),
         '1o_1':(92, 101.65, 0, 101.65),
         '4o_0':(105, 108, 105, 200),
         '4o_1':(101.65, 108, 101.65, 200),
         '3o_0':(95, 92, 95, 0),
         '3o_1':(98.35, 92, 98.35, 0)}
intersections   =    [['1i_0','3o_0'] , #['1i_0','2o_1'] ,
                      ['1i_0','2o_0'] , ['1i_1','4o_1'] ,
                      ['2i_0','4o_0'] , #['2i_0','1o_1'] ,
                      ['2i_0','1o_0'] , ['2i_1','3o_1'] ,
                      ['3i_0','2o_0'] , #['3i_0','4o_1'] ,
                      ['3i_0','4o_0'] , ['3i_1','1o_1'] ,
                      ['4i_0','1o_0'] , #['4i_0','3o_1'] ,
                      ['4i_0','3o_0'] , ['4i_1','2o_1'] ]  
roadMap = RoadMap(roads, intersections)

#intersectionInfo = pd.read_csv('collisionsFile_OwnSim.csv',header=0)
intersectionInfo = pd.read_csv('collisionsFile_Quad.csv',header=0) 
   
def splitRoad(lane):
    if len(lane)==9: # internal lane for intersection
        #inroute,ingrade,inlane = splitRoad(lane[:4])
        return [lane[:4], 1, lane[5:]]
    elif len(lane)==4: # starting or ending road
        if lane[1] == 'i':
            grade = 0
        elif lane[1] == 'o':
            grade = 2
    return [int(lane[0]), grade, int(lane[3])]
    
Example #5
0
}
intersections = [
    ['1i_0', '3o_0'],  #['1i_0','2o_1'] ,
    ['1i_0', '2o_0'],
    ['1i_1', '4o_1'],
    ['2i_0', '4o_0'],  #['2i_0','1o_1'] ,
    ['2i_0', '1o_0'],
    ['2i_1', '3o_1'],
    ['3i_0', '2o_0'],  #['3i_0','4o_1'] ,
    ['3i_0', '4o_0'],
    ['3i_1', '1o_1'],
    ['4i_0', '1o_0'],  #['4i_0','3o_1'] ,
    ['4i_0', '3o_0'],
    ['4i_1', '2o_1']
]
roadMap = RoadMap(roads, intersections)

#intersectionInfo = pd.read_csv('collisionsFile_OwnSim.csv',header=0)
intersectionInfo = pd.read_csv('collisionsFile_Quad.csv', header=0)


def splitRoad(lane):
    if len(lane) == 9:  # internal lane for intersection
        #inroute,ingrade,inlane = splitRoad(lane[:4])
        return [lane[:4], 1, lane[5:]]
    elif len(lane) == 4:  # starting or ending road
        if lane[1] == 'i':
            grade = 0
        elif lane[1] == 'o':
            grade = 2
    return [int(lane[0]), grade, int(lane[3])]
Example #6
0
}
intersections = [
    ['1i_0', '3o_0'],  #['1i_0','2o_1'] ,
    ['1i_0', '2o_0'],
    ['1i_1', '4o_1'],
    ['2i_0', '4o_0'],  #['2i_0','1o_1'] ,
    ['2i_0', '1o_0'],
    ['2i_1', '3o_1'],
    ['3i_0', '2o_0'],  #['3i_0','4o_1'] ,
    ['3i_0', '4o_0'],
    ['3i_1', '1o_1'],
    ['4i_0', '1o_0'],  #['4i_0','3o_1'] ,
    ['4i_0', '3o_0'],
    ['4i_1', '2o_1']
]
roadMap = RoadMap(roads, intersections)
roadOrder = pd.DataFrame(
    {
        'left': [4, 3, 1, 2],
        'right': [3, 4, 2, 1],
        'straight': [2, 1, 4, 3]
    },
    index=[1, 2, 3, 4])


def combineRoad(inroad, outroad):
    if any(list(inroad == i and outroad == j for i, j in intersections)):
        return inroad + '_' + outroad
    return None