如何获取 Veins 中两个节点(例如车辆)之间的距离或行程时间?

How to get the distance or travel time between two nodes (e.g., vehicles) in Veins?

在静脉中,我可以使用 Coord.distance() 函数计算两个坐标之间的距离。但是,此函数只是计算两点之间的笛卡尔距离。两辆车或一辆车与路口之间的实际距离取决于边缘形状(例如,曲线边缘)。此外,它还取决于边长(SUMO 参数)。它们在 SUMO 或 Veins 中的功能是否考虑了这些因素?

你可以使用 SuMO 的 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);

我发现我的错误了!

为了获得车辆与另一个节点(特别是交通灯)之间的行驶距离,我必须估计一个有效的坐标,它靠近交通灯并位于车辆路线上,与计算车辆与红绿灯交叉点坐标之间的距离。

为了估计交通灯的有效坐标,我使用了道路 ID 中车辆将通过交通灯的任何车道的最后坐标。代码将是这样的:

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