【问题标题】:How to use change “changeVehicleRoute” function using Veins, SUMO and Omnet++?如何使用 Veins、SUMO 和 Omnet++ 更改“changeVehicleRoute”功能?
【发布时间】:2021-03-17 04:45:14
【问题描述】:

我正在使用一个简单的网络来更改以下车辆的路线。我的代码没有显示任何错误。 SUMO 和 omnet++ 都正常工作;但是,车辆并没有改变路线。我已经使用给定的静脉演示网络进行了尝试,但仍然无法正常工作。到目前为止,我已经尝试了几种在不同来源中找到的方法(当我将它们留在 cmets 中时,您可以在实际代码中看到这些方法),但仍然没有任何车辆正在改变路线。

我的 rou.xml 是:

<vehicle id="0" depart="5.00">
    <route edges="-gneE4 -gneE3 -gneE2 "/>
</vehicle>
<vehicle id="1" depart="5.00">
    <route edges="-gneE4 -gneE3 -gneE2 "/>
</vehicle>

<vehicle id="2" depart="5.90">
    <route edges="-gneE4 -gneE3 -gneE2 "/>
</vehicle>
 <vehicle id="3" depart="6.0">
    <route edges="-gneE4 -gneE3 -gneE2 "/>
</vehicle>

<vehicle id="4" depart="7.0">
    <route edges="gneE2 gneE3 gneE4"/>
</vehicle>

<vehicle id="5" depart="40.0">
<route edges="-gneE4 -gneE3 -gneE2 "/>

</vehicle>

并且更改路由是 TraCIDemo11p.cc 中的更改路由....

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

findHost()->getDisplayString().setTagArg("i", 1, "green");

//traciVehicle->changeVehicleRoute({"-gneE11","-gneE11"});
// mobility = TraCIMobilityAccess().get(getParentModule());
// traci = mobility->getCommandInterface();
//traciVehicle = mobility->getVehicleCommandInterface();
// traciVehicle->changeRoute("-gneE11", 6);

if (mobility->getRoadId()[0] != ':'){traciVehicle->changeRoute("-gneE11", 3600);}

if (!sentMessage) {
    sentMessage = true;
    // repeat the received traffic update once in 2 seconds plus some random delay
    wsm->setSenderAddress(myId);
    wsm->setSerial(3);
    scheduleAt(simTime() + 2 + uniform(0.01, 0.2), wsm->dup());
}

}

【问题讨论】:

    标签: routes omnet++ veins sumo


    【解决方案1】:

    如果您想了解各种 SUMO 方法的作用,我建议您直接查看源代码,例如 https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/mobility/traci/TraCICommandInterface.cc#L313。您将看到,您的代码所做的是更改汽车的路线,以假设边缘 -gneE11 的努力为 3600(1 小时,即 很多 的努力) .此边缘不属于您的任何车辆路线,因此您的车辆都不在乎:它们打算走的路线仍然“完美无缺”。

    有关替代方案,另请参阅https://github.com/sommer/veins/blob/veins-5.1/subprojects/veins_testsims/src/veins_testsims/traci/TraCITestApp.cc 的方法,该方法调用 Veins 5.1 中实现的所有 SUMO 方法一次,以查看它们是否按预期运行。例如,https://github.com/sommer/veins/blob/veins-5.1/subprojects/veins_testsims/src/veins_testsims/traci/TraCITestApp.cc#L285 将(对于一辆车)假设的边缘 42 更改为 9999,然后(稍后)检查车辆是否确实避免了边缘。

    从您注释掉的代码来看,https://github.com/sommer/veins/blob/veins-5.1/subprojects/veins_testsims/src/veins_testsims/traci/TraCITestApp.cc#L475 中的代码更符合您的目标:为车辆提供一条新路线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-21
      相关资源
      最近更新 更多