How can I get a traffic light that exists in sumo and change its phase in veins?

我的梦境 提交于 2019-12-03 21:59:53

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!