0

I am doing a simulation which when an emergency vehicle is approaching to the intersection the state of traffic light should be changed it phase to green. What I try to do is, EV, will send message to the RSU sending it laneId, then the RSU will trigger traffic light through Traci function. However when the simulation reach the part when it need to trigger the Traci function to change traffic light phase, the simulation said "Simulation has encounter a problem, finished with error". Here is the code for the RSU :-

trafficlightrsu.cc files :

'''

 #include "trafficlightrsu.h"
 #include "veins/modules/application/traci/MyVeinsApp.h"
 #include "veins/modules/application/traci/TraCIDemo11pMessage_m.h"

 using namespace veins;

 Define_Module(veins::trafficlightrsu);

 void trafficlightrsu::onWSA(DemoServiceAdvertisment* wsa)
 {
    // if this RSU receives a WSA for service 42, it will tune to the channel
    if (wsa->getPsid() == 42) {
        mac->changeServiceChannel(static_cast<Channel>(wsa->getTargetChannel()));
     }
 }


 void trafficlightrsu::onWSM(BaseFrame1609_4* frame)
 {
    TraCIDemo11pMessage* wsm = check_and_cast<TraCIDemo11pMessage*>(frame);

    std:: string laneId = wsm->getDemoData();

    if(laneId == "14617022#0_0"){

        manager->getCommandInterface()->trafficlight("cluster_144084639_252529291_255540900_6503456532").setPhaseIndex(2);


        }
 }

'''

trafficlightrsu.h file :

'''

    #pragma once
    
    #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h"
    #include "veins/modules/mobility/traci/TraCIScenarioManager.h"
    #include "veins/modules/mobility/traci/TraCICommandInterface.h"
    
    using namespace omnetpp;
    
    namespace veins {
    
    
    class VEINS_API trafficlightrsu : public DemoBaseApplLayer {
    protected:
        void onWSM(BaseFrame1609_4* wsm) override;
        void onWSA(DemoServiceAdvertisment* wsa) override;
   //fix by adding this part
        TraCIMobility* mobility;
        TraCICommandInterface* traci;
        TraCICommandInterface::Vehicle* traciVehicle;

        TraCIScenarioManager* manager;
        std::string trafficLightId;
    
    private:
        void setTraCI();
    };
    
    
    }

'''

Daniel
  • 1
  • 2
  • It is impossible to provide any help without further details regarding the issue. Have you tried to attach a debugger? – thardes2 Mar 17 '22 at 13:23
  • I did not try using debugger yet. But the problem seem to be from the line 'manager->getCommandInterface()->trafficlight("cluster_144084639_252529291_255540900_6503456532").setPhaseIndex(2);' – Daniel Mar 18 '22 at 04:47
  • It is impossible to provide any help without further information regarding the error – thardes2 Mar 19 '22 at 19:28
  • Can you maybe find a log file for sumo somewhere or enable one in the sumocfg? The easiest thing to check is if the id of the traffic light is correct. – Michael Mar 21 '22 at 07:02
  • I just fix my problem by adding declaring TraCIMobility* mobility;, TraCICommandInterface* traci; and TraCICommandInterface::Vehicle* traciVehicle; inside trafficlightrsu.h file. However my code still did not perform as it should be by changins traffic light into green. – Daniel Mar 21 '22 at 15:44
  • How to get information on why a simulation crashes is a frequently asked question. See http://veins.car2x.org/documentation/faq/ for an in-depth explanation - as well as a very short video tutorial on running a Veins simulation with a debugger attached. – Christoph Sommer Mar 22 '22 at 08:32

0 Answers0