前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >omnet++,veins,sumo使用多应用层实现车辆和行人的模拟

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

原创
作者头像
PERSEUS
发布2023-11-03 23:26:09
4020
发布2023-11-03 23:26:09
举报
文章被收录于专栏:车联网仿真车联网仿真

1、完成网络的搭建:

首先搭建一个简单的十字路口场景。

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

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

代码语言:javascript
复制
<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。

代码语言:javascript
复制
<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,结点必须与将要设置人行道的路段有连接。

代码语言:javascript
复制
<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>

4)生成网络:

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

代码语言:javascript
复制
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中再指定相应的模块。

代码语言:javascript
复制
<?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,内容如下:

代码语言:javascript
复制
<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,内容如下:

代码语言:javascript
复制
<?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文件中的配置来更改配置文件:

代码语言:javascript
复制
*.manager.launchConfig = xmldoc("intersection.launchd.xml") 

如果在导入文件后运行出现报错“xmldoc("config.xml","//AnalogueModel[@type='SimpleObstacleShadowing']/obstacles"): Element not found -- in module(veins:ObstacleControl) RSUExampleScenario.obstacles(id=2), during network setup”,注释.ini文件中的:

代码语言:javascript
复制
*.obstacles.obstacles = xmldoc("config.xml", "//AnalogueModel[@type='SimpleObstacleShadowing']/obstacles")

如果还出错,备注config.xml中的<AnalogueModel type="SimpleObstacleShadowing">标签。

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

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

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

代码语言:javascript
复制
*.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,方法是一样的。如果两个模块的结构不一样,其中可有一些难搞的地方,可能以后会再说。

代码语言:javascript
复制
*.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。

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

以上即本次全部内容!

我正在参与2023腾讯技术创作特训营第三期有奖征文,组队打卡瓜分大奖!

邀请人:千万别过来

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、完成网络的搭建:
    • 1)定义结点:新建intersection.node.xml,内容如下:
      • 2) 定义边:新建intersection.edge.xml,内容如下:
        • 3)在路口添加人行道:新建intersection.con.xml,内容如下:
          • 4)生成网络:
          • 2、在路网中加入车流和人流:
            • 1)新建intersection.rou.xml,内容如下:
              • 2)新建intersection.sumo.cfg,内容如下:
                • 3)验证网络和车流:
                • 3、在Veins中模拟
                  • 1)导入文件:
                    • 2)指定行人和车的不同模块 :
                      • 3)添加人模块的配置(所有node配置先给human来一份):
                      领券
                      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档