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?
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);
}
}