'C++/Omnet++ connect to SUMO via TraCI Interface

I have a question regarding connecting to SUMO as a second client.

I have found the following tutorial from Sep. 2021:

https://www.academia.edu/49581640/Manual_of_Sumo_Matlab_Veins_INET_OMNeT_Programming_and_interfacing

It basically tells me, that in order to fulfill the requirements of connecting to SUMO as a client, I only have to adapt the "TraCIScenarioManager.cc/.h" and "TraCICommandInterface.cc/.h" files (available on github in Mr. Sommer's folder sommer/veins/..., i think very easy to find) such that

  1. My C++/Omnet++ client tells SUMO the desired importance/position in the processing order. (E.g. Omnet++ client is "second" in a chain of in total two clients connecting to SUMO, in each timestep).

  2. Give SUMO feedback that it may proceed to the next timestep of simulation (which SUMO will do if all connected clients provide such a message)

I adapted the following code in my TraCIScenarioManger.cc file (with "_SUMO" extension). This - if called - shall fulfill above requirement "1".:

void TraCIScenarioManager_SUMO::init_traci(bool OrderIsSet)
{

 auto* commandInterface = getCommandInterface();
  {
    // set Order
    if (!OrderIsSet)
    {
        commandInterface -> setOrder(2);
        OrderIsSet = true;
    }
    auto apiVersion = commandInterface->getVersion();
    EV_DEBUG << "TraCI server \"" << apiVersion.second << "\" reports API version "                 << apiVersion.first << endl;
    commandInterface->setApiVersion(apiVersion.first);
    }...

Regarding the "2" requirement the tutorial link above says:

The [setOrder] function has to be called in TraCIScenarioManager.cc inside a loop. As setOrder must be called only once, a boolean variable is defined and used to call it only once. The function must be placed at the start of void TraCIScenarioManager::init_traci() function, before the api version function call,

Thus, my main script looks like this. I set up a loop an as the boolean condition is only "false" for the first time, setOrder is only called once (SetOrder is a function of getCommandInterface() which is in turn an object of class "TraCICommandInterface").

However, in this loop, in particular by using the executeOneTimestep function I cannot connect to SUMO. The tutorial unfortunately does not cover this relevant step of setting up the main function. Does anybody know how I can properly connect to SUMO?

Main function within TraCIScenarioManager_SUMMO.cc (based on TraCIScenarioManager.cc):

bool OrderIsSet = false;

int main() {

TraCIScenarioManager_SUMO ScenarioManager;

while(true)
{
ScenarioManager.init_traci(OrderIsSet);
ScenarioManager.executeOneTimestep();
};
return 0;
}

Best regards, Lukas



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source