Search code examples
pythonsumo

Sumo, TraCI: Subscription with tc.VAR_ROUTE and tc.VAR_FOLLOWER fails. Which subscription variables can I use for vehicles?


I want to subscribe to vehicles in my simulation. However, I find it very difficult to understand which variables I can use for this, as the documentation does not include this information.

        traci.vehicle.subscribe(veh_id, [
            tc.VAR_SPEED,
            tc.VAR_ACCELERATION,
            tc.VAR_EMERGENCY_DECEL,
            # tc.VAR_ROUTE,
            tc.VAR_POSITION,
            # tc.VAR_FOLLOWER,
            tc.VAR_NEXT_TLS
        ])

The issue is, that tc.VAR_ROUTE causes this error in the terminal:

traci.exceptions.TraCIException: Could not add subscription. Get Vehicle Variable: unsupported variable 0x57 specified

and tc.VAR_FOLLOWER causes this error in SUMO:

Error: Storage::readChar(): invalid position
Quitting (on error).

Why is that? Also I do not quite understand how to learn more about the different constants. For example, which ones can I use to subscribe to vehicles? When I look into the file under traci/constants.py, there are different types of variables.

  • starting with CMD_ (the comments call these "command")
  • starting with RESPONSE_ (the comments call these "response")
  • starting with VAR_ (the comments say these are "Variable types (for CMD_GET_*_VARIABLE)")
  • stop flags, departure flags, and many more
  • Also, the comments sometimes say something like: (get: ...; set: ...)

e.g. here:

#  position (2D) (get: vehicle, poi, inductionloop, lane area detector; set: poi)
VAR_POSITION = 0x42 

What does that mean, I know that I can get the subscription results from subscribing to these constants, but how could I possibly set them?

My main question is if someone can please explain how these constants are structured and which ones I can use for subscribing to vehicles.


Solution

  • You are right this is not well documented. I added a ticket: https://github.com/eclipse/sumo/issues/8579

    The answer to your direct question is that everything which is listed in the value retrieval section of the docs (which should be equivalent to having a "get" in the constants file comment) should be "subscribable".

    VAR_ROUTE is not, because it is only used to set a route using the edge list but there is no equivalent getter. You can only subscribe to the route ID for instance. VAR_FOLLOWER in turn needs a parameter when subscribing, so you need to give that as an additional argument. How to do that unfortunately depends on your SUMO version.

    For SUMO 1.9 and later the call looks like this:

    traci.vehicle.subscribe(vehID, (tc.VAR_FOLLOWER,), begin, end, {tc.VAR_FOLLOWER: ("d", dist)})