0

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.

sepideh
  • 61
  • 7

1 Answers1

0

I understood where is my mistake. I calculate distance1 and distance2 at same time. However I should calculate them in different time. for this purpose I consider getpositionAt() method instead of getcurrentposition().

simtime_t T=simTime()+60;
senderposition1=mobility->getpositionAt(T);
receiverposition1=mobility2->getpositionAt(T);
double distance2=senderposition1.Distance(receiverposition1);
sepideh
  • 61
  • 7