riebl / artery

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

Traffic lights in Artery #190

Closed xrispa-m closed 3 years ago

xrispa-m commented 3 years ago

Hi! I need to create a scenario with traffic lights in Artery where the state of the traffic light could change at a certain time. I have created a similar scenario using Veins and Sumo in OMNeT++ and I have used the traci trafficlight class and the setState function. I added the following code in the onWSM from OMNeT++.

if (simTime() > 30 && simTime() < 50) {traci->trafficlight("cluster_254108781_257412131").setState("rrrrrrrrrrrrrrrrrrrr");}

Is there a similar way to do something like that using Artery?

Thanks!

riebl commented 3 years ago

Sure, every SUMO feature exposed by its C++ TraCI API can be used in Artery. I think you are looking for TraCIAPI::TrafficLightScope::setRedYellowGreenState.

xrispa-m commented 3 years ago

Thank you for the reply! Is there a certain class that I should use to add the code for the traffic light? Is CaService and the RsuCaService something similar to the onWSM?

riebl commented 3 years ago

An ItsG5Service's indicate method is invoked whenever a message has arrived for the respective service. In general, I recommend creating a dedicated service for each independent use case.

xrispa-m commented 3 years ago

I was using the RsuCaService before seeing your comment and I tried to create a new object that will be connected to the TraCIAPI. I've created a different program for the traffic lights and then I used the setProgram to change the original program at a given time.

Even though I don't get any errors, the traffic light programs is being set to the last program I'll have in the .net.xml file and it never changes to the new program.

Is there any chance that while the code has no errors, the functionality of the traffic lights is not used correctly?

riebl commented 3 years ago

I don't have a lot of experience controlling SUMO traffic lights. Please see the SUMO manual on how to change their programs properly.

xrispa-m commented 3 years ago

I found a way to access the traffic light using the mVehicleContoller.

mVehicleController = &getFacilities().get_const<traci::VehicleController>();
const std::string id = mVehicleController->getVehicleId();
auto& vehicle_api = mVehicleController->getTraCI()->vehicle;
auto& trafficLight_api = mVehicleController->getTraCI()->trafficlights;