0

I'm using a python code with the traci library to know if there are any vehicles near a certain distance to a chosen vehicle, to test a solution I'm trying to implement I need to know a vehicle's current edge.

I'm on Ubuntu 18.04.3 LTS, using sublime to edit the code and the os, sys, optparse, subprocess, random, math libraries. I've tried using getLaneId and getEdgeId, the last one is not in the documentation but I tough I've seen it somewhere and tried to test it. . Another option that i had was using getNeighbors but i didn't know exactly how to use it and it returned the same error message as the previous commands.

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()

All of them returned the following error message : AttributeError: VehicleDomain instance has no attribute 'getLaneId'. But I think the vehicle domain has indeed the getLaneId attribute since it is in the documentation: https://sumo.dlr.de/pydoc/traci._vehicle.html#VehicleDomain-getSpeed. I was expecting it to return the edge's id. Please I need help with this problem. Thank you in advance.

2 Answers2

1

The TraCI command for edgeID can be found in the _vehicle.VehicleDomain module. The syntax is as follows:

traci._vehicle.VehicleDomain.getRoadID(self, vehicleID)
FrainBr33z3
  • 1,085
  • 1
  • 6
  • 12
  • Works like a charm too! Thank you! – Gustavo Azevedo Correa Sep 04 '19 at 02:16
  • Please do not access the domains directly, rather use traci.vehicle.getRoadID – Michael Sep 04 '19 at 20:50
  • @Michael any particular reason why? – FrainBr33z3 Sep 05 '19 at 06:38
  • @FrainBr33z3 As indicated by the leading underscore the _vehicle.py is considered an internal module and not part of the public interface. But probably more important by accessing the method of a class without creating an instance you skip the initialization part of the object and it is not guaranteed to work in general (I think it is even illegal in Python 2, see the comments to the second answer here: https://stackoverflow.com/questions/735975/static-methods-in-python). – Michael Sep 05 '19 at 07:28
1

It needs to be getLaneID with a capital D.

Michael
  • 3,510
  • 1
  • 11
  • 23