How to get count of cars in specific range

时光总嘲笑我的痴心妄想 提交于 2019-12-08 06:09:02

问题


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.

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);
}

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

*.connectionManager.maxInterfDist = 100m

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?


回答1:


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).



来源:https://stackoverflow.com/questions/49021921/how-to-get-count-of-cars-in-specific-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!