Ejemplo n.º 1
0
    if speed < 0 and accel < 0:
        return 100
    if accel == 0:
        return distance / speed
    discrim = (speed**2 + 2 * accel * distance)
    if discrim < 0:
        return 100
    return (discrim**.5 - speed) / accel


DT = 0.1

# simulations
for simIndex in range(numsims):
    parameters = params.iloc[simIndex]
    sim = Simulator(roadMap, gui=False, delay=0., waitOnStart=True)
    sim.createVehicle('Passing', 'main', parameters['Passing Position'])
    sim.createVehicle('Lead', 'main', parameters['Lead Position'])
    sim.createVehicle('Oncoming', 'oncoming', parameters['Oncoming Position'])

    time = 0
    continueSim = True
    overtakeNotComplete = True
    vPass = parameters['Passing Speed']
    vLead = parameters['Lead Speed']
    vOncom = parameters['Oncoming Speed']
    accPass = parameters['Passing Acceleration']
    accLead = parameters['Lead Acceleration']
    accOncom = parameters['Oncoming Acceleration']

    while continueSim:
Ejemplo n.º 2
0
        return -1
    if speed < 0 and accel < 0:
        return 100
    if accel == 0:
        return distance / speed
    discrim = (speed**2 + 2*accel*distance)
    if discrim < 0:
        return 100
    return (discrim**.5 - speed) / accel

DT = 0.1

# simulations
for simIndex in range(numsims):
    parameters = params.iloc[simIndex]
    sim = Simulator(roadMap, gui = False, delay=0., waitOnStart = True)
    sim.createVehicle('Passing','main',parameters['Passing Position'])
    sim.createVehicle('Lead','main',parameters['Lead Position'])
    sim.createVehicle('Oncoming','oncoming',parameters['Oncoming Position'])
    
    time = 0
    continueSim = True
    overtakeNotComplete = True
    vPass = parameters['Passing Speed']
    vLead = parameters['Lead Speed']
    vOncom = parameters['Oncoming Speed']
    accPass = parameters['Passing Acceleration']
    accLead = parameters['Lead Acceleration']
    accOncom = parameters['Oncoming Acceleration']

    while continueSim:
        self.restart=True
    def add(self, newrows):
        if self.restart:
            self.df = pd.DataFrame(newrows)
            self.restart=False
        else:
            self.df = self.df.append(newrows, ignore_index = True)
    def out(self):
        if self.colnames is not None:
            self.df.columns =  self.colnames
        #self.df.to_csv(fileName, sep=',', header=True, index=False)
        self.restart=True
        return self.df
    
    
Sim = Simulator(roadMap, gui=False, delay = 0.)

# first gather the possible positions/angles of each intersection lane
allcars = {}
for start, end in intersections:
    road = combineRoad(start, end)
    print "at "+road
    Sim.createVehicle(road, start, 90.)

    turn = 0
    if roadOrder.loc[int(start[0]),'left'] == int(end[0]):
        turn = 2
    elif roadOrder.loc[int(start[0]),'right'] == int(end[0]):
        turn = 1
    
    thisdf = WriteFrame(['x','y','angle','length','width','lp'])    
Ejemplo n.º 4
0
    '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

Sim.end()
Ejemplo n.º 5
0
    cars['angle'] = [-1]*ncars
    cars['ilane'] = ['']*ncars
    cars['lanechanged'] = [0]*ncars
    cars['changex'] = [0]*ncars
    cars['changey'] = [0]*ncars
    cars['changeangle'] = [0]*ncars

    collisionCount = 0
    TotReward = 0
    WrongPath = 0
    ttime = 0
    maxTime = 100 # seconds
    prevIndices = {}
       
    # start simulator
    Sim = Simulator(roadMap, gui = GUI, delay = SIMDELAY)    

    ## run simulation
    while ttime < maxTime and np.any(cars['status']<=0):
        
        # create new vehicles
        for carID in np.where(cars['status']<0)[0]:
            car = cars.iloc[carID]
            if car['time'] <= ttime:
                # search through lane and see if another vehicle is taking the spot
                otherCars = (cars['status'] == 0) | (cars['status'] >= 2)
                addThisCar = True
                for otherID in np.where(otherCars)[0]:
                    if cars['lane'].iloc[otherID] == car['lane']:
                        if cars['lanepos'].iloc[otherID] <= 10.:
                            addThisCar = False
Ejemplo n.º 6
0
    cars['angle'] = [-1] * ncars
    cars['ilane'] = [''] * ncars
    cars['lanechanged'] = [0] * ncars
    cars['changex'] = [0] * ncars
    cars['changey'] = [0] * ncars
    cars['changeangle'] = [0] * ncars

    collisionCount = 0
    TotReward = 0
    WrongPath = 0
    ttime = 0
    maxTime = 100  # seconds
    prevIndices = {}

    # start simulator
    Sim = Simulator(roadMap, gui=GUI, delay=SIMDELAY)

    ## run simulation
    while ttime < maxTime and np.any(cars['status'] <= 0):

        # create new vehicles
        for carID in np.where(cars['status'] < 0)[0]:
            car = cars.iloc[carID]
            if car['time'] <= ttime:
                # search through lane and see if another vehicle is taking the spot
                otherCars = (cars['status'] == 0) | (cars['status'] >= 2)
                addThisCar = True
                for otherID in np.where(otherCars)[0]:
                    if cars['lane'].iloc[otherID] == car['lane']:
                        if cars['lanepos'].iloc[otherID] <= 10.:
                            addThisCar = False
Ejemplo n.º 7
0
    def add(self, newrows):
        if self.restart:
            self.df = pd.DataFrame(newrows)
            self.restart = False
        else:
            self.df = self.df.append(newrows, ignore_index=True)

    def out(self):
        if self.colnames is not None:
            self.df.columns = self.colnames
        #self.df.to_csv(fileName, sep=',', header=True, index=False)
        self.restart = True
        return self.df


Sim = Simulator(roadMap, gui=False, delay=0.)

# first gather the possible positions/angles of each intersection lane
allcars = {}
for start, end in intersections:
    road = combineRoad(start, end)
    print "at " + road
    Sim.createVehicle(road, start, 90.)

    turn = 0
    if roadOrder.loc[int(start[0]), 'left'] == int(end[0]):
        turn = 2
    elif roadOrder.loc[int(start[0]), 'right'] == int(end[0]):
        turn = 1

    thisdf = WriteFrame(['x', 'y', 'angle', 'length', 'width', 'lp'])