0

I am doing a research that includes an intersection. Simulation should be done by SUMO, OMNeT++ and Veins. when an emergency vehicle is approaching to the intersection the state of traffic light should be changed to green for that road after crossing the state should be returned to the previuos state. I have generate XML and SUMO files also some codes on OMNeT++ but the state of traffic light cannot be changed. I think even onBSM function doesn't work!!! I would be thankful if someone can help me.

'''
#include <iostream>
#include "mynet.h"
#define debugEV_clear EV
#define debugEV EV << logName() << "::" << getClassName() << ": "

//here you can see mynet.cc file
Define_Module(Veins::mynet);


void Veins::mynet::initialize(int stage) {
BaseWaveApplLayer::initialize(stage);
if (stage == 0) {

}
else if (stage == 1) {
    initMsg = new cMessage("traffic light init",77);
    phaseMsg = new cMessage("phase msg",88); //88 & 77 are just 
random 
number for handling messag efunction
    scheduleAt(simTime()+0.1, initMsg);
}

}

void Veins::mynet::onBSM(BasicSafetyMessage* bsm) {
//Your application has received a beacon message from another car or 
RSU
//code for handling the message goes here


//emergency car number is 2, if its distance from intersection got 
 less 20 meters so set traffic light to program1, the light changes 
 to gree
if (bsm->getSenderAddress() == 2){
    if ((curPosition-bsm->getSenderPos()).length() < 20) {
        if (!phaseMsg->isScheduled()) {
            //trafficLightId = "light1";
            traci- 
>trafficlight(trafficLightId).setProgram("program1");
            //traci->trafficlight(trafficLightId).setPhaseIndex(0);
            scheduleAt(simTime()+5,phaseMsg);
        }
    }
}
}


void Veins::mynet::onWSM(WaveShortMessage* wsm) {
//Your application has received a data message from another car or 
RSU
//code for handling the message goes here, see TraciDemo11p.cc for 
examples
}

void Veins::mynet::onWSA(WaveServiceAdvertisment* wsa) {
//Your application has received a service advertisement from another 
car 
or RSU
//code for handling the message goes here, see TraciDemo11p.cc for 
examples
}

   //handle self message function can be seen below
void Veins::mynet::handleSelfMsg(cMessage* msg) {
BaseWaveApplLayer::handleSelfMsg(msg);
//BasicSafetyMessage* bsm = dynamic_cast<BasicSafetyMessage *>(msg);
//scheduleAt(simTime()+0.1, initMsg);
//this method is for self messages (mostly timers)
//it is important to call the BaseWaveApplLayer function for BSM and 
WSM 
   transmission

    //after emergency car crosses the intersection the traffic light 
return 
to the previuos state 
   switch (msg->getKind())
  {
  case 77:
   manager = TraCIScenarioManagerAccess().get();
   traci = manager->getCommandInterface();
    trafficLightId = "light1";
    traci->trafficlight(trafficLightId).setProgram("program2");
    //traci->trafficlight(trafficLightId).setPhaseIndex(2);
   break;
  case 88:
   traci->trafficlight(trafficLightId).setProgram("program2");
   //traci->trafficlight(trafficLightId).setPhaseIndex(2);
   break;
  default:
   assert(0);
   break;
  }

  }
'''

'''
   //here you can see mynet.h file       
   #include"veins/modules/application/ieee80211p/BaseWaveApplLayer.h"
    #include "veins/modules/mobility/traci/TraCIScenarioManager.h"
    #include "veins/modules/mobility/traci/TraCICommandInterface.h"
    #include "veins/modules/mobility/traci/TraCIMobility.h"

    namespace Veins{
    class mynet : public BaseWaveApplLayer {
    protected:
    virtual void initialize( int stage);
    virtual void onWSM(WaveShortMessage* wsm);
    virtual void onWSA(WaveServiceAdvertisment* wsa);
    virtual void onBSM(BasicSafetyMessage * bsm);
    virtual void handleSelfMsg(cMessage* msg);

    
    TraCIScenarioManager* manager;
    std::string trafficLightId;
    
        cMessage* initMsg;
        cMessage* phaseMsg;


        };
        }
'''

