Ejemplo n.º 1
0
 # save current information        
 passlane, lp, passPosition, passAngle = sim.getVehicleState('Passing')
 lane, lp, leadPosition, leadAngle = sim.getVehicleState('Lead')
 lane, lp, oncomPosition, oncomAngle = sim.getVehicleState('Oncoming')
 output.add([time, 'Passing', passPosition[0], passPosition[1],
                 passAngle, vPass, currentAccPass])
 output.add([time, 'Lead', leadPosition[0], leadPosition[1],
                 leadAngle, vLead, accLead])
 output.add([time, 'Oncoming', oncomPosition[0], oncomPosition[1],
                 oncomAngle, vOncom, accOncom])
 
 # switch lanes
 leadHeadway = calcHeadway(passPosition[0]-leadPosition[0]-5.8, vLead,
                           accLead)
 if time > parameters['tpr'] and passlane=='main' and overtakeNotComplete:
     sim.moveVehicle('Passing','overtaking')
 if passlane=='overtaking' and leadHeadway >= 1.:
         sim.moveVehicle('Passing','main')
         overtakeNotComplete = False
 # move vehicles
 vehicleLeft = 0
 vehicleLeft += sim.moveVehicleAlong('Passing', vPass*DT+currentAccPass/2*DT*DT)
 vehicleLeft += sim.moveVehicleAlong('Lead', vLead*DT+accLead/2*DT*DT)
 vehicleLeft += sim.moveVehicleAlong('Oncoming', vOncom*DT+accOncom/2*DT*DT)
 vPass += currentAccPass*DT
 vLead += accLead*DT
 vOncom += accOncom*DT
 
 time += DT
 sim.updateGUI()
 continueSim &= vehicleLeft == 0 # at least one vehicle exits sim
Ejemplo n.º 2
0
        ])
        output.add([
            time, 'Lead', leadPosition[0], leadPosition[1], leadAngle, vLead,
            accLead
        ])
        output.add([
            time, 'Oncoming', oncomPosition[0], oncomPosition[1], oncomAngle,
            vOncom, accOncom
        ])

        # switch lanes
        leadHeadway = calcHeadway(passPosition[0] - leadPosition[0] - 5.8,
                                  vLead, accLead)
        if time > parameters[
                'tpr'] and passlane == 'main' and overtakeNotComplete:
            sim.moveVehicle('Passing', 'overtaking')
        if passlane == 'overtaking' and leadHeadway >= 1.:
            sim.moveVehicle('Passing', 'main')
            overtakeNotComplete = False
        # move vehicles
        vehicleLeft = 0
        vehicleLeft += sim.moveVehicleAlong(
            'Passing', vPass * DT + currentAccPass / 2 * DT * DT)
        vehicleLeft += sim.moveVehicleAlong('Lead',
                                            vLead * DT + accLead / 2 * DT * DT)
        vehicleLeft += sim.moveVehicleAlong(
            'Oncoming', vOncom * DT + accOncom / 2 * DT * DT)
        vPass += currentAccPass * DT
        vLead += accLead * DT
        vOncom += accOncom * DT
Ejemplo n.º 3
0
#                    if offset - maxChange < -3.35/2.: # crossed on 1: lane 2 speed 0 turnto left lane
#                        newlane = makeRoad(route, grade, 1)
#                        newoffset = offset - maxChange + 3.35
#                        cars.loc[carID,'lanechanged'] = 0
#                if not newlane is None:
#                    Sim.moveVehicle(str(carID), newlane, car['lanepos'], offset=newoffset)
#                    cars.loc[carID,'lane'] = newlane
#                cars.loc[carID,'changex'] = car['x']
#                cars.loc[carID,'changey'] = car['y']
#                cars.loc[carID,'changeangle'] = car['angle']
#            else:
#                #cars.loc[carID,'lanechanged'] = 0
#                # head towards center of lane
#                Sim.offsetVehicle(str(carID), min(max(-offset, -maxChange),maxChange))
            if laneChange == 1 and ln == 1:
                Sim.moveVehicle(str(carID), makeRoad(route, grade, 0))
            elif laneChange == 0 and ln == 0:
                Sim.moveVehicle(str(carID), makeRoad(route, grade, 1))
                
                
            speedChange = [0,-10.,10.][int(speedChange)]/MS2KPH            
            cars.loc[carID,'speed'] = min(max(car['speed']+speedChange, 0.),60./MS2KPH)
            distance = car['speed']*DELTAT
            
            # the vehicle is about to make a transition to a new roa   
            exited = Sim.moveVehicleAlong(str(carID), distance, turn)
            if exited: # car leaving simulation
                Sim.removeVehicle(str(carID))
                cars.loc[carID,'status'] = 1
                WrongPath = WrongPath + int(route != splitRoad(car['dest'])[0])
        
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
            #                    if offset - maxChange < -3.35/2.: # crossed on 1: lane 2 speed 0 turnto left lane
            #                        newlane = makeRoad(route, grade, 1)
            #                        newoffset = offset - maxChange + 3.35
            #                        cars.loc[carID,'lanechanged'] = 0
            #                if not newlane is None:
            #                    Sim.moveVehicle(str(carID), newlane, car['lanepos'], offset=newoffset)
            #                    cars.loc[carID,'lane'] = newlane
            #                cars.loc[carID,'changex'] = car['x']
            #                cars.loc[carID,'changey'] = car['y']
            #                cars.loc[carID,'changeangle'] = car['angle']
            #            else:
            #                #cars.loc[carID,'lanechanged'] = 0
            #                # head towards center of lane
            #                Sim.offsetVehicle(str(carID), min(max(-offset, -maxChange),maxChange))
            if laneChange == 1 and ln == 1:
                Sim.moveVehicle(str(carID), makeRoad(route, grade, 0))
            elif laneChange == 0 and ln == 0:
                Sim.moveVehicle(str(carID), makeRoad(route, grade, 1))

            speedChange = [0, -10., 10.][int(speedChange)] / MS2KPH
            cars.loc[carID, 'speed'] = min(max(car['speed'] + speedChange, 0.),
                                           60. / MS2KPH)
            distance = car['speed'] * DELTAT

            # the vehicle is about to make a transition to a new roa
            exited = Sim.moveVehicleAlong(str(carID), distance, turn)
            if exited:  # car leaving simulation
                Sim.removeVehicle(str(carID))
                cars.loc[carID, 'status'] = 1
                WrongPath = WrongPath + int(route != splitRoad(car['dest'])[0])