您的位置:首页 > 其它

Veins(车载通信仿真框架)入门教程

2018-02-28 23:28 806 查看

Veins入门教程——教你如何下手研究

目录

Veins入门教程——教你如何下手研究
目录

废话少说!

讲解omnetpp.ini!(挑关键的)

讲解RSUExampleScnario.ned!

注意:写着写着发现要讲的实在太多了,实在没精力了,后面就只会提重点了,可能显得虎头蛇尾,但本文只是提点入门,最重要的还是自己去琢磨,不可能一篇博客就包教会。还有学之前先学会C++。

Veins是一款用于车载移动环境下无线通信仿真的开源框架,其对于车载无线网的底层结构,如物理层、MAC层等基于802.11p协议已基本开发完善,因此在此基础上进行二次开发,如改进MAC层协议或者路由协议等研究都是非常便携的。甚至如果是进行应用层上的研究,如车联网环境下的车辆自动驾驶、编队行驶、路径规划、信号灯区域协调等则更加方便,因为底层的结构可以直接使用,不必再浪费时间精力在这些并不是需要主要研究但却又对仿真结果影响重大的部分。

Veins的好处很多,一旦掌握可以节省大量的开发时间,得到更加准确的仿真实验结果,为自己的理论提供更加权威可靠的支持。但是Veins的相关教程却寥寥无几,除了官网上的一份运行其内置示例的教程外很难再寻找到其他相关教程,因此很多人打开Veins后面对密密麻麻的
C++
代码难以下手,望而却步。博主因为学业所需对其进行过一段时间的研究,真是万分痛苦!在此将自己的研究经验经过整理得到一份入门级教程奉献给大家,愿大家都能早日脱离苦海。

看教程之前先确定自己已经把官网上的内置示例的教程运行成功了。

废话少说!

首先在OMNeT++的IDE左侧有如下图所示的窗口,打开veins的项目(博主拿二次开发过的程序在讲解,可能会比纯净版多出一些文件,大家不要在意),veins内置的示例就在文件夹examples内:



antenna.xml:对车辆天线做出配置,不用管;

config.xml:配置物理层无线电传播相关参数,如示例中将信号路径衰落的模型配置为“SmiplePathlossModel”,障碍物引起的信号衰落模型设置为“SimpleObstacleShadowing”,一般使用默认的即可;

<?xml version="1.0" encoding="UTF-8"?>
<root>
<AnalogueModels>
<AnalogueModel type="SimplePathlossModel">
<parameter name="alpha" type="double" value="2.0"/>
<parameter name="carrierFrequency" type="double" value="5.890e+9"/>
</AnalogueModel>
<AnalogueModel type="SimpleObstacleShadowing">
<parameter name="carrierFrequency" type="double" value="5.890e+9"/>
<obstacles>
<type id="building" db-per-cut="9" db-per-meter="0.4" />
</obstacles>
</AnalogueModel>
</AnalogueModels>
<Decider type="Decider80211p">
<!-- The center frequency on which the phy listens-->
<parameter name="centerFrequency" type="double" value="5.890e9"/>
</Decider>
</root>


debug:调试信息,不用管;

erlangen.launchd.xml:建立与SUMO的通信,不能更改;

erlangen.net.xml: SUMO路网文件,跑自己的仿真时需要替换,至于如何生成请参考SUMO官网文档

erlangen.poly.xml:如果SUMO路网文件是由地图转化而来的,如从OpenStreetMap导入的,则路网文件中还将包含所选地区的建筑物的信息,通过SUMO提供的OpenStreetMap Web接口便可生成记录这些建筑物形状、大小和位置信息的配置文件,作为config.xml内信号衰落模型的输入;如果不考虑建筑物对于信号传播的影响则无需此文件,当然config.xml内的信号衰落模型的配置也要删去;

<?xml version="1.0" encoding="UTF-8"?>
<root>
<AnalogueModels>
<AnalogueModel type="SimplePathlossModel">
<parameter name="alpha" type="double" value="2.0"/>
<parameter name="carrierFrequency" type="double" value="5.890e+9"/>
</AnalogueModel>
</AnalogueModels>
<Decider type="Decider80211p">
<!-- The center frequency on which the phy listens-->
<parameter name="centerFrequency" type="double" value="5.890e9"/>
</Decider>
</root>


erlangen.rou.xml:交通流文件,如何生成也请查阅SUMO官网文档,不再赘述;

erlangen.sumo.cfg: SUMO运行文件,可对运行时长等运行参数进行配置;

