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)
        if lane[1]=='o': # must be included since back of vehicle
                lanepos = lanepos + roadMap.getLength(road)
        if status==0:  # add vehicle info to the dataframe
            thisdf.add([[pos[0],pos[1],angle,VEHsize[0],VEHsize[1],lanepos]])
        Sim.moveVehicleAlong(road, dist, turn)
        totaldist += dist
        Sim.updateGUI()
        
    allcars[road] = thisdf.out()
    Sim.removeVehicle(road)
Sim.end(waitOnEnd = False)

for car in allcars.itervalues():
    car['angle'] = car['angle'] + 1.5708
#
## now use dataframes of position+angle to find collision points
#collisions = WriteFrame(['lane','lane2','begin_lp','end_lp'])
#for an in range(len(intersections)):
#    for bn in range(an):
#        print "checking "+str(an)+", "+str(bn)
#        starta,enda = intersections[an]
#        startb,endb = intersections[bn]
#        roada = combineRoad(starta,enda)
#        roadb = combineRoad(startb,endb)
#        cara = allcars[roada]
Esempio n. 2
0
                    carLane) == 4:  # not in intersection yet
                destlane = cars.loc[carID, 'dest']
                destlane = destlane[:3] + carLane[3:]
                cars.loc[carID,
                         'ilane'] = roadMap.combineRoad(carLane, destlane)
            elif len(carLane) == 4:
                cars.loc[carID, 'ilane'] = carLane
            else:
                cars.loc[carID, 'ilane'] = carLane

        # cars that collided last time are now completely removed
        carsThatCollidedLastStep = np.where(cars['status'] >= 2)[0]
        for carID in carsThatCollidedLastStep:

            cars.loc[carID, 'status'] = 1
            Sim.removeVehicle(str(carID))

        # check for collisions
        activeCars = np.where(cars['status'] == 0)[0]
        for carNum in range(len(activeCars)):
            carID = activeCars[carNum]
            car = cars.iloc[carID]
            for altNum in range(carNum):
                altID = activeCars[altNum]
                alt = cars.iloc[altID]
                carObject = pd.Series(
                    [car['x'], car['y'], car['angle'], VEHsize[0], VEHsize[1]],
                    index=collisionCheck.collisionVars)
                altObject = pd.Series(
                    [alt['x'], alt['y'], alt['angle'], VEHsize[0], VEHsize[1]],
                    index=collisionCheck.collisionVars)
Esempio n. 3
0
     
     if carLane[1] == 'i' and len(carLane)==4: # not in intersection yet
         destlane = cars.loc[carID,'dest']
         destlane = destlane[:3] + carLane[3:]
         cars.loc[carID,'ilane'] = roadMap.combineRoad(carLane, destlane)
     elif len(carLane)==4:
         cars.loc[carID,'ilane'] = carLane
     else:
         cars.loc[carID, 'ilane'] = carLane
 
 # cars that collided last time are now completely removed
 carsThatCollidedLastStep = np.where(cars['status']>=2)[0]
 for carID in carsThatCollidedLastStep:
     
     cars.loc[carID, 'status'] = 1
     Sim.removeVehicle(str(carID))
 
 # check for collisions
 activeCars = np.where(cars['status']==0)[0]
 for carNum in range(len(activeCars)):
     carID = activeCars[carNum]
     car = cars.iloc[carID]
     for altNum in range(carNum):
         altID = activeCars[altNum]
         alt = cars.iloc[altID]
         carObject = pd.Series([car['x'],car['y'],car['angle'],
                                VEHsize[0],VEHsize[1]],
                                index=collisionCheck.collisionVars)
         altObject = pd.Series([alt['x'],alt['y'],alt['angle'],
                                VEHsize[0],VEHsize[1]],
                                index=collisionCheck.collisionVars)
Esempio n. 4
0
    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)
        if lane[1] == 'o':  # must be included since back of vehicle
            lanepos = lanepos + roadMap.getLength(road)
        if status == 0:  # add vehicle info to the dataframe
            thisdf.add(
                [[pos[0], pos[1], angle, VEHsize[0], VEHsize[1], lanepos]])
        Sim.moveVehicleAlong(road, dist, turn)
        totaldist += dist
        Sim.updateGUI()

    allcars[road] = thisdf.out()
    Sim.removeVehicle(road)
Sim.end(waitOnEnd=False)

for car in allcars.itervalues():
    car['angle'] = car['angle'] + 1.5708
#
## now use dataframes of position+angle to find collision points
#collisions = WriteFrame(['lane','lane2','begin_lp','end_lp'])
#for an in range(len(intersections)):
#    for bn in range(an):
#        print "checking "+str(an)+", "+str(bn)
#        starta,enda = intersections[an]
#        startb,endb = intersections[bn]
#        roada = combineRoad(starta,enda)
#        roadb = combineRoad(startb,endb)
#        cara = allcars[roada]