Exemple #1
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:
    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:
            
    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'])    
    
    dist = 0.1
    status = -1
    totaldist = 0
    while status < 1 and totaldist < 50:
        lane,lanepos,pos,angle = Sim.getVehicleState(road)
        status = 1*(lane[1]=='o' and lanepos > 5.) - 1*(lane[1]=='i' and len(lane)==4)
Exemple #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()
 ## 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
             if addThisCar:
                 Sim.createVehicle(str(carID), car['lane'], 0.)
                 cars.loc[carID,'status'] = 0
     
     # gather vehicle info
     for carID in np.where(cars['status']==0)[0]:        
         carLane,carLanePos,carPos,carAngle = Sim.getVehicleState(str(carID))
         
         if carLane == '':
             print '!!!! lane is empty'+ str(carID) + cars.loc[carID,'lane']
             carLane = cars.loc[carID,'lane']
             carLanePos = 0.0
             carPos = (-6.*carID,-6.*carID)
             carAngle = 0.
         elif carLane is None:
             print '!!!! lane is none '+ str(carID)
             cars.loc[carID,'status']=1
Exemple #6
0
    ## 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
                if addThisCar:
                    Sim.createVehicle(str(carID), car['lane'], 0.)
                    cars.loc[carID, 'status'] = 0

        # gather vehicle info
        for carID in np.where(cars['status'] == 0)[0]:
            carLane, carLanePos, carPos, carAngle = Sim.getVehicleState(
                str(carID))

            if carLane == '':
                print '!!!! lane is empty' + str(carID) + cars.loc[carID,
                                                                   'lane']
                carLane = cars.loc[carID, 'lane']
                carLanePos = 0.0
                carPos = (-6. * carID, -6. * carID)
                carAngle = 0.
            elif carLane is None:
    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'])

    dist = 0.1
    status = -1
    totaldist = 0
    while status < 1 and totaldist < 50:
        lane, lanepos, pos, angle = Sim.getVehicleState(road)
        status = 1 * (lane[1] == 'o' and