riebl / artery

OMNeT++ V2X simulation framework for ETSI ITS-G5
GNU General Public License v2.0
202 stars 128 forks source link

Connecting to Sumo server by TraCi #317

Closed alizz-99 closed 4 months ago

alizz-99 commented 6 months ago

Hi! I am trying to connect to the traci server from an external python file. I have read that by default traci is connected to port 8813 but when i try this in the script: traci.connect(port=8813) it returns the following error: Could not connect to TraCI server at localhost:8813 [Errno 111] Connection refused. I have also tried to modify the sumo configuration file and put , but I can't connect either.

Thank you!

riebl commented 6 months ago

Artery uses a random port for TraCI by default, see the traci/PosixLauncher module. You can set it to a fixed port number by setting the module's port parameter in your omnetpp.ini.

alizz-99 commented 6 months ago

Thank you for the quick response! But I have added to my omnetpp.ini: *.traci.launcher.port = 8813, and I still can't access that port from the python file. The error persists.

alizz-99 commented 6 months ago

Hi! I have managed to customize the port number, but I guess since artery uses traci, sumo by default only accepts one client connection. I have seen that you can modify this value with --num-clients. I don't know if it is possible to modify this value in artery.

fysch commented 6 months ago

You can use *.traci.launcher.extraOptions to pass any option you want to SUMO.

alizz-99 commented 6 months ago

Perfect thank you! I get sumo to wait for two clients to connect. One connects automatically from artery and the second one I connect from the python file getting this response in the sumo logs: Starting server on port 8000 waiting for 2 clients... client connected client connected but it gets stuck there and does nothing. If I try to do traci.simulationStep() I get an error.

alizz-99 commented 6 months ago

Hello! I finally reached my goal using *.traci.launcher.extraOptions thank you very much! Now another question, I've created a service that I have equipped to a static rsu, which processes the data of the vehicles and I would like to control the traffic lights from this code and I do not know how. I am trying to reach this data with

std::shared_ptr<traci::API> m_traci;
auto& trafficlights_api = m_traci->trafficlights;

but I got nothing, it returns a dumped core.

riebl commented 6 months ago

Your m_traci shared pointer is empty and thus dereferencing it crashes the program. Just because code compiles does not mean it is correct.

You can retrieve a valid traci::API object by looking up the NodeManager object usually located at module path World.traci.nodes. The NodeManager has a getAPI getter method for exactly your purpose.

alizz-99 commented 6 months ago

I'm trying to do something like that but it doesn't work either... I'm not sure if I understood you correctly:

std::shared_prt<traci::NodeManager> manager;
auto api = manager->getAPI()->trafficlights;

errors:

Error: tcpip::Socket::recvAndCheck @ recv: peer shutdown
Quitting (on error).
Segmentation fault (core dumped)
alizz-99 commented 5 months ago

Hello again! I would just like to know if it is possible to create a service for RSUs, and inside this service to have access to the traffic lights of the scene by traci, as it is done in cars with mVehiclecontroller.