如何获得特定范围内的汽车数量 [英] How to get count of cars in specific range

查看:125
本文介绍了如何获得特定范围内的汽车数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模拟一种VANET场景,在这种场景中,如果道路被阻塞,那么在特定时间之后,汽车会广播一条消息,其中包括被阻塞的roadId和其周围100米处的车辆数量.

In veins i'm trying to simulate a VANET scenario in which if road is blocked then after specific time the car broadcast a message including blocked roadId and count of vehicles around it's 100 meter.

在TraCIDemo11p应用程序中,当汽车停下来超过10秒钟时,它将节点颜色更改为红色(以表示事故),并向包含阻塞道路ID的其他汽车发送消息,所有这些操作都在handlePositionUpdate方法中完成:

In TraCIDemo11p application when the car is stopped for longer than 10 seconds it changes the node color to red (to show an accident) and sends a message out to other cars containing the blocked road id, all this is done in handlePositionUpdate mehtod:

findHost()->getDisplayString().updateWith("r=16,red");
sentMessage = true;

WaveShortMessage* wsm = new WaveShortMessage();
populateWSM(wsm);
wsm->setWsmData(mobility->getRoadId().c_str());

//host is standing still due to crash
if (dataOnSch) {
    startService(Channels::SCH2, 42, "Traffic Information Service");
    //started service and server advertising, schedule message to self to send later
    scheduleAt(computeAsynchronousSendingTime(1,type_SCH),wsm);
}
else {
    //send right away on CCH, because channel switching is disabled
    sendDown(wsm);
}

可以通过更新.ini文件中的maxInterfDist值来设置100m的限制

The limit of 100m can be set by updating maxInterfDist value in in .ini file

*.connectionManager.maxInterfDist = 100m

现在我遇到的问题是如何获取车辆数量和100m的面积,我有一个想法,这将使用TraCI来完成,并且很可能使用

Now the problem I have is how to get the count of vehicles and 100m of area, I have an idea that this will be done using TraCI and most probably using LaneAreaDetector's getJamLengthVehicle but i'm not getting how this will be done in veins, is their any equivalent method or i'm looking in wrong direction?

推荐答案

您可以使用

You can get a list of all vehicles in the OMNeT++ simulation using TraCIScenarioManager::getManagedHosts method. From there, it should be straightforward to calculate the distance between any two hosts (their location on the OMNeT++ canvas is equivalent to their position, measured in meters).

这篇关于如何获得特定范围内的汽车数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