Reputation: 21
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
Upvotes: 1
Views: 447
Reputation: 21
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.
Upvotes: 1
Reputation: 6943
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
.
Upvotes: 1