1

I'd like to know if there is the possibility to access the acceleration parameter by adding a function to the TraCICommandInterface. I've seen that the speed value is taken from the Move.h file. I'd like to access to the acceleration computed by TraCI if it's possible, just to get it and not for setting it. Some one have some suggestion? Thanks

2 Answers2

1

Getting the acceleration a vehicle has performed in the last time step is supported by the TraCI API (as of SUMO 1.1.0) via Command 0xa4 (Get Vehicle Variable), variable 0x72 (acceleration) according to the SUMO Wiki.

As of Veins 5 alpha 1, you would simply amend the TraCICommandInterface class of your local copy of Veins to have a method to do so. Your method will likely look very similar to the TraCICommandInterface::Vehicle::getMaxSpeed function.

Here is some example code that works for Veins 5a1 and SUMO 1.0.1. In src/veins/modules/mobility/traci/TraCICommandInterface.cc, add:

double TraCICommandInterface::Vehicle::getAcceleration()
{
    return traci->genericGetDouble(CMD_GET_VEHICLE_VARIABLE, nodeId, VAR_ACCELERATION, RESPONSE_GET_VEHICLE_VARIABLE);
}

If you also amend TraCICommandInterface.h with a corresponding double getAcceleration(); declaration and src/veins/modules/mobility/traci/TraCIConstants.h with a constant like const uint8_t VAR_ACCELERATION = 0x72;, you can query the acceleration like traciVehicle->getAcceleration() in TraCIDemo11p.cc.

Christoph Sommer
  • 6,893
  • 1
  • 17
  • 35
  • That is not so trivial, infact I tried this method but there are few problems: 1) 0x72 it's an already declared variable, even if not used 2) if I try to use 0x72 to get the value as soon as the simulation start this is the error message reported: A runtime error occurred: TraCI server reported error executing commend 0xa4("Get Vehicle Variable: unsupported variable 0x72 specified"). --in module (TraCIDemo11p) – Marcello Sgarbi Jan 10 '19 at 11:43
  • You're absolutely right - this (SUMO refusing to query the acceleration) seems to be a bug that is present at least in SUMO 1.1.0. All the code is in place, but you need to allow VAR_ACCELERATION as one of the possible variables to query for, e.g., in https://github.com/eclipse/sumo/blob/v1_1_0/src/traci-server/TraCIServerAPI_Vehicle.cpp#L294 – Christoph Sommer Jan 10 '19 at 15:16
  • 1
    I hope Veins 5 and SUMO 1.1.0 will be working as soon as possible :) . May I ask you if there is the possibility to try to introduce the acceleration in SUMO 0.30.0? Is there an interface like the one that you described for sumo 1.1.0? – Marcello Sgarbi Jan 11 '19 at 08:50
  • Commit [33f359](https://github.com/sommer/veins/commit/33f359) is based on Veins 5 alpha 1 and adds support for SUMO 1.1.0 – Christoph Sommer Jan 11 '19 at 15:35
  • @ChristophSommer Querying the acceleration from the python client is possible, at least our tests work. The code line you are referring to is for setting not for retrieval so I do not see a SUMO bug immediately. – Michael Jan 11 '19 at 21:24
  • @Michael you're right. I just re-tried and querying VAR_ACCELERATION worked out-of-the-box for both SUMO 1.0.1 and 1.1.0. Indeed, all that was needed was a clean re-build of SUMO. Sorry for the confusion! – Christoph Sommer Jan 13 '19 at 11:56
  • I tried and retried and retried, but I have problems in quering the acceleration. Can you tell me which function and where I have to declare? I added a definition in TraCIConstants VAR_ACCELERATION 0x72, then in TraCICommandInterface I defined a new function so that: `double TraCICommandInterface::Vehicle::getAcceleration() { return traci->genericGetDouble(CMD_GET_VEHICLE_VARIABLE, nodeId, VAR_ACCELERATION, RESPONSE_GET_VEHICLE_VARIABLE); } ` but when I try to get the value for example in BaseWaveApplLayer using `traciVehicle->getAcceleration()` it report me and error in comunication. – Marcello Sgarbi Jan 20 '19 at 19:44
  • @Michael Can you please tell me how you did in SUMO 1.0.1? The fact that you get it as out-of-the-box shows that I'm not getting the point on how to do that. I hope you will have time to do that. I'm using Veins 4.5.1 and SUMO 1.0.1 because you said you can do it also with this. – Marcello Sgarbi Jan 21 '19 at 09:46
  • Are you sure that Veins 4.5.1 is what you are using? Did you mean Veins 4.5? – Christoph Sommer Jan 21 '19 at 09:56
  • @ChristophSommer sorry Veins 4.7.1, omnet 5.4.1, sumo 1.0.1 – Marcello Sgarbi Jan 21 '19 at 10:41
  • @MarcelloSgarbi My comment was referring to the "vanilla" sumo with the python traci client not to Veins. I just wanted to make clear that the command is in fact implemented and working on the (sumo) server side. You can simply have a look at https://github.com/eclipse/sumo/blob/master/tools/traci/_vehicle.py#L193 – Michael Jan 24 '19 at 21:30
  • Veins 4.7.1 does not support SUMO 1.0.1, only SUMO 0.32.0 - and SUMO 0.32.0 does not yet support querying the acceleration. Veins 5a1 supports SUMO 1.0.1, so you most likely want to go with that. I will amend my answer with some example code. – Christoph Sommer Jan 25 '19 at 13:17
1

I would like to give a solution about how I find out the acceleration problem. I'm using SUMO 0.30.0, Veins 4.7.1, Omnet++ 5.4.1 .

I was looking more carefully the TraCIMobility class. Reading line by line I found that the acceleration were computed! So I saved it into a variable, I created a pubblic method to get it and I tring to printing the results for each vehicle, cames out that it is equal to the SUMO one! So without using any call via TraCICommandInterface I'm able to have a reliable value for the acceleration.

For people without a lot of experience I add this: in TraCIMobility.h before the end of the TraCIMobility class:

    protected:
        double m_acceleration = 0;
    public:
        double getAcceleration() { return m_acceleration;}

In TraCIMobility.cc, after the computation of the co2emission variable, I add this line:

m_acceleration = acceleration;

In this way I'm able to use in TraCIDemo11p.cc the right acceleration for each vehicle, without computing it every time a message was received.