我需要通过在仅由一个交叉口与四个连接的双车道组成的网络中使用加速度值来设置每个时间步的车速(见图)。因此,我一直在使用setSpeed命令,但是遇到了问题。在Sumo-GUI中,车辆参数中显示的速度会显示设置的速度值,并且getSpeed还会提供所需的速度。然而,通过使用单个时间步长之间的驱动距离(通过车辆位置计算)除以时间步长来计算实际速度,可以在车道上获得不同的值。在模拟可视化中也可以识别速度差。一旦相交到达,速度似乎是正确的。 speedMode已设置为零,并且车道的速度限制设置为100,所以这不会成为问题。任何帮助将不胜感激。我已经测试了SUMO 1.1.0和1.2.0。在下面提到的交叉路口中,显示了示例代码,其中车辆应持续行驶5 m / s(加速度= 0)并输出。可以看出,实际速度只要在3.8左右的车道上行驶并在穿过交叉路口时达到5 m / s。遵循的路线只是从左到右。
代码:
from sumolib import checkBinary
import sys
import traci
step_length = 0.5
traci.start([checkBinary('sumo-gui'), '-c', "Config.sumocfg", '--step-length', str(step_length)])
start_vel = 5
helper_var = 0
vehID = 'car1'
traci.simulationStep()
traci.vehicle.setSpeedMode(vehID, 0)
traci.vehicle.setLaneChangeMode(vehID, 0)
traci.vehicle.setSpeed(vehID, start_vel)
traci.simulationStep()
while traci.simulation.getMinExpectedNumber():
acceleration = 0
newSpeed = traci.vehicle.getSpeed(vehID) + step_length * acceleration
print("Wanted new speed: ", newSpeed)
traci.vehicle.setSpeed(vehID, newSpeed)
traci.simulationStep()
print("Apparently new speed: ", traci.vehicle.getSpeed(vehID))
if helper_var != 0:
print("Actual new speed: ", abs((helper_var - traci.vehicle.getPosition(vehID)[0])/step_length))
helper_var = traci.vehicle.getPosition(vehID)[0]
else:
helper_var = traci.vehicle.getPosition(vehID)[0]
print('---------------------------------------------')
traci.close()
sys.stdout.flush()
穿过结点之前和之后的输出部分:
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.8000000000000007
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.799999999999997
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.8000000000000043
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.847999999999997
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 5.0
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 5.0
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 5.000000000000002
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 4.999999999999998
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 5.0
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 4.664
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.8000000000000007
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.799999999999997
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.8000000000000043
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.799999999999997
---------------------------------------------
Wanted new speed: 5.0
Apparently new speed: 5.0
Actual new speed: 3.8000000000000043