SUMO变步长仿真

SUMO仿真步长调整

SUMO默认的仿真步长为1s,对于仿真步长的控制,可通过traci.vehicle.setActionStepLength()函数,route配置文件中actionStepLength属性,以及.sumocfg配置文件来改变仿真步长:

函数设置

路网文件:mynet.net.xml





<net version="1.6" 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="0.00,0.00,1500.00,500.00" origBoundary="-10000000000.00,-10000000000.00,10000000000.00,10000000000.00" projParameter="!"/>

    <edge id=":gneJ1_0" function="internal">
        <lane id=":gneJ1_0_0" index="0" speed="10.84" length="10.76" shape="998.34,-1.60 1003.14,-1.78 1006.15,-2.32 1007.38,-3.22 1006.83,-4.49"/>
    edge>
    <edge id=":gneJ1_1" function="internal">
        <lane id=":gneJ1_1_0" index="0" speed="8.41" length="6.31" shape="998.34,-1.60 999.64,-1.80 1001.56,-2.18 1003.44,-2.42 1004.57,-2.22"/>
    edge>
    <edge id=":gneJ1_2" function="internal">
        <lane id=":gneJ1_2_0" index="0" speed="7.11" length="4.40" shape="998.34,-1.60 999.46,-1.50 1000.49,-1.19 1001.44,-0.68 1002.30,0.04"/>
    edge>

    <edge id="gneE0" from="gneJ0" to="gneJ1" priority="-1">
        <lane id="gneE0_0" index="0" speed="13.89" length="998.34" shape="0.00,-1.60 998.34,-1.60"/>
    edge>
    <edge id="gneE1" from="gneJ1" to="gneJ2" priority="-1">
        <lane id="gneE1_0" index="0" speed="13.89" length="705.45" shape="1006.83,-4.49 1505.66,494.34"/>
        <lane id="gneE1_1" index="1" speed="13.89" length="705.45" shape="1004.57,-2.22 1503.39,496.61"/>
        <lane id="gneE1_2" index="2" speed="13.89" length="705.45" shape="1002.30,0.04 1501.13,498.87"/>
    edge>

    <junction id="gneJ0" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,0.00 0.00,-3.20"/>
    <junction id="gneJ1" type="priority" x="1000.00" y="0.00" incLanes="gneE0_0" intLanes=":gneJ1_0_0 :gneJ1_1_0 :gneJ1_2_0" shape="1001.17,1.17 1007.96,-5.62 1007.97,-4.27 1006.76,-3.80 1004.76,-3.47 1001.95,-3.27 998.34,-3.20 998.34,0.00 999.39,0.13 999.88,0.29 1000.34,0.52 1000.77,0.81">
        <request index="0" response="000" foes="000" cont="0"/>
        <request index="1" response="000" foes="000" cont="0"/>
        <request index="2" response="000" foes="000" cont="0"/>
    junction>
    <junction id="gneJ2" type="dead_end" x="1500.00" y="500.00" incLanes="gneE1_0 gneE1_1 gneE1_2" intLanes="" shape="1506.79,493.21 1500.00,500.00"/>

    <connection from="gneE0" to="gneE1" fromLane="0" toLane="0" via=":gneJ1_0_0" dir="l" state="M"/>
    <connection from="gneE0" to="gneE1" fromLane="0" toLane="1" via=":gneJ1_1_0" dir="l" state="M"/>
    <connection from="gneE0" to="gneE1" fromLane="0" toLane="2" via=":gneJ1_2_0" dir="l" state="M"/>

    <connection from=":gneJ1_0" to="gneE1" fromLane="0" toLane="0" dir="l" state="M"/>
    <connection from=":gneJ1_1" to="gneE1" fromLane="0" toLane="1" dir="l" state="M"/>
    <connection from=":gneJ1_2" to="gneE1" fromLane="0" toLane="2" dir="l" state="M"/>

net>

路线配置文件:my_route1.rou.xml

<routes>

   <vType id="CarA" length="4" maxspeed="6"/>
   
   <route id="route1" edges="gneE0 gneE1"/>
   
   <vehicle id="NPC_Car1" depart="0" departLane="0" route="route1" type="CarA"/>
   <vehicle id="NPC_Car2" depart="5" departLane="0" route="route1" type="CarA"/>	

routes>

运行配置文件:my_config_file.sumocfg

<configuration>
   <input>
     <net-file value="mynet.net.xml"/>
     <route-files value="my_route1.rou.xml"/>
   input>
   <time>
     <begin value="0"/>
     <end value="1000"/>
   time>
   <gui_only>
     <start value="t"/>
     <quit-on-end value="t"/>
   gui_only>
configuration>

Python主程序:

"""
@Author: Fhz
@Create Date: 2023/4/6 10:14
@File: main_test.py
@Description: 
@Modify Person Date: 
"""
import sys
import os
import time
import numpy as np

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'")

import traci
from sumolib import checkBinary

if_show_gui = True

if not if_show_gui:
    sumoBinary = checkBinary('sumo')
else:
    sumoBinary = checkBinary('sumo-gui')

sumocfgfile = "Sumo_Config_test/my_config_file.sumocfg"
traci.start([sumoBinary, "-c", sumocfgfile])

# Add new vehicle
traci.vehicle.add("self_car", "route1", "CarA", "20", "0")
traci.vehicle.setColor("self_car", (255, 0, 0))
traci.vehicle.setActionStepLength("self_car", 0.1)

SIM_STEPS = [1, 180]
beginTime = SIM_STEPS[0]
duration = SIM_STEPS[1]

time.sleep(2)

for step in range(duration):
    traci.simulationStep(step*0.1)

route配置文件属性

路线配置文件:my_route1.rou.xml

<routes>

   <vType id="CarA" length="4" maxspeed="6"  actionStepLength="0.1"/>
   
   <route id="route1" edges="gneE0 gneE1"/>
   
   <vehicle id="NPC_Car1" depart="0" departLane="0" route="route1" type="CarA"/>
   <vehicle id="NPC_Car2" depart="5" departLane="0" route="route1" type="CarA"/>	

routes>

其他文件一致

.sumocfg配置文件属性

<configuration>
   <input>
     <net-file value="mynet.net.xml"/>
     <route-files value="my_route1.rou.xml"/>
   </input>
   <time>
     <begin value="0"/>
     <end value="1000"/>
     <step-length value="0.1"/>
   </time>
   <gui_only>
     <start value="t"/>
     <quit-on-end value="t"/>
   </gui_only>
</configuration>

其他文件一致

你可能感兴趣的:(自动驾驶,python,人工智能)