I have already created my own Veins scenario, now i need to retrieve vehicle values such as mean speed and gas emission like CO2 of each individual vehicles of the scenario. Can somebody explain to me in details how to achieve this? Any code that need to be implemented? If yes,in which file? I have already browsed through the TraCI wiki of SUMO,but it isn't explained how to achieve this. Any help would be of great value to me. USING: SUMO 0.32 and Omnet++5.3
1 Answers
I am using an older version of veins but it may still be the same way.
Indeed, as you said the tip is in the TraciMobility file. Take a look at "TraciMobility.cc" & "TraciMobility.h" which are in "veins\modules\mobility\traci\". You can figure out that there is a variable (double totalCO2Emission) initialized and maintained during the simulation run time. The variable is recorder as a scalar. I am not sure how to get its value yet (since I am new to veins as well). however there is another way to get the totalCO2Emission which will be to:
- Add a method for that, in "TraciMobility.h".
virtual double getTotalCO2Emission() const {
return totalCO2Emission;
}
- now in what concerns your question about the exact place to retrieve the CO2 value, since it is from the vehicle then you "may want to" add it in "TraCIDemo11p.cc" (if you receive a specific message?) if on message reception, then add this in the "TraCIDemo11p::onWSM" function:
double test = mobility->getTotalCO2Emission();
or just print it as an event like:
EV << "Test the CO2 emission: " << mobility->getTotalCO2Emission() << endl;
so whenever the vehicle receives a message, it will show up in the simulation screen (if it is not cmd) the current CO2 emsision amount.
If any thing, feel free to mention it.
Best regards,