Hello everyone! I'm trying to get the number of vehicles that were involved in a collision during the Sumo simulation via TraCI. I'm using a Veins application to control Sumo simulation via TraCI. I verified that this seems to be done by getCollidingVehiclesNumber() <http://sumo.dlr.de/daily/pydoc/traci._simulation.html#SimulationDomain-getCollidingVehiclesNumber> with variable ID VAR_COLLIDING_VEHICLES_NUMBER.
Checking the Veins code, I understood that I need to register this variable associated with the simulation (CMD_SUBSCRIBE_SIM_VARIABLE). Therefore, I include this variable in the list of variables registered in the simulation. My change in Veins TraCIScenarioManager.cc: <https://github.com/sommer/veins/blob/veins/src/veins/modules/mobility/traci/TraCIScenarioManager.cc> $ git diff src/veins/modules/mobility/traci/TraCIScenarioManager.cc*diff --git a/src/veins/modules/mobility/traci/TraCIScenarioManager.cc b/src/veins/modules/mobility/traci/TraCIScenarioManager.cc**index 56b4eb5d..098423ab 100644**--- a/src/veins/modules/mobility/traci/TraCIScenarioManager.cc**+++ b/src/veins/modules/mobility/traci/TraCIScenarioManager.cc**@@ -279,6 +279,8 @@* void TraCIScenarioManager::initialize(int stage) drivingVehicleCount = 0; autoShutdownTriggered = false; *+ collidingVehicleCount = 0;**+* world = FindModule<BaseWorldUtility*>::findGlobalModule(); vehicleObstacleControl = FindModule<VehicleObstacleControl*>::findGlobalModule();*@@ -314,7 +316,7 @@* void TraCIScenarioManager::init_traci() simtime_t beginTime = 0; simtime_t endTime = SimTime::getMaxTime(); std::string objectId = "";*- uint8_t variableNumber = 7;**+ uint8_t variableNumber = 8;* uint8_t variable1 = VAR_DEPARTED_VEHICLES_IDS; uint8_t variable2 = VAR_ARRIVED_VEHICLES_IDS; uint8_t variable3 = commandInterface->getTimeStepCmd();*@@ -322,7 +324,8 @@* void TraCIScenarioManager::init_traci() uint8_t variable5 = VAR_TELEPORT_ENDING_VEHICLES_IDS; uint8_t variable6 = VAR_PARKING_STARTING_VEHICLES_IDS; uint8_t variable7 = VAR_PARKING_ENDING_VEHICLES_IDS;*- TraCIBuffer buf = connection->query(CMD_SUBSCRIBE_SIM_VARIABLE, TraCIBuffer() << beginTime << endTime << objectId << variableNumber << variable1 << variable2 << variable3 << variable4 << variable5 << variable6 << variable7);**+ uint8_t variable8 = VAR_COLLIDING_VEHICLES_NUMBER;**+ TraCIBuffer buf = connection->query(CMD_SUBSCRIBE_SIM_VARIABLE, TraCIBuffer() << beginTime << endTime << objectId << variableNumber << variable1 << variable2 << variable3 << variable4 << variable5 << variable6 << variable7 << variable8);* processSubcriptionResult(buf); ASSERT(buf.eof()); }*@@ -864,6 +867,17 @@* void TraCIScenarioManager::processSimSubscription(std::string objectId, TraCIBuf parkingVehicleCount -= count; drivingVehicleCount += count; }*+ if (variable1_resp == VAR_COLLIDING_VEHICLES_NUMBER) {**+ uint8_t varType;**+ buf >> varType;**+ ASSERT(varType == TYPE_INTEGER);**+ uint32_t count;**+ buf >> count;**+ EV_DEBUG << "TraCI reports " << count << " collided vehicles." << endl;**+**+ collidingVehicleCount += count;**+ }* else if (variable1_resp == getCommandInterface()->getTimeStepCmd()) { uint8_t varType; buf >> varType; However, with that, the simulation init is crashing. The error displayed in TraCi is as follows: Result: "<?xml version="1.0"?> <status> <exit-code>1</exit-code> <start>1590255944</start> <end>1590255952</end> <status>Exited with error code 1</status> <stdout><![CDATA[Loading configuration ... done. ]]></stdout> <stderr><![CDATA[ *Error: tcpip::Socket::recvAndCheck @ recv: peer shutdownQuitting (on error).* ]]></stderr> </status> " The CMD_SUBSCRIBE_SIM_VARIABLE query is handled here: https://github.com/eclipse/sumo/blob/master/src/traci-server/TraCIServer.cpp#L839 and the error is returned here: https://github.com/eclipse/sumo/blob/master/src/foreign/tcpip/socket.cpp#L458 Could anyone tell me if this is the correct way to access the count of collisions identified during the simulation? Or is there a way to get this value directly? Thanks in advance! -- Tiago Alves Silva
_______________________________________________ sumo-user mailing list [email protected] To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
