omnet++,veins,sumo使用多应用层实现车辆和行人的模拟

1、完成网络的搭建:

搭建一个简单的十字路口场景:

1)定义结点:新建intersection.node.xml,内容如下:

NOTE1:结点属性type="traffic_light" 意味着车辆和行人在此遵守信号灯指引,而type="unregulated"意味着车辆和行人在此不改变运动状态,即可能出现碰撞。

<nodes>
	<node id="node1" x="600" y="0" type="priority"/>
	<node id="node2" x="0" y="600" type="priority"/>
	<node id="node3" x="600" y="600" type="traffic_light"/>
	<node id="node4" x="1200" y="600" type="priority"/>
	<node id="node5" x="600" y="1200" type="priority"/>
	
	<node id="node8" x="300" y="300" type="priority"/>
	<node id="node9" x="300" y="600" type="unregulated"/>
	<node id="node10" x="300" y="900" type="priority"/>
</nodes>

2) 定义边:新建intersection.edge.xml,内容如下:

NOTE2:修改edge的车道lane,index="0"为最右侧车道,添加属性allow="pedestrian" 或者 添加edge属性:sidewalkWidth="1" 自动添加一个allow="pedestrian"的lane,宽度等于1。

<edges>
	<edge id="1to3" from="node1" to="node3" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="3to1" from="node3" to="node1" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="2to9" from="node2" to="node9" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="9to2" from="node9" to="node2" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="9to3" from="node9" to="node3" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="3to9" from="node3" to="node9" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="4to3" from="node4" to="node3" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="3to4" from="node3" to="node4" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="5to3" from="node5" to="node3" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
	<edge id="3to5" from="node3" to="node5" priority="4" numLanes="3" speed="15">
		<lane index="0" allow="pedestrian"/>
	</edge>
		
	<edge id="8to9" from="node8" to="node9" priority="4" numLanes="1" speed="15">
	</edge>
	<edge id="9to8" from="node9" to="node8" priority="4" numLanes="1" speed="15">
	</edge>
	<edge id="9to10" from="node9" to="node10" priority="4" numLanes="1" speed="15">
	</edge>
	<edge id="10to9" from="node10" to="node9" priority="4" numLanes="1" speed="15">
	</edge>
</edges>

3)在路口添加人行道:新建intersection.con.xml,内容如下:

NOTE3:node为设置人行道的结点,edge表示人行道横跨的道路。
NOTE4:在结点上添加crossing,结点必须与将要设置人行道的路段有连接。

<connections>
<crossing node="node3" edges="1to3 3to1" priority="true"/>
<crossing node="node3" edges="9to3 3to9" priority="true"/>
<crossing node="node3" edges="4to3 3to4" priority="true"/>
<crossing node="node3" edges="5to3 3to5" priority="true"/>
</connections>

3)生成网络:

 打开sumo文件夹中的\bin\start-command-line.bat,使用指令:

netconvert --node-files=intersection.node.xml --edge-files=intersection.edge.xml --connection-files=intersection.con.xml --output-file=intersection.net.xml

生成intersection.net.xml文件。

 2、在路网中加入车流和人流:

1)新建intersection.rou.xml,内容如下:

NOTE5:这里都是定义的vType,到veins中再指定相应的模块。

<?xml version="1.0" encoding="UTF-8"?>
<routes>
	<route id="route0" edges="2to9 9to3 3to4"/>
	<route id="route1" edges="4to3 3to9 9to2"/>
	<route id="route2" edges="1to3 3to5"/>
	<route id="route3" edges="5to3 3to1"/>
	<route id="route4" edges="8to9 9to3 3to5"/>
	<route id="route5" edges="10to9 9to8"/>
   
	<vType id="vtype0" accel="2.6" decel="4.5" sigma="0.5" length="4" width = "2" minGap="2.5" maxSpeed="14" color="1,1,0"/>
	<vType id="vtype1" accel="2.6" decel="4.5" sigma="0.5" length="0.21" width = "0.48" minGap="2.5" maxSpeed="1.39" color="0,1,1"/>
	
	<flow id="flow0" type="vtype0" route="route0" begin="0" period="3" number="10"/>	
	<flow id="flow1" type="vtype0" route="route1" begin="0" period="3" number="10"/>	
	<flow id="flow2" type="vtype0" route="route2" begin="0" period="3" number="10"/>	
	<flow id="flow3" type="vtype0" route="route3" begin="0" period="3" number="10"/>
		
	<flow id="flow4" type="vtype1" route="route4" begin="0" period="3" number="10" departPos="250"/>
	<flow id="flow5" type="vtype1" route="route5" begin="0" period="3" number="10" departPos="240"/>	