omnetpp.ini:
OMNeT++运行文件,后文重点讲解;


RSUExampleScnario.ned: OMNeT++类似于积木,一个工程项目是由多个ned文件互相嵌套组合而成的。veins作为一个基于OMNeT++的框架,其便是由层次分明的ned文件组合而成的,如果学过面向对象编程的话可能会容易理解一些,这些ned文件就类似一个个。但是OMNeT++中更为特殊,因为ned文件只是定义了组件的结构,比如定义一辆车,ned只是描述了它包含几个对外通信的接口,这些接口的参数之类的,具体的功能还需要与ned文件同名的C++文件进行定义,比如用这些接口选择与谁进行通信,专业点就叫路由。对于OMNet++独特的ned网络语言大家还是踏踏实实看OMNeT++官方手册学习吧。一开始可能找不到头绪,所以建议大家去听听这个OMNeT++基础讲解的视频课程(要学的东西是不是很多?是不是很烦?)。这里的RSUExampleScnario.ned定义了OMNeT++中最大的结构——网络(network),可以看到在omnetpp.ini中的[General]部分对于本次仿真所运行的网络定义为RSUExampleScenario;

[General]
cmdenv-express-mode = true
cmdenv-autoflush = true
cmdenv-status-frequency = 1s
**.cmdenv-log-level = info

ned-path = .
image-path = ../../images

network = RSUExampleScenario


讲解omnetpp.ini!(挑关键的)

network:非常关键的参数,需要替换成自己的network级ned文件;

sim-time-limit: 网络仿真时间限制,注意与SUMO生成的交通流运行时长对应;

RSU SETTINGS:RSUExampleScnario.ned中的路侧单元ned中的参数做出设置。其中最重要的就是
applType
,它指定了RSU的应用层,也就是RSU会做什么。其实RSU也是一个ned文件,比network级低,它是由另外几个更低级的ned组成的,包括作为应用层的ned(appl),作为MAC层的ned(nic),作为移动驱动的ned(mobility)。
applType
指定的就是应用层的ned,而应用层ned的功能又由其同名且在同一个文件夹的C++文件定义,这样RSU的功能也就确定了,
做应用层研究的要改变的就是这个应用层的ned与对应的C++文件
。至于后面那些参数都是对于应用层ned中的一些参数做出设置,比如.rsu[*].appl.beaconUserPriority = 7就是令所有RSU应用层的信标优先级为7,这个就不要再问了,做车联网的这个还不懂就别玩了。

##########################################################
#                       RSU SETTINGS                     #
#                                                        #
#                                                        #
##########################################################
*.rsu[0].mobility.x = 2000
*.rsu[0].mobility.y = 2000
*.rsu[0].mobility.z = 3

*.rsu[*].applType = "TraCIDemoRSU11p"
*.rsu[*].appl.headerLength = 80 bit
*.rsu[*].appl.sendBeacons = true
*.rsu[*].appl.dataOnSch = false
*.rsu[*].appl.beaconInterval = 1s
*.rsu[*].appl.beaconUserPriority = 7
*.rsu[*].appl.dataUserPriority = 5




11p specific parameters NIC-Settings:对MAC层ned(nic)相关参数做出设置,nic包含两个子ned(mac1609_4和phy80211p)。至于connectionManager基本保持不变,如果要研究信号传播范围的影响的话,需要改变maxInterfDist

##########################################################
#            11p specific parameters                     #
#                                                        #
#                    NIC-Settings                        #
##########################################################
*.connectionManager.sendDirect = true
*.connectionManager.maxInterfDist = 2600m
*.connectionManager.drawMaxIntfDist = false

*.**.nic.mac1609_4.useServiceChannel = false

*.**.nic.mac1609_4.txPower = 20mW
*.**.nic.mac1609_4.bitrate = 6Mbps
*.**.nic.phy80211p.sensitivity = -89dBm

*.**.nic.phy80211p.useThermalNoise = true
*.**.nic.phy80211p.thermalNoise = -110dBm

*.**.nic.phy80211p.decider = xmldoc("config.xml")
*.**.nic.phy80211p.analogueModels = xmldoc("config.xml")
*.**.nic.phy80211p.usePropagationDelay = true

*.**.nic.phy80211p.antenna = xmldoc("antenna.xml", "/root/Antenna[@id='monopole']")




WaveAppLayer: 对移动节点(车辆)的应用层做出设置,和RSU一个道理;

