SUMO建立一个最简单场景的例子
建立一个场景的步骤
1、点开左上角的veins文件夹下examples,右击new>folder新建文件夹,自定义名称(例如cf_highway),此文件夹内放入场景文件。一个简单的场景文件由(此处以example为例)example.lauch.xml、example.sumo.cfg、example.rou.xml、example.net.xml组成。net文件是路的信息,rou文件是车流信息,sumo.cfg是配置文件,lauch.xml是启动文件这个文件在ini里使用。
2、首先需要一个txt文件编辑器,默认的txt就可以用,或者推荐下载Notepad++。下图1所示为整体各个文件之间的关系图
图1. 各部分之间关系图
接下来开始打开新的空txt格式文件开始编辑。其中net文件是由同名的nod文件和edg文件生成的(还可以有typ文件和con文件,简单的场景可能不需要)。其中nod文件中记录的是场景中的坐标点,edge文件负责连接这些点
1
2
3
4
5
6<?xml version="1.0" encoding="UTF-8"?> <nodes > <node id="1" x="0.0" y="0.0" /> <node id="2" x="+3000.0" y="0.0" /> </nodes>
(1)nod文件格式如上所示,id为点的id,在连接这些点时要用到,x、y为在场景中点的横纵坐标定位唯一点。
1
2
3
4
5<?xml version="1.0" encoding="UTF-8"?> <edges > <edge id="D1" from="1" to="2" type="a"/> </edges>
(2)edg文件格式如上所示,id为路的id,由上面定义的点所连接起来,此处有type类型这一属性在typ文件中描述。
1
2
3
4
5<?xml version="1.0" encoding="UTF-8"?> <types> <type id="a" priority="3" numLanes="2" speed="13.889"/> </types>
(3)typ文件中id是类型的id,在edg里引用(也可不用这项属性),priority是驾驶优先级,驾驶优先级是根据交通规则和定义的数字。数字越大,相应道路的优先级就越高。如果nod文件和typ文件都存在优先级的话,优先级信息将覆盖节点文件中的信息;numLanes是每条道路上的车道数,speed为这条车道上所允许的最大车速。
(4)三个同名文件都分别保存为**.nod.xml,.edg.xml,.typ.xml。这三个文件将通过应用模块NETCONVERT生成一个配置文件。为了有效执行,应该创建一个配置文件,其中包括输入文件的名称、输出net文件的名称和其他必需的操作。如果文件和模块NETCONVERT不在同一目录中,则应指定每个文件的相应路径(建议三个文件放在同一目录下会方便许多,例如C:OMNeTppsumo-0.30.0bin)。示例网络的配置文件如下所示,命名为**.netc.cfg。
1
2
3
4
5
6
7
8
9
10
11
12
13
14<configuration> <input> <edge-files value="example.edg.xml"/> <node-files value="example.nod.xml"/> <type-files value="example.typ.xml"/> </input> <output> <output-file value="example.net.xml"/> </output> <processing> <no-turnarounds value="true"/> </processing> </configuration>
(5)用系统命令行执行。具体操作按下win+R键,输入cmd,在出来的界面中输入cd 加四个文件所在的路径(例如cd C:OMNeTppsumo-0.30.0bin)进入指定路径,然后输入 netconvert –c example.netc.cfg,显示Loading configuration… done.Success.即为生成成功,在该路径下会多出一个**.net文件;显示Error: Could not access configuration ‘example.netc.cfg’.Quitting (on error).则没有成功,先检查路径是否正确,该路径下是否有4个同名的edg、nod、typ、netc.cfg文件,然后再尝试输入netconvert –c example.netccfg,生成成功,至此关于路的信息的net文件就已经生成成功。
3、rou文件可以由上面的net文件和一个记录车流的flow文件生成
(1)flow文件的格式如下
1
2
3
4
5
6
7
8
9
10<flows> <flow id="route1" color="1,1,0" from="D1" to="D1" begin="0" end= "200" number="30" departLane="0" /> <flow id="route2" color="255,1,0" from="D1" to="D1" begin="200" end= "400" number="30" departLane="1" />
1
2
3
4
5
6
7
8<?xml version="1.0" encoding="iso-8859-1"?> <configuration > <input> <net-file value="example.net.xml"/> <route-files value="example.rou.xml"/> </input> </configuration>
保存为example.sumo.cfg。
(4)最后建立一个打开文件(xml格式)example.launch.xml
1
2
3
4
5
6
7
8<?xml version="1.0"?> <!-- debug config --> <launch> <copy file="example.net.xml" /> <copy file="example.rou.xml" /> <copy file="example.sumo.cfg" type="config" /> </launch>
在ini文件里引用example.launch.xml。
最后附上netgenerate的使用
https://blog.csdn.net/weixin_48557841/article/details/107313876
最后
以上就是积极春天最近收集整理的关于SUMO建立一个最简单场景的例子的全部内容,更多相关SUMO建立一个最简单场景内容请搜索靠谱客的其他文章。
发表评论 取消回复