I found that in SUMO, once traci.vehicle.changeLane(“self_car”, “{}”.format(0), 5) be started, it will not accept new action during the 5 steps, For example, if I want to abort the lane change in this whole duration, what should i do? Here’s my code, since it’s no use:
<code>def abort_lane_change(egoID, original_lane_index):
traci.vehicle.changeLane(egoID, original_lane_index, 0)
print(f"Vehicle {egoID} aborting lane change and returning to lane {original_lane_index}")
for step in range(duration):
time.sleep(0.5)
traci.vehicle.setLaneChangeMode("self_car", 0b000000000000)
traci.vehicle.setLaneChangeMode("vehicle1", 0b000000000000)
traci.vehicle.setSpeedMode("self_car", 0)
traci.vehicle.setSpeedMode("vehicle1", 0)
traci.simulationStep()
if step == 10: # 假设在第10步开始换道
traci.vehicle.changeLane(egoID, 1, 5) # 换到车道1,用时5秒
if 10 < step < 15: # 在10到15步之间尝试中止换道
current_lane_index = traci.vehicle.getLaneIndex(egoID)
print(f"Step {step}: Current lane index of {egoID} is {current_lane_index}")
if current_lane_index != original_lane_index:
abort_lane_change(egoID, original_lane_index)
</code>
<code>def abort_lane_change(egoID, original_lane_index):
traci.vehicle.changeLane(egoID, original_lane_index, 0)
print(f"Vehicle {egoID} aborting lane change and returning to lane {original_lane_index}")
for step in range(duration):
time.sleep(0.5)
traci.vehicle.setLaneChangeMode("self_car", 0b000000000000)
traci.vehicle.setLaneChangeMode("vehicle1", 0b000000000000)
traci.vehicle.setSpeedMode("self_car", 0)
traci.vehicle.setSpeedMode("vehicle1", 0)
traci.simulationStep()
if step == 10: # 假设在第10步开始换道
traci.vehicle.changeLane(egoID, 1, 5) # 换到车道1,用时5秒
if 10 < step < 15: # 在10到15步之间尝试中止换道
current_lane_index = traci.vehicle.getLaneIndex(egoID)
print(f"Step {step}: Current lane index of {egoID} is {current_lane_index}")
if current_lane_index != original_lane_index:
abort_lane_change(egoID, original_lane_index)
</code>
def abort_lane_change(egoID, original_lane_index):
traci.vehicle.changeLane(egoID, original_lane_index, 0)
print(f"Vehicle {egoID} aborting lane change and returning to lane {original_lane_index}")
for step in range(duration):
time.sleep(0.5)
traci.vehicle.setLaneChangeMode("self_car", 0b000000000000)
traci.vehicle.setLaneChangeMode("vehicle1", 0b000000000000)
traci.vehicle.setSpeedMode("self_car", 0)
traci.vehicle.setSpeedMode("vehicle1", 0)
traci.simulationStep()
if step == 10: # 假设在第10步开始换道
traci.vehicle.changeLane(egoID, 1, 5) # 换到车道1,用时5秒
if 10 < step < 15: # 在10到15步之间尝试中止换道
current_lane_index = traci.vehicle.getLaneIndex(egoID)
print(f"Step {step}: Current lane index of {egoID} is {current_lane_index}")
if current_lane_index != original_lane_index:
abort_lane_change(egoID, original_lane_index)
I will really be appreciated if any one can help me with this problem.
New contributor
yutong wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.