如何从 TraCIDem11p.cc 获取 RSU 坐标?

How to get RSU coordinate from TraCIDem11p.cc?

我想知道如何开始编写一个能够在车辆靠近 RSU 时发送消息的程序。 首先,我仍然对一些定义感到困惑,但是,慢慢地,我想我会学习脉络。

module = simulation.getModuleByPath("rsu[0]");
c = MobilityAccess().get(module)->getCurrentPosition();

我在这个线程中找到了这部分代码:Getting the location of two different modules

但还有一些疑问:

1) Module是个什么样的对象?我猜 TraCIMobility*

2) simulation 怎么样?我不知道。

所以,谁能先向我解释一下如何在 TraCIDemo11p.cc 中获取 RSU 坐标?

谢谢!

如果您研究 Veins 4.4 教程模拟(例如,通过 运行 它在 OMNeT++ 的 TkEnv 中),您将看到 rsu[0] 包含一个名为 mobility 的子模块,其类型BaseMobility。如果您调查 BaseMobility class,您会发现它有一个方法 getCurrentPosition()。大概通过阅读 OMNeT++ 用户手册,您已经知道如何获得指向模拟中任何模块的指针。

将这些知识放在一起,您已经找到了一种方法(在许多可能的方法中)来获取静脉模拟中(命名的)节点的位置。

假设您使用的是 Veins 4.4,以下代码可以由模拟中的任何 OMNeT++ 模块执行,以获取名为 rsu[0]:

的节点的位置
Coord pos = check_and_cast<BaseMobility*>(getSimulation()->getModuleByPath("rsu[0].mobility"))->getCurrentPosition();

此外,如果您需要一种动态方式来获取 RSU 坐标。主要是如果你有超过一个 RSU 的场景,你可以使用 "findSubModule":

BaseMobility *baseMob;
baseMob = FindModule<BaseMobility*>::findSubModule(getParentModule());
Coord rsuCoord = baseMob->getCurrentPosition();

希望这对某人有所帮助。

干杯。