I want to determine that two vehicles are getting far away. I wrote my codes in handlepositionupdate method of TraCIDemo11p class but only half of my code runs correctly.
Coord senderPosition = mobility->getCurrentPosition();
double direction1=mobility->getAngleRad();
std::map<std::string, cModule*> availableCars = mobility->getManager()-
>getManagedHosts();
std::map<std::string, cModule*>::iterator it;
for(it = availableCars.begin(); it != availableCars.end(); it++)
{
TraCIMobility* mobility2 = TraCIMobilityAccess().get(it->second);
double direction2=mobility2->getAngleRad();
Coord receiverPosition = mobility2->getCurrentPosition();
if(direction2!=direction1){
std::cout<<"they move in opposite direction"<<endl;
}
double distance1=senderPosition.distance(receiverPosition);
WaveShortMessage* wsm = new WaveShortMessage();
scheduleAt(simTime()+1,wsm);
cArray array("array1");
int index = array.add(wsm);
double distance2=senderPosition.distance(receiverPosition);
if(distance2>distance1){
std::cout<<"they are getting far away"<<endl;
array.remove(index);
array.addAt(index, bsm);
}
}
}
when I run it ,it just presents they move in opposite direction and The rest of it is not presented. therefore I want that my code determines which vehicles are getting far away.where is my problem? I really appreciate any help.