0

I'm using veins 5 and I am trying to obtain the position of nodes around in a certain distance from a node. More specifically, I'm trying to get a mapping position of all nodes in an instant to work with the positions of the nodes.

I read this question How to get count of cars in specific range, however it centered in veins 4.6 and also I didn't get how to use the method suggested by Christoph Sommer. Is it possible to get the mapping in veins 5? How can I work this?

I'll appreciate any help Thanks!

1 Answers1

0

Finally I got the position of all nodes in the simulation and calculate their distance from a tagged car.

To do this I "translate" the answer of Ahmad Ahsan in the question How to get Coordinates of each vehicle in VEINS? to veins 5.0 in the following way:

void MessageGenerator::getMapping(){

    // Get my position on the scenario
    veins::Coord myPosition = mobility->getPositionAt(simTime());
    EV << myPosition << endl;

    // Get all available nodes in simulation
    std::map<std::string, cModule*> allNodes = mobility->getManager()->getManagedHosts();

    // Iterate through collection and find distance,
    std::map<std::string, cModule*>::iterator it;

    for(it = allNodes.begin(); it != allNodes.end(); it++)
    {
        TraCIMobility* auxMobility = TraCIMobilityAccess().get(it->second);
        veins::Coord receiverPosition = auxMobility->getPositionAt(simTime());

        //returns distance in meters
        double dist = myPosition.distance(receiverPosition);
        EV << "Distance: " << dist << endl;
    }
}

The key change is in the getPositionAt(simTime()) method.

One additional comment, as discussed in this post the method of obtain all vehicles in simulation is a bad practice if this data is used for realistic simulation purposes, because it is rarely possible to obtain all positions in one time step. In my case, I used it for only evaluation purposes.