</routes>

 2)新建intersection.sumo.cfg,内容如下:

<configuration>
    <input>
      <net-file value="D:/sumo/abcBeaconRateAdapt/intersection.net.xml"/>
      <route-files value="D:/sumo/abcBeaconRateAdapt/intersection.rou.xml"/>
    </input>
   
    <time>
      <begin value="0"/>
      <end value="1000"/>
      <step-length value="0.1"/>
    </time>
	
    <reports>
       <print-options value="false"/>
    </reports>
    
    <gui_only>
        <start value="true"/>
    </gui_only>
</configuration>

 3)验证网络和车流:

打开sumo\bin\sumo-gui.exe模拟车流,正确则进行下一步:

3、在Veins中模拟

1)导入文件:

复制intersection.net.xml、intersection.rou.xml、intersection.sumo.cfg三个文件放入omnetpp中veins项目下相应位置,新建intersection.launchd.xml,内容如下:

<?xml version="1.0"?>
<!-- debug config -->
<launch>
	<copy file="intersection.net.xml" />
	<copy file="intersection.rou.xml" />
	<copy file="intersection.sumo.cfg" type="config" />
</launch>

修改omnetpp.ini文件中的配置来更改配置文件:

*.manager.launchConfig = xmldoc("intersection.launchd.xml") 

 如果在导入文件后运行出现如下错误:

注释.ini文件中的:

*.obstacles.obstacles = xmldoc("config.xml", "//AnalogueModel[@type='SimpleObstacleShadowing']/obstacles")

如果还出错,备注config.xml中的:

2)指定行人和车的不同模块 :

在omnetpp.ini文件中添加配置为人和车分配不同的模块类型、模块名和显示的图片(在images\veins\node中)。为了方(tou)便(lan),这里Human模块和node模块一样,改了个名字。

NOTE6:这里的两个vtype对应intersection.rou.xml中的两个vtype。

*.manager.moduleType = "vtype0=org.car2x.veins.nodes.Car vtype1=org.car2x.veins.nodes.Human"
*.manager.moduleName = "vtype0=node vtype1=human"
*.manager.moduleDisplayString = "vtype0='i=veins/node/car;is=vs' vtype1='i=veins/node/pedestrian;is=vs'"

3)添加人模块的配置(所有node配置先给human来一份):

这里应用层用了"MyVeinsApp",这个类是vines自带的,继承自BaseWaveApplLayer,比较空,很适合用来自己定义应用层。当然,如果给Human模块定义不一样的应用层,也可以继承BaseWaveApplLayer,方法是一样的。如果两个模块的结构不一样,其中可有一些难搞的地方,可能以后会再说。

*.human[*].applType = "MyVeinsApp"
*.human[*].appl.headerLength = 80 bit
*.human[*].appl.sendBeacons = false
*.human[*].appl.dataOnSch = false
*.human[*].appl.beaconInterval = 1s

*.human[*].veinsmobilityType.debug = true
*.human[*].veinsmobility.x = 0
*.human[*].veinsmobility.y = 0
*.human[*].veinsmobility.z = 1.895
*.human[*0].veinsmobility.accidentCount = 0
*.human[*0].veinsmobility.accidentStart = 75s
*.human[*0].veinsmobility.accidentDuration = 50s

*.human[*].appl.dataOnSch = true

 运行Veins:

当人和车相撞时,可能出错,因为在定义结点时,左边的十字路口定义为了无规则,如果不需要碰撞也定义成"traffic_light"就行了。在sumo中模拟时,相撞的车辆会被从场景中移除:

以上即本次全部内容,感谢看到最后,希望对你有帮助。

  • 17
    点赞
  • 86
    收藏
    觉得还不错? 一键收藏
  • 23
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 23
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值