如何重新实现静脉下的事故?

时间:2016-03-22 13:25:43

标签: omnet++

我想知道如何在Veins 2.0&一般情况下(使用TraciMobility模块)? 我检查了最后一个代码版本,似乎事故模拟背后的机制是相同的。

我注意到,负责任的代码如下:

//in TraCIMobility::initialize() method

if (accidentCount > 0) {
        simtime_t accidentStart = par("accidentStart");
        startAccidentMsg = new cMessage("scheduledAccident");
        stopAccidentMsg = new cMessage("scheduledAccidentResolved");
        scheduleAt(simTime() + accidentStart, startAccidentMsg);
}


//in TraCIMobility::handleSelfMsg() method

if (msg == startAccidentMsg) {
        commandSetSpeed(0);
        simtime_t accidentDuration = par("accidentDuration");
        scheduleAt(simTime() + accidentDuration, stopAccidentMsg);
        accidentCount--;
}

所以,如果我理解正确的话,这种机制只会将当前的车速设置为0,但是不要让它停止移动并停留在当前位置?!

假设我想通过命令车辆直接停在当前位置来模拟事故?我怎么能实现它?使用stop Traci命令?

谢谢,

2 个答案:

答案 0 :(得分:1)

通过Command 0xc4 0x40设置车辆速度会立即生效并保持有效直到设置为不同的速度或重置(通过传递值-1)。

您可以在其TraCI API的SUMO文档中找到更多详细信息。

答案 1 :(得分:0)

最后,

Veins 2.0下的事故实施(我认为对于上层版本来说是相同的)就像我之前所说的那样,通过将速度设置为0(使用Traci命令/变量:Change Vehicle State(0xc4) /speed (0x40))。 / p>

如果有人想以不同的方式实施事故,例如在Y路下的X位置停车,则必须使用Traci命令/变量重新实施事故:更改车辆状态(0xc4)/停止(0x12) ,此命令将位置X和道路Y作为参数。

祝你好运,