在SUMO中获取错误的速度值



下面是我的autobahn.net.xml

<?xml version="1.0" encoding="UTF-8"?><net version="1.9" junctionCornerDetail="5" limitTurnSpeed="5.50" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd"><location netOffset="0.00,0.00" convBoundary="-124.21,-12.52,21.96,76.82" origBoundary="10000000000.00,10000000000.00,-10000000000.00,-10000000000.00" projParameter="!"/><edge id=":gneJ11_0" function="internal"><lane id=":gneJ11_0_0" index="0" speed="13.89" length="0.10" shape="-119.32,-13.29 -119.32,-13.29"/></edge><edge id=":gneJ9_0" function="internal"><lane id=":gneJ9_0_0" index="0" speed="13.89" length="0.10" shape="11.42,48.97 11.42,48.97"/></edge><edge id="entr" from="gneJ11" to="gneJ9" priority="-1" shape="-119.59,-11.72 -92.19,-6.96 9.84,49.35 9.96,49.62"><lane id="entr_0" index="0" speed="13.89" length="146.26" shape="-119.32,-13.29 -91.65,-8.49 11.09,48.21 11.42,48.97"/></edge><edge id="entry" from="gneJ0" to="gneJ11" priority="-1"><lane id="entry_0" index="0" speed="13.89" length="4.69" shape="-123.94,-14.10 -119.32,-13.29"/></edge><edge id="exit" from="gneJ9" to="gneJ1" priority="-1"><lane id="exit_0" index="0" speed="13.89" length="29.73" shape="11.42,48.97 23.42,76.17"/></edge><junction id="gneJ0" type="dead_end" x="-124.21" y="-12.52" incLanes="" intLanes="" shape="-124.21,-12.52 -123.66,-15.67"/><junction id="gneJ1" type="dead_end" x="21.96" y="76.82" incLanes="exit_0" intLanes="" shape="24.89,75.53 21.96,76.82"/><junction id="gneJ11" type="priority" x="-119.59" y="-11.72" incLanes="entry_0" intLanes=":gneJ11_0_0" shape="-119.59,-11.72 -119.04,-14.87 -119.59,-11.72"><request index="0" response="0" foes="0" cont="0"/></junction><junction id="gneJ9" type="priority" x="9.96" y="49.62" incLanes="entr_0" intLanes=":gneJ9_0_0" shape="9.96,49.62 12.89,48.33 9.96,49.62"><request index="0" response="0" foes="0" cont="0"/></junction><connection from="entr" to="exit" fromLane="0" toLane="0" via=":gneJ9_0_0" dir="s" state="M"/><connection from="entry" to="entr" fromLane="0" toLane="0" via=":gneJ11_0_0" dir="s" state="M"/><connection from=":gneJ11_0" to="entr" fromLane="0" toLane="0" dir="s" state="M"/><connection from=":gneJ9_0" to="exit" fromLane="0" toLane="0" dir="s" state="M"/></net>

以下是我的autobahn.rou.xml

<routes><vType id="normal_car" vClass="passenger" maxSpeed="40" speedFactor="0.9" speedDev="0.2" sigma="0.5" /><vType id="sporty_car" vClass="passenger" maxSpeed="60" speedFactor="1.3" speedDev="0.1" sigma="0.1" /><vType id="trailer" vClass="trailer"  maxSpeed="30" speedFactor="1.1" speedDev="0.1" /><vType id="coach" vClass="coach"  maxSpeed="30" speedFactor="1." speedDev="0.1" /><flow id="normal" type="normal_car" begin="0" end="5000" number="5000" from="entr" to="exit" departPos="last" departLane="best" /><flow id="sporty" type="sporty_car" begin="0" end="5000" number="300" from="entr" to="exit" departPos="last" departLane="best" /><flow id="coach" type="coach" begin="0" end="5000" number="300" from="entry" to="exit" departPos="last" departLane="best" /><flow id="trailer" type="trailer" begin="0" end="5000" number="700" from="entry" to="exit" departPos="last" departLane="best" /></routes>
import os
import sys
import optparse
# we need to import some python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME'")

from sumolib import checkBinary  # Checks for the binary in environ vars
import traci

def get_options():
opt_parser = optparse.OptionParser()
opt_parser.add_option("--nogui", action="store_true",
default=False, help="run the commandline version of sumo")
options, args = opt_parser.parse_args()
return options
def run():
step = 0
all_cars_coming_out = 0
while traci.simulation.getMinExpectedNumber() > 0:
veh_list = traci.simulation.getLoadedIDList()
for veh in veh_list:
# print(veh)
print(traci.vehicle.getSpeed(veh))
traci.simulationStep()
step += 1
all_cars_coming_out += len(veh_list)
# import pdb; pdb.set_trace()
print(all_cars_coming_out)

if __name__ == "__main__":
options = get_options()
# check binary
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
# traci starts sumo as a subprocess and then this script connects and runs
traci.start(
[sumoBinary,
"-n", 
"autobahn.net.xml",
"-r", 
"autobahn.rou.xml"])
run()

我使用traci.vehicle.getSpeed(veh)来检索每一步中所有向量的速度。但是,我得到了类似-10343445的值。我怎样才能获得正确的速度?

您在执行模拟步骤之前检索速度,因此您可能会得到文档中提到的错误值-103741824:https://sumo.dlr.de/docs/TraCI/Vehicle_Value_Retrieval.html.这是因为这些车辆没有机会插入网络。

最新更新