eclipse-sumo / sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
https://eclipse.dev/sumo
Eclipse Public License 2.0
2.49k stars 1.41k forks source link

How to get a detector ID where a vehicle of interest is located? #15429

Closed dawn-fm closed 5 days ago

dawn-fm commented 1 week ago

Hi all,

I'm not sure whether this is proper to write a question on here. Sorry in advance if not proper.

I am writing to find a method to ask if there are any methods to get a detector ID where a vehicle of interest is located.

My scenario is as follows:

I have a 5x5 grid network (below figure), each edge of which has two lanes.

Say the length of each lane is 100m and has E2 detectors of length 10m on every unit distance (say 10m).

Moreover, there is a vehicle of interest with a given origin-destination pair.

In order to move this vehicle via TraCI, I want to get a detector ID where this vehicle is located.

How can I do above things?

Thank you.

If possible, upload an example that shows your problem. 5x5gridnetwork

SUMO-version: SUMO 1.4.0

operating system: Ubuntu 20.04 on WSL2 (Windows 11)

namdre commented 1 week ago

traci.vehicle.subscribeContext(vehID, inductionloop.DOMAIN_ID, range, [traci.constants.TRACI_ID_LIST])

or you could iterate over all detectors and check whether they have the vehicle with lanearea.getLastStepVehicleIDs.

dawn-fm commented 1 week ago

@namdre Thank you for your kind response!

I tried your former suggestion among two. Since I chose and installed lanearea detector on my network, I wrote the code as follows:

import traci.constants as tc
...
traci.start()
traci.route.add('OD', ['origin','destination']
...
traci.vehicle.subscribeContext(EV_ID, tc.CMD_GET_LANEAREA_VARIABLE, 20, [tc.TRACI_ID_LIST])

while traci.simulation.getMinExpectedNumber() > 0:
    traci.simulationStep()

    e2_id = traci.vehicle.getContextSubscriptionResults(EV_ID)
    print(e2_id)

traci.close()

But this kept shows me a result of

>> {}
{}
{}
...
{}

Judging by the observation that changing domain to LANE (i.e., tc.CMD_GET_LANE_VARIABLE yields lane IDs, TraCI connection and subscription works well.

Afraid of bothering you but can you help me more?

Thank you.

namdre commented 1 week ago

The described approach works in my own test. Please provide all input files (including the minimal python script) to replicate the problem on my end. (you can attach a .zip archive)

dawn-fm commented 1 week ago

Okay. Here is my zip archive. The version of my environment is stated above. LaneRPM_share.zip

dawn-fm commented 5 days ago

Hi,

After upgrading Ubuntu 22.04 and SUMO 1.12.0, e2 detector value retrieval from vehicle subscription became available. The bug was with the old version! I will self-close this issue.

Thank you for your help so far Dr. Erdmann (@namdre).