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: currentAccPass = 0. if time > parameters['tpr']: currentAccPass = accPass # 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 ])
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: currentAccPass = 0. if time > parameters['tpr']: currentAccPass = accPass # 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.:
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) 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
'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()
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 continue #if carLane[1] == 'o': # cars.loc[carID,'status'] = 1 cars.loc[carID,'lane'] = carLane
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 continue #if carLane[1] == 'o': # cars.loc[carID,'status'] = 1
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) 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)