예제 #1
0
 laneChange = False
 
 car['speed'] = car['speed']+speedChange
 distance = car['speed']*DELTAT
 if turn and grade=='i':
     zz = list((j for i,j,k in intersectionLookUp if i==car['lane']))
     if len(zz) > 1:
         if zz[0]==car['dest']:
             newdest=zz[1]
         else:
             newdest=zz[0]
     #right = next((i for i,j in enumerate(roadOrder) if 
     #                        j==route)) + 1
     #newdest = makeRoad(roadOrder[right],'o',ln)
     #if not newdest == car['dest']:
         err += Sim.moveVehicleAlong(str(carID), 0.0, newdest)
         #car['dest'] = newdest # keep old destination?
 if laneChange and (grade =='i' or grade=='o'):
     newlane = makeRoad(route,grade,1-ln)
     err += Sim.moveVehicle(str(carID), newlane, car['lanepos'])
     cars['lane'] = newlane
     
 if Sim.getLaneInfo(car['lane'])[0] - carLanePos <= distance:
     if grade=='i': # entering intersection
         #internal = next((k for i,j,k in intersectionLookUp if
         #            i==car['lane'] and j==car['dest']))
         #err += Sim.moveVehicleAlong(str(carID), distance, internal)
         err += Sim.moveVehicleAlong(str(carID), distance, ':')
     elif grade=='o': # leaving simulation
         Sim.removeVehicle(str(carID))
         cars['status'].iloc[carID] = 1
예제 #2
0
 if params_iter['Collision Time'].iloc[0] < 0:
     egoObject = pd.Series(egoState[2:5] + list(VEHsize),
                           index=collisionCheck.collisionVars)
     leftObject = pd.Series(leftState[2:5] + list(VEHsize),
                            index=collisionCheck.collisionVars)
     if collisionCheck.check(egoObject,leftObject):
         params_iter['Collision Time'].iloc[0] = ttime
         params_iter['Collision Vehicle'].iloc[0] = 'left'
 
 # construct next step
 ttime += DELTAT
 egoDist = egoSpeed*DELTAT
 if Sim.getLaneInfo(egoLane)[0] - egoLanePos <= egoDist:
     if egoLane[1]=='i': # ego entering intersection
         if uniform(0,2)<1:
             err += Sim.moveVehicleAlong('ego',egoDist, '2o_0')
         else:
             err += Sim.moveVehicleAlong('ego',egoDist, '2o_1')
     elif egoLane[1]=='o': # remove vehicle or exit simulation
         break
     #else: # ego leaving intersection
     #    destLane = Sim.getLaneInfo(egoLane)[2][0]
     #    err += Sim.moveVehicleAlong('ego',egoDist,destLane)
 elif egoDist > 0.:    
     err += Sim.moveVehicleAlong('ego', egoDist)
     
 leftDist = leftSpeed*DELTAT
 if Sim.getLaneInfo(leftLane)[0] - leftLanePos < leftDist:
     if leftLane[1]=='i': # ego entering intersection
         err += Sim.moveVehicleAlong('left',leftDist, '1o_1')
     elif leftLane[1]=='o': # remove or exit sim
예제 #3
0
     else:
         output = output.append([egoState, leadState])
     
     # check for first collision - others too difficult to store..
     if params_iter['Collision Time'].iloc[0] < 0:
         egoObject = pd.Series(egoState[2:5] + list(VEHsize),
                               index=collisionCheck.collisionVars)
         leadObject = pd.Series(leadState[2:5] + list(VEHsize),
                                index=collisionCheck.collisionVars)
         if collisionCheck.check(egoObject,leadObject):
             params_iter['Collision Time'].iloc[0] = ttime
     
     # construct next step
     ttime += DELTAT
     if egoSpeed > 0.:    
         err += Sim.moveVehicleAlong('ego', egoSpeed * DELTAT)
     if leadSpeed > 0.:
         err += Sim.moveVehicleAlong('lead', leadSpeed * DELTAT)
         
     # check for ending of simulation
     if lanelength - max(leadLanePos, egoLanePos) < 10:
         # either vehicle is near the end of the road
         break
     if egoLanePos - leadLanePos > 100:
         # ego passed lead a while ago
         break
     if err > 0:
         break
 
 if err == 0:
     Sim.end()
