TraCI/C++TraCIAPI
Contents
C++ TraCIAPI client library
The C++ TraCIAPI is client library that is part of the SUMO-source tree. The library can be found at sumo/src/utils/traci]. Examle code that uses the library is at TraCI-Testclient. Doxygen-generated documentation can be found here
Due to not being the main client library for use by the core developers, this client library may not support the full API. see ticket2008.
TraCI-Testclient
The TraCI-Testclient is an application for testing the server side of the TRaCI-API. When using it as the basis for your own control script one needs to be aware of its two operating modes:
Feeding raw TraCI commands to SUMO
In this operating mode, the full TraCI-API is supported. Example input files typically look like:
repeat 50 simstep2 0 setvalue 0xc4 0x31 veh0 <string> e_vo0 simstep2 200
This mode is meant for testing the server side and is unsuitable for building a control program that mixes TraCI calls with custom code.
Testing the TraCIAPI client library
In this mode the client library itself is used. Example code looks like:
SUMOTime t = simulation.getCurrentTime(); std::vector<std::string> = edge.getIDList();
Example Code
#include <iostream>
#include <utils/traci/TraCIAPI.h>
class Client : public TraCIAPI {
public:
Client() {};
~Client() {};
};
int main(int argc, char* argv[]) {
Client client;
client.connect("localhost", 1337);
std::cout << "time in ms: " << client.simulation.getCurrentTime() << "\n";
std::cout << "run 5 steps ...\n";
client.simulationStep(5 * 1000);
std::cout << "time in ms: " << client.simulation.getCurrentTime() << "\n";
client.close();
}
compiling:
g++ -o test TraCIAPITest.cpp utils/traci/libtraci.a foreign/tcpip/storage.o foreign/tcpip/socket.o -I .
running:
sumo -c test.sumocfg --remote-port 1337 & ./test