'''
//here you can see omnet.ini file
[General]
cmdenv-express-mode = true
cmdenv-autoflush = true
cmdenv-status-frequency = 1s
**.cmdenv-log-level = info

ned-path = .
image-path = ../../images

network = mynet_rsu

##########################################################
#            Simulation parameters                       #
##########################################################
debug-on-errors = true
print-undisposed = true

sim-time-limit = 200s

**.scalar-recording = true
**.vector-recording = true

**.debug = false
**.coreDebug = false

*.playgroundSizeX = 2500m
*.playgroundSizeY = 2500m
*.playgroundSizeZ = 50m


##########################################################
# Annotation parameters                                  #
##########################################################
*.annotations.draw = true

##########################################################
#            TraCIScenarioManager parameters             #
##########################################################
*.manager.updateInterval = 0.1s
*.manager.host = "localhost"
*.manager.port = 9999
*.manager.autoShutdown = true
*.manager.launchConfig = xmldoc("mynet.launchd.xml")

##########################################################
#                       RSU SETTINGS                     #
#                                                        #
#                                                        #
##########################################################
*.rsu[0].mobility.x = 190
*.rsu[0].mobility.y = 190
*.rsu[0].mobility.z = 3

*.rsu[*].applType = "mynet"
*.rsu[*].appl.headerLength = 80 bit
*.rsu[*].appl.sendBeacons = false
*.rsu[*].appl.dataOnSch = false
*.rsu[*].appl.beaconInterval = 0.1s
*.rsu[*].appl.beaconUserPriority = 7
*.rsu[*].appl.dataUserPriority = 5

##########################################################
#            11p specific parameters                     #
#                                                        #
#                    NIC-Settings                        #
##########################################################
*.connectionManager.sendDirect = true
*.connectionManager.maxInterfDist = 2600m
*.connectionManager.drawMaxIntfDist = false

*.**.nic.mac1609_4.useServiceChannel = false

*.**.nic.mac1609_4.txPower = 20mW
*.**.nic.mac1609_4.bitrate = 6Mbps
*.**.nic.phy80211p.sensitivity = -89dBm

*.**.nic.phy80211p.useThermalNoise = true
*.**.nic.phy80211p.thermalNoise = -110dBm

*.**.nic.phy80211p.decider = xmldoc("config.xml")
*.**.nic.phy80211p.analogueModels = xmldoc("config.xml")
*.**.nic.phy80211p.usePropagationDelay = true

*.**.nic.phy80211p.antenna = xmldoc("antenna.xml", 
"/root/Antenna[@id='monopole']")

##########################################################
#                    WaveAppLayer                        #
##########################################################
*.node[*].applType = "mynet"
*.node[*].appl.headerLength = 80 bit
*.node[*].appl.sendBeacons = false
*.node[*].appl.dataOnSch = false
*.node[*].appl.beaconInterval = 0.1s

##########################################################
#                      Traffic Light                     #
##########################################################

*.manager.trafficLightModuleType = 
"org.car2x.veins.nodes.TrafficLight"
*.manager.trafficLightModuleName = "trafficLight"
*.manager.trafficLightModuleDisplayString = default
*.manager.trafficLightFilter = "trafficLightId"
*.trafficLight[*].mobility.x = 190
*.trafficLight[*].mobility.y = 190
*.trafficLight[*].mobility.z = 3

*.trafficLight[*].applType = "mynet"
*.trafficLight[*].logicType = "static"

##########################################################
#                      Mobility                          #
##########################################################
*.node[*].veinsmobilityType.debug = true
*.node[*].veinsmobility.x = 0
*.node[*].veinsmobility.y = 0
*.node[*].veinsmobility.z = 1.895

[Config Default]

[Config WithBeaconing]
*.rsu[*].appl.sendBeacons = true
*.node[*].appl.sendBeacons = true

[Config WithChannelSwitching]
*.**.nic.mac1609_4.useServiceChannel = true
*.node[*].appl.dataOnSch = true
*.rsu[*].appl.dataOnSch = true


'''

'''
//here you can see my mynet.tls.xml for simulatig traffic light file 
of 
SUMO which also repeated this part in mynet.net.xml file
<tlLogics version="0.27" xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
instance" 
   
<tls>
<tlLogic id="light1" type="static" programID="program1" offset="0">
    <phase duration="999" state="GrGr"/>
    <phase duration="999" state="yryr"/>
    <phase duration="999" state="rGrG"/>
    <phase duration="999" state="ryry"/>
</tlLogic>

<tlLogic id="light1" type="static" programID="program2" offset="0">
    <phase duration="999" state="rGrG"/>
    <phase duration="999" state="ryry"/>
    <phase duration="999" state="GrGr"/>
    <phase duration="999" state="yryr"/>
</tlLogic>
</tls>

<connection from="1to2" to="2to3" fromLane="0" toLane="0" tl="light1" 
linkIndex="3"/>
<connection from="3to2" to="2to1" fromLane="0" toLane="0" tl="light1" 
linkIndex="1"/>
<connection from="4to2" to="2to5" fromLane="0" toLane="0" tl="light1" 
linkIndex="0"/>
<connection from="5to2" to="2to4" fromLane="0" toLane="0" tl="light1" 
linkIndex="2"/>
</tlLogics>

'''
Adel
  • 1
  • 1
  • Please consider adding more insights and comments instead of just code blocks. – Anirban Saha Jun 23 '21 at 06:38
  • Can you explain more about what works and what does not? How can I reproduce the problem you are having on my machine? – Christoph Sommer Jun 23 '21 at 21:40
  • @ChristophSommer Thank your for your comment, I can send you my files if I have an email from you or can I share somewhere with you. The problem is related to traffic light it cannot be change to green state. Also I think onBSM message also is not received!!!! – Adel Jun 25 '21 at 09:05
  • 2
    If you send me your files that won’t help anybody reading this discussion here. Rather, I would recommend to append your question with a minimal reproducible example (see the site rules for what makes a good such example) – Christoph Sommer Jun 25 '21 at 12:55

0 Answers0