예제 #4
0
        if params_iter['Collision Time'].iloc[0] < 0:
            egoObject = pd.Series(egoState[2:5] + list(VEHsize),
                                  index=collisionCheck.collisionVars)
            leftObject = pd.Series(leftState[2:5] + list(VEHsize),
                                   index=collisionCheck.collisionVars)
            if collisionCheck.check(egoObject, leftObject):
                params_iter['Collision Time'].iloc[0] = ttime
                params_iter['Collision Vehicle'].iloc[0] = 'left'

        # construct next step
        ttime += DELTAT
        egoDist = egoSpeed * DELTAT
        if Sim.getLaneInfo(egoLane)[0] - egoLanePos <= egoDist:
            if egoLane[1] == 'i':  # ego entering intersection
                if uniform(0, 2) < 1:
                    err += Sim.moveVehicleAlong('ego', egoDist, '2o_0')
                else:
                    err += Sim.moveVehicleAlong('ego', egoDist, '2o_1')
            elif egoLane[1] == 'o':  # remove vehicle or exit simulation
                break
            #else: # ego leaving intersection
            #    destLane = Sim.getLaneInfo(egoLane)[2][0]
            #    err += Sim.moveVehicleAlong('ego',egoDist,destLane)
        elif egoDist > 0.:
            err += Sim.moveVehicleAlong('ego', egoDist)

        leftDist = leftSpeed * DELTAT
        if Sim.getLaneInfo(leftLane)[0] - leftLanePos < leftDist:
            if leftLane[1] == 'i':  # ego entering intersection
                err += Sim.moveVehicleAlong('left', leftDist, '1o_1')
            elif leftLane[1] == 'o':  # remove or exit sim
예제 #5
0
파일: Qsim.py 프로젝트: xjtuwh/carstop
            car['speed'] = car['speed'] + speedChange
            distance = car['speed'] * DELTAT
            if turn and grade == 'i':
                zz = list(
                    (j for i, j, k in intersectionLookUp if i == car['lane']))
                if len(zz) > 1:
                    if zz[0] == car['dest']:
                        newdest = zz[1]
                    else:
                        newdest = zz[0]
                #right = next((i for i,j in enumerate(roadOrder) if
                #                        j==route)) + 1
                #newdest = makeRoad(roadOrder[right],'o',ln)
                #if not newdest == car['dest']:
                    err += Sim.moveVehicleAlong(str(carID), 0.0, newdest)
                    #car['dest'] = newdest # keep old destination?
            if laneChange and (grade == 'i' or grade == 'o'):
                newlane = makeRoad(route, grade, 1 - ln)
                err += Sim.moveVehicle(str(carID), newlane, car['lanepos'])
                cars['lane'] = newlane

            if Sim.getLaneInfo(car['lane'])[0] - carLanePos <= distance:
                if grade == 'i':  # entering intersection
                    #internal = next((k for i,j,k in intersectionLookUp if
                    #            i==car['lane'] and j==car['dest']))
                    #err += Sim.moveVehicleAlong(str(carID), distance, internal)
                    err += Sim.moveVehicleAlong(str(carID), distance, ':')
                elif grade == 'o':  # leaving simulation
                    Sim.removeVehicle(str(carID))
                    cars['status'].iloc[carID] = 1
예제 #6
0
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 17 20:13:37 2015

@author: motro
"""

from sumoMethods import Sumo

configuration = 'emptyhighway'

sim = Sumo(configuration, gui=True)

sim.createVehicle('a','main_0',40)
[lane,lanex,xy] = sim.getVehicleState('a')
print 'a, 0: '+str(xy[0])

sim.createVehicle('b','main_0')
[lane,lanex,xy] = sim.getVehicleState('b')
print 'b, 0: '+str(xy[0])

sim.moveVehicleAlong('b',38)
[lane,lanex,xy] = sim.getVehicleState('a')
print 'a, 1: '+str(xy[0])
[lane,lanex,xy] = sim.getVehicleState('b')
print 'b, 1: '+str(xy[0])

sim.end()
예제 #7
0
    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
    
err = 0
Sim = Sumo(configuration,gui=True)

# first gather the possible positions/angles of each intersection lane
allcars = {}
for start, end, road in intersectionLookUp:
    print "at "+road
    err += Sim.createVehicle(road, start, 90.)
    err += Sim.moveVehicleAlong(road, 0.1, end)
    thisdf = WriteFrame(['x','y','angle','length','width','lp'])    
    
    dist = 1.
    status = -1
    totaldist = 0
    while status < 1 and totaldist < 50:
        lane,lanepos,pos,angle = Sim.getVehicleState(road)
        status = (lane[1]=='o')-(lane[1]=='i')
        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)
        totaldist += dist
        time.sleep(.05) # might guard against freeze
        
    allcars[road] = thisdf.out()