Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
590 views
in Technique[技术] by (71.8m points)

c++ - How to get count of cars in specific range

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...