How to get count of cars in specific range

2019-05-31 09:25发布

问题:

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