getRoadID()函数

huangapple go评论57阅读模式
英文:

Veins getRoadID()

问题

The provided code appears to be written in C++ and is related to handling messages in a vehicular network simulation. The relevant translated code is:

void TraCIDemo11p::onData(WaveShortMessage* wsm) {
if (mobility->getRoadId()[0] != ':') traciVehicle->changeRoute(wsm->getWsmData(), 9999);
}

The code is called when a vehicle receives a message to change its route after an accident occurs. It checks if the first character of the lane ID obtained from getRoadId() is not equal to ':' and then proceeds to change the vehicle's route.

The provided note mentions the software versions being used for the simulation: omnet 5.0, sumo-0.25.0, and veins-4.4.

英文:
void TraCIDemo11p::onData(WaveShortMessage* wsm) {
if (mobility->getRoadId()[0] != ':') traciVehicle->changeRoute(wsm->getWsmData(), 9999);

}

The above code is getting called when the vehicle receives a message to change its route when an accident happens.
mobility->getRoadId() gives the lane ID but what does getRoadId()[0] mean?

As I know getRoadId()[0] gives either 1 or :


Note: I am using omnet 5.0, sumo-0.25.0 and veins-4.4. (TraCIDemo11p.cc)

答案1

得分: 1

对于一个字符串,[0] 返回索引为 0 的字符,即第一个字符。在这种情况下,它返回道路标识符的第一个字符。

在SUMO中,属于交叉口的道路部分(称为“内部边缘”)通常分配一个以 : 开头的名称,因此检查当前道路ID是否以 : 开头是一种快速方法,用来确保我们不会在车辆正在通过交叉口时尝试更改其路线。

英文:

For a string of characters, the [0] returns the character at index 0, that is, the first character. In this case, it returns the first character of the road identifier.

In SUMO, the section of roads that is part of an intersection (called “internal edge”) is typically assigned a name starting with :, so checking if the current road ID starts with : is a quick hack to make sure we’re not trying to change a vehicle’s route while it is driving on an intersection.

huangapple
  • 本文由 发表于 2020年1月6日 16:35:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定