##########################################################
#                    WaveAppLayer                        #
##########################################################
*.node[*].applType = "TraCIDemo11p"
*.node[*].appl.headerLength = 80 bit
*.node[*].appl.sendBeacons = true
*.node[*].appl.dataOnSch = false
*.node[*].appl.beaconInterval = 1s


Mobility: 对移动节点的移动模块做出设置。其中accidentCount、accidentStart、accidentDuration这三个参数是对移动节点发生事故的事件做出设置,这是veins的examples演示的功能(事故预警消息的传播),我们用不到直接令accidentCount=0即可。

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


讲解RSUExampleScnario.ned!

这里只挑最重要的讲,其余的自己看ned文件的import、extends往上慢慢捋就行。

看代码可以发现RSUExampleScnario内加入了一个RSU单元。

import org.car2x.veins.nodes.RSU;
import org.car2x.veins.nodes.Scenario;

network RSUExampleScenario extends Scenario
{
submodules:
rsu[1]: RSU {
@display("p=150,140;i=veins/sign/yellowdiamond;is=vs");
}
}


那么下面官网上的示例动图里的移动节点是怎么加入的呢?



其实是通过TraCIScenarioManagerLaunchd.ned这个模块加入的

package org.car2x.veins.modules.mobility.traci;

//
// Extends the TraCIScenarioManager for use with sumo-launchd.py and SUMO.
//
// Connects to a running instance of the sumo-launchd.py script
// to automatically launch/kill SUMO when the simulation starts/ends.
//
// All other functionality is provided by the TraCIScenarioManager.

simple TraCIScenarioManagerLaunchd
{
parameters:
@display("i=block/network2");
@class(Veins::TraCIScenarioManagerLaunchd);
bool debug = default(false);  // emit debug messages?
double connectAt @unit("s") = default(0s);  // when to connect to TraCI server (must be the initial timestep of the server)
double firstStepAt @unit("s") = default(-1s);  // when to start synchronizing with the TraCI server (-1: immediately after connecting)
double updateInterval @unit("s") = default(1s);  // time interval of hosts' position updates
string moduleType = default("org.car2x.veins.nodes.Car");  // module type to be used in the simulation for each managed vehicle
string moduleName = default("node");  // module name to be used in the simulation for each managed vehicle
// module displayString to be used in the simulation for each managed vehicle
// display strings key-value pairs needs to be protected with single quotes, as they use an = sign as the type mappings. For example
// <pre>
// *.manager.moduleDisplayString = "'i=block/process'"
// *.manager.moduleDisplayString = "a='i=block/process' b='i=misc/sun'"
// </pre>
//
// moduleDisplayString can also be left empty:
// <pre>
// *.manager.moduleDisplayString = ""
// </pre>
string moduleDisplayString = default("*='i=veins/node/car;is=vs'");
string host = default("localhost");  // sumo-launchd.py server hostname
int port = default(9999);  // sumo-launchd.py server port
xml launchConfig; // launch configuration to send to sumo-launchd.py
int seed = default(-1); // seed value to set in launch configuration, if missing (-1: current run number)
bool autoShutdown = default(true);  // Shutdown module as soon as no more vehicles are in the simulation
int margin = default(25);  // margin to add to all received vehicle positions
string roiRoads = default("");  // which roads (e.g. "hwy1 hwy2") are considered to consitute the region of interest, if not empty
string roiRects = default("");  // which rectangles (e.g. "0,0-10,10 20,20-30,30) are considered to consitute the region of interest, if not empty. Note that these rectangles have to use TraCI (SUMO) coordinates and not OMNeT++. They can be easily read from sumo-gui.
double penetrationRate = default(1); //the probability of a vehicle being equipped with Car2X technology
int numVehicles = default(0);
bool useRouteDistributions = default(false);
int vehicleRngIndex = default(0); // index of the RNG stream to be used, all random numbers concerning the managed vehicles
}


其中下面一行代码定义了RSUExampleScnario.ned这个network中加入的移动节点。往上一层层捋就很容易发现,RSUExampleScnario继承自Scnario,Scnario又import了TraCIScenarioManagerLaunchd。

string moduleType = default("org.car2x.veins.nodes.Car");


到此为止,入门结束,剩下的具体功能实现请进入src/veins/nodes文件夹,仔细琢磨其中的ned文件并一层层往上捋即可。最后再啰嗦一句,ned定义结构,同名C++文件定义功能,明白这一点其实就没问题了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  车联网 仿真 veins