0

In veins, I can calculate the distance between two coordinating using the Coord.distance() function. However, this function simply calculates the Cartesian distance between two points. The real distance between two vehicles or a vehicle and a junction depends on the edge shape (e.g., curve edge). Also, it depends on edge length (SUMO parameters). Is their a function in SUMO or Veins that takes these factors into consideration?

Hamzah
  • 120
  • 6

2 Answers2

2

You can use SuMO's distance request TraCI call which can calculate the air distance as well as the driving distance between two arbitrary positions. In Veins this call is implemented in TraCICommandInterface::getDistance():

double getDistance(const Coord& position1, const Coord& position2, bool returnDrivingDistance);
Julian Heinovski
  • 1,822
  • 3
  • 16
  • 27
  • This method works well for the air distance, i.e., returnDrivingDistance = false. However, If I set returnDrivingDistance = true, it returns wrong numbers that goes up and down as the car approach the junction or the coord in road I am interested to cal the distance with. – Hamzah Jun 26 '18 at 19:33
  • Hello I am having the same problem when returning driving distance it gives wrong values! Did you figure out the problem??? – ksa May 19 '20 at 18:21
0

I figured out my mistake!

In order to get a driving distance between a vehicle and another node (specifically traffic light), I had to estimate a valid Coord which is closed to the traffic light and lies on the vehicle route, as opposite to calculating the distance between the vehicle and the traffic light's junction coord.

To estimate a valid coord for the traffic light, I used the last coord of any lane in the road id from which the vehicle will pass the traffic light. The code will be something like this:

// get traffic light controlled lanes
    Veins::TraCICommandInterface::Trafficlight traciTL = traci->trafficlight(trafficLightID);
    // controlled lanes
    std::list<std::string> lanes = traciTL.getControlledLanes();
    for(auto lane : lanes){
        // which controlled lane in the road_id
        if(traci->lane(lane).getRoadId() == road_id){  // found
            // return last Coord of this lane
            std::list<Coord> laneCoords = traci->lane(lane).getShape();
            return  getDistance(vehicle_Coord, laneCoords.back(),true); 
        }
    }
Hamzah
  • 120
  • 6