首页 > 解决方案 > 如何使用 TraCi 获取边缘的 id?

问题描述

我正在使用带有 traci 库的 python 代码来了解是否有任何车辆靠近所选车辆一定距离,以测试我正在尝试实施的解决方案我需要知道车辆的当前边缘。

我在 Ubuntu 18.04.3 LTS 上,使用 sublime 编辑代码和 os、sys、optparse、subprocess、random、math 库。我试过使用getLaneIdand getEdgeId,最后一个不在文档中,但我很难在某处看到它并尝试对其进行测试。. 我曾经使用的另一个选项,getNeighbors但我不知道如何使用它,它返回与以前的命令相同的错误消息。

def run():
    step = 0
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        print(step)
        print(distancia("veh1","veh0"))
        step += 1  
        if step > 2:
            print(traci.vehicle.getLaneId("veh0"))
    traci.close()
    sys.stdout.flush()

他们都返回以下错误消息:AttributeError: VehicleDomain instance has no attribute 'getLaneId'。但我认为车辆域确实具有该getLaneId属性,因为它在文档中:https ://sumo.dlr.de/pydoc/traci._vehicle.html#VehicleDomain-getSpeed 。我期待它返回边缘的ID。请我需要帮助来解决这个问题。先感谢您。

标签: sumo

解决方案


edgeID 的 TraCI 命令可以在_vehicle.VehicleDomain模块中找到。语法如下:

traci._vehicle.VehicleDomain.getRoadID(self, vehicleID)

推荐阅读