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)
        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'])
Exemple #2
0
                    cars.loc[carID, 'status'] = 2 + altID
                    cars.loc[altID, 'status'] = 2 + carID
                    collisionCount += 2
                    Sim.addCrashSymbol(str(carID), str(altID))
                    print "found a double lane-change collision"
                    print "shouldn't be happening anymore!!"

        # gather when the vehicles reach potential collision points
        trajectories = {}
        for carID in np.where((cars['status'] == 0)
                              | (cars['status'] >= 2))[0]:
            car = cars.iloc[carID]
            route, grade, ln = splitRoad(car['lane'])

            if grade == 0:  # not in intersection yet
                initDist = car['lanepos'] - roadMap.getLength(car['lane'])
            elif grade == 2:  # left intersection (but maybe tail end is still there)
                initDist = car['lanepos'] + roadMap.getLength(car['ilane'])
            else:
                initDist = car['lanepos']

            trajectory = []
            for crossIndex in range(intersectionInfo.shape[0]):
                thisCross = intersectionInfo.iloc[crossIndex]
                if thisCross['lane'] == car['ilane']:
                    #                   if thisCross['end_lp'] > initDist:
                    #                      timeToCrossingStart = (thisCross['begin_lp'] -
                    #                                             initDist) / car['speed']
                    #                      timeToCrossingEnd = (thisCross['end_lp'] -
                    #                                               initDist) / car['speed']
                    #                      trajectory += [[thisCross['lane2'],
                if collisionCheck.check(carObject, altObject):
                    cars.loc[carID, 'status'] = 2 + altID
                    cars.loc[altID, 'status'] = 2 + carID
                    collisionCount += 2
                    Sim.addCrashSymbol(str(carID), str(altID))
                    print "found a double lane-change collision"
                    print "shouldn't be happening anymore!!"
        
        # gather when the vehicles reach potential collision points
        trajectories = {}
        for carID in np.where((cars['status']==0) | (cars['status']>=2))[0]:
            car = cars.iloc[carID]
            route,grade,ln = splitRoad(car['lane'])
            
            if grade==0: # not in intersection yet
                initDist = car['lanepos'] - roadMap.getLength(car['lane'])
            elif grade==2: # left intersection (but maybe tail end is still there)
                initDist = car['lanepos'] + roadMap.getLength(car['ilane'])            
            else:
                initDist = car['lanepos']
            
            trajectory = []
            for crossIndex in range(intersectionInfo.shape[0]):
                thisCross = intersectionInfo.iloc[crossIndex]
                if thisCross['lane'] == car['ilane']:
#                   if thisCross['end_lp'] > initDist:
#                      timeToCrossingStart = (thisCross['begin_lp'] - 
#                                             initDist) / car['speed']
#                      timeToCrossingEnd = (thisCross['end_lp'] - 
#                                               initDist) / car['speed']
#                      trajectory += [[thisCross['lane2'],
    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)
        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