-1

In sumo, my simulation has a traffic light called 539320442.

I want that a RSU (that exists in veins) changes this traffic light's phase.

So I created a Trafficlight variable in the TraCIDemoRSU11p.h as it follows:

TraCICommandInterface::Trafficlight* RSU_traffic_light;

Now I would like to get this traffic light that has id: 539320442 and change its phase by using:

void TraCICommandInterface::Traffic_light::setPhase(string, integer)

The problem is that in the TraCIDemoRSU11p.cc I couldn't get the traffic light and save it in:

RSU_traffic_light;

So I was wondering how can I get this traffic light and save it in RSU_traffic_light:

RSU_traffic_light = getTrafficLightbyID("539320442");

Would it be something like that? What is the exactly syntax for it?

pb772
  • 539
  • 1
  • 3
  • 14
  • you write "part of the code didn't work". Can you elaborate further? What did alternatives did you try? What did you expect would happen? What happened? – Christoph Sommer Mar 07 '17 at 08:39
  • I will edit it again, I found exactly where the main problem is. – pb772 Mar 07 '17 at 08:42
  • 1
    You mention you tried using a method with a signature of `TraCICommandInterface::Traffic_light::setPhase(string, integer)`. No such method exists in Veins. Neither does a class `Traffic_light` exist. Maybe you are going by documentation of different software (maybe the SUMO C++ API?). – Christoph Sommer Mar 07 '17 at 17:05

1 Answers1

2

Setting a traffic light's program and phase is what the simple test application included in Veins 4.5 does. You can refer to its source code to see how it changes traffic light phases:

#include "veins/modules/mobility/traci/TraCIMobility.h"
#include "veins/modules/mobility/traci/TraCICommandInterface.h"

TraCIMobility* mobility;
TraCICommandInterface* traci;

mobility = TraCIMobilityAccess().get(getParentModule());
traci = mobility->getCommandInterface();
traci->trafficlight("10").setProgram("myProgramGreenRed");
traci->trafficlight("10").setPhaseIndex(1);

Note that this uses the SUMO traffic light id and phase id of the test scenario, that is,

<tlLogic id="10" type="static" programID="myProgramRed" offset="0">
 <phase duration="999" state="GggGGgrrr"/>
 <phase duration="999" state="GggGGgrrr"/>
</tlLogic>

Your scenario will likely use a different traffic light ID and phase ID.

Christoph Sommer
  • 6,893
  • 1
  • 17
  